wente
2024-06-07 682de99bfea2567dc3d505516cd98aef0f2ab927
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <zt-dialog ref="dialog" @confirm="formSubmit">
    <el-form :model="dataForm" ref="dataForm" :disabled="dataForm.disabled" label-width="120px">
      <zt-form-item label="上级系统" prop="pid" v-if="isTree">
        <zt-combo-tree v-model="dataForm.pid" :datas="productList"/>
      </zt-form-item>
      <zt-form-item label="名称" prop="name" rules="required">
        <el-input v-model="dataForm.name"></el-input>
      </zt-form-item>
      <zt-form-item label="节点类型" prop="productType" rules="required">
        <zt-dict v-model="dataForm.productType" dict="product" @input="getDefaultImg"
                 :disabled="disabled"></zt-dict>
      </zt-form-item>
      <zt-form-item label="运行状态图" prop="operatImg" v-if="isShow">
        <el-input v-model="dataForm.operatImgName" @focus="selectPicture()"></el-input>
        <el-image v-if="dataForm.operatImg" :src="url+dataForm.operatImg" style="height: 50px;width: 50px"></el-image>
      </zt-form-item>
      <zt-form-item label="排序" prop="sort">
        <el-input v-model="dataForm.sort" :readonly="readonly"></el-input>
      </zt-form-item>
    </el-form>
    <PictureSelect ref="pictureSelect" @setPicture="openAddWin">
    </PictureSelect>
  </zt-dialog>
</template>
 
<script>
  import PictureSelect from "@/views/modules/basicInfo/SelectPicture";
  import Cookies from "js-cookie";
 
  export default {
    data() {
      return {
        disabled: false,
        url: `${window.SITE_CONFIG['apiURL']}/sysPictureBase/getSvgImage?token=${Cookies.get('token')}&id=`,
        isTree: false,
        isShow: true,
        fileId: '',
        productList: [],
        dataForm: {
          id: '',
          pid: '',
          name: '',
          productType: '',
          operatImg: '',
          operatImgName: '',
          sort: '',
          status: ''
        }
      }
    },
    components: {
      PictureSelect
    },
    methods: {
      init(id, params) {
        if (params.type === 'tree') {
          this.isTree = true
          this.isShow = false
          this.getProductList()
        } else {
          this.dataForm.pid = params.pid
          this.dataForm.productType = params.type
        }
        if (this.dataForm.productType === 10 && id == null) {
          this.getDefaultImg(this.dataForm.productType)
        }
        this.disabled = !!id;
      },
      // 获取系统列表
      async getProductList() {
        let res = await this.$http.get('/basicInfo/XhProductModel/getProductList')
        this.productList = res.data
        console.log(this.productList, 'getProductList')
      },
      async getDefaultImg(selected) {
        console.log(selected, 'async getDefaultImg')
        let params = {
          productType: selected
        }
        let res = await this.$http.get(`/sysPictureBase/getDefaultImg`, {params: params})
        this.dataForm.operatImgName = res.data.name
        this.dataForm.operatImg = res.data.id
      },
      selectPicture() {
        this.$refs.pictureSelect.$refs.dialog.init(this.dataForm.productType)
      },
      openAddWin(row) {
        this.dataForm.operatImgName = row.name
        this.dataForm.operatImg = row.id
        console.log(row, 'openAddWin(row)')
      },
      // 获取信息
      async getInfo() {
        let res = await this.$http.get(`/basicInfo/XhProductModel/${this.dataForm.id}`)
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      },
      // 表单提交
      async formSubmit() {
        let flag = true
        if (this.isTree) {
          if (this.dataForm.productType !== '5' || this.dataForm.productType !== '4') {
            this.$alert("不支持新增此节点")
            flag = false
          }
        } else {
          if (this.dataForm.productType === '5' || this.dataForm.productType === '4') {
            this.$alert("不支持新增此节点")
            flag = false
          }
        }
 
        if (!flag) {
          return
        }
        let res = await this.$http[!this.dataForm.id ? 'post' : 'put']('/basicInfo/XhProductModel/', this.dataForm)
        if (res.success) {
          await this.$tip.success()
          this.$refs.dialog.close()
          this.$emit('refreshDataList')
          this.map.clear()
        }
      }
    }
  }
</script>