田源
2024-01-30 eff08b9e2986b91615620c0fa47c2de2170f7a78
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<template>
  <div v-if="Formlist.length>0">
    <div style="height: calc(100vh - 553px)">
      <avue-crud ref="crud" :data="data" :option="option" :page.sync="page" :table-loading="loading"
                 @on-load="getDataList" @size-change="handleSizePage" @current-change="handleCurrentPage"
                 @row-click="handleRowClick">
        <template slot="menu" slot-scope="{type,size,row,index}">
          <el-button :size="size" :type="type" icon="el-icon-check"
                     @click="handleMaintenance(row, index)">维护
          </el-button>
        </template>
      </avue-crud>
    </div>
    <el-dialog :visible.sync="dialogNode" append-to-body="true" title="模板阶段" width="50%">
      <avue-crud ref="crud" :data="stageData" :option="stageOption" :table-loading="loading" @on-load="getStagelist"
                 @row-click="handleRowStageClick">
        <template slot="menu" slot-scope="{type,size,row,index}">
          <el-button :size="size" :type="type" icon="el-icon-check"
                     @click="handleMaintenanceTransfer(row, index)">维护
          </el-button>
        </template>
      </avue-crud>
    </el-dialog>
    <table-transfer v-if="flag" v-model="attributeValue" :columns="columns" :dataList="attributeData"
                    :visible.sync="dialogTransfer" keyName="oid" @close="handelClose" @save="handleSave"></table-transfer>
  </div>
</template>
 
<script>
import {getFlowpathList, stagelist, attributeListRight, attributeList, attributeSave} from '@/api/template/flowpath.js'
import TableTransfer from '@/components/template/TableTransfer'
 
export default {
  name: 'Stage',
  components: {
    TableTransfer
  },
  props: {
    code: {
      typeof: String,
      required: true,
      default: ""
    },
    Formlist: {
      type: Array,
      default: []
    }
  },
  watch: {
    code: {
      handler(newval, oldval) {
        this.getDataList()
      }
    }
  },
  data() {
    const options = {
      height:'auto',
      border: true,
      addBtn: false,
      align: 'center',
      menuAlign: 'center',
      index: true,
      searchMenuSpan: 8,
      searchBtn: false,
      emptyBtn: false,
      columnBtn: false,
      delBtn: false,
      refreshBtn: false,
      header: false,
      editBtn: false,
    }
    return {
      attributeData: [],
      attributeValue: [],
      flag: false,
      dialogTransfer: false,
      dialogNode: false,
      visibleTable: false,
      loading: false,
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      modelKey: '',
      data: [],
      stageData: [],
      saveParam: {},
      columns: [
        {
          key: "oid",
          label: "oid",
          visible: false,
        },
        {
          key: "id",
          label: "属性编号",
          visible: true,
        },
        {
          key: "name",
          label: "属性名称",
          visible: true,
        },
        {
          key: "attributeGroup",
          label: "属性分组",
          visible: true,
        },
      ],
      option: {
        ...options,
        height: 330,
        column: [
          {label: '模板编号', prop: 'modelKey'},
          {label: '模板名称', prop: 'modelName'},
          {label: '描述', prop: 'buttonTypeValue'},
        ]
      },
      stageOption: {
        ...options,
        height: 620,
        column: [
          {label: '阶段编号', prop: 'taskId'},
          {label: '阶段名称', prop: 'taskName'},
        ]
      },
    }
  },
  methods: {
    setTable(data, list) {
      return data.map(item => {
        if (list.length !== 0) {
          list.forEach(element => {
            if (item.id === element.attrId) item.checked = true
          });
        }
        return item
      })
    },
    // 获取列表
    async getDataList() {
      this.loading = false
      if (this.code) {
        const {pageSize, currentPage} = this.page
        let param = {size: pageSize, current: currentPage}
        const response = await getFlowpathList({...param, ...{templateId: this.code}})
        if (response.status === 200) {
          this.loading = false
          const data = response.data.data
          this.data = data.records
          this.page.total = data.total
        } else this.loading = false
      } else {
        this.data = []
      }
    },
    // 获取阶段列表
    async getStagelist() {
      this.loading = false
      const response = await stagelist({modelKey: this.modelKey})
      if (response.status === 200) {
        this.loading = false
        this.stageData = response.data.data
      } else this.loading = false
    },
    // 获取全部属性
    async getAttributeList() {
      const response = await attributeList({'conditionMap[classifyTemplateOid]': this.code})
      const responseRight = await attributeListRight({
        templateId: this.code,
        modelKey: this.modelKey,
        taskId: this.saveParam.taskId
      })
      if (response.status === 200 && responseRight.status === 200) {
        let datas = response.data.data.records
        let dataRight = responseRight.data.data
        datas = datas.map(item => {
          const {oid, id, name, attributeGroup} = item
          item = {oid, id, name, attributeGroup, ...{checked: false}}
          if (dataRight.length !== 0) {
            dataRight.forEach(element => {
              if (item.id === element.attrId) item.checked = true
            });
          }
          return item
        })
        let dataValue = datas.map(item => item.checked ? item.oid : undefined)
        this.attributeValue = dataValue.filter(item => item)
        this.attributeData = datas
        this.flag = true
      }
    },
    // 获取已保存属性
    async getAttributeListRight() {
      const response = await attributeListRight({
        templateId: this.code,
        modelKey: this.modelKey,
        taskId: this.saveParam.taskId
      })
      if (response.status === 200) {
        let data = response.data.data
        data = data.map(item => {
          const {attrId, attrName, attrGroup} = item
          return {attrId, attrName, attrGroup}
        })
        this.listRight = data
      }
    },
    // 维护
    handleMaintenance(row) {
      this.dialogNode = true
      this.modelKey = row.modelKey
      this.saveParam.modelKey = row.modelKey
      this.getStagelist()
    },
    // 维护
    handleMaintenanceTransfer(row) {
      this.saveParam.taskId = row.taskId
      this.saveParam.taskName = row.taskName
      this.getAttributeList()
      this.$nextTick(() => {
        this.dialogTransfer = true
      })
    },
    handleRowClick(row) {
      this.modelKey = row.modelKey
      this.saveParam.modelKey = row.modelKey
      this.dialogNode = true
    },
    handleRowStageClick(row) {
      this.saveParam.taskId = row.taskId
      this.saveParam.taskName = row.taskName
      this.getAttributeList()
      this.$nextTick(() => {
        this.dialogTransfer = true
      })
    },
    async handleSave(event) {
      const data = event.map(item => {
        const {id, name, attributeGroup} = item
        return {attrId: id, attrName: name, attrGroup: attributeGroup}
      })
      let param = {
        templateId: this.code,
        processStageAttr: data,
        ...this.saveParam
      }
      const response = await attributeSave(param)
      if (response.status === 200) {
        // loading()
        this.$message({
          type: 'success',
          message: '新增数据成功!'
        })
        this.flag = false
        // done()
        // this.getDataList()
      }
    },
    handelClose() {
      this.flag = false
    }
  }
}
</script>