Fixiaobai
2023-11-09 45e7495fe17c3b390a6d0e2461f0b8f965d46f6f
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
<template>
  <div class="mod-config">
    <basic-container>
      <el-row>
        <el-col :span="12">
          <ttable
            :table="table"
            @currentChange="handleCurrentChange"
            :uploadInfo="uploadInfo"
            :prelang="prelang"
            :options="options"
            :ajaxFun="ajaxFun"
            ref="templateTable"
          >
            <template #toolbar></template>
          </ttable>
        </el-col>
        <el-col :span="12" style="padding-left: 10px">
          <el-card>
            <div slot="header">
              <el-row>
                <el-col :span="8">
                  <span>参数</span>
                </el-col>
                <el-col :span="8" :offset="6">
                  <el-button
                    style="float: right; padding: 3px 0"
                    type="text"
                    @click="relateOperationParam()"
                    >添加</el-button
                  >
                </el-col>
              </el-row>
            </div>
            <el-table
              :data="operationParams"
              id="templateParamTable"
              ref="operationParam"
              :default-sort="{ prop: 'index' }"
              highlight-current-row
              height="700"
              style="width: 100%"
              class="l-mes-table basic-template-table"
              border
              stripe
            >
              <el-table-column
                prop="index"
                label="序号"
                width="50"
                align="center"
              >
                <template slot-scope="scope">
                  <div style="display:flex">
                    <span style="width:20px;">
                      <i class="icon aufontAll  h-icon-all-drag"></i
                    ></span>
                    <span>{{ scope.row.index }}</span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="参数编号" prop="code" align="center">
              </el-table-column>
              <el-table-column
                label="参数项"
                prop="parameterItem"
                align="center"
              >
              </el-table-column>
              <!-- <el-table-column
                label="参数类型"
                prop="type"
                align="center"
                :formatter="getParam"
              >
              </el-table-column>
 
              <el-table-column
                prop="defaultValue"
                label="默认值"
                align="center"
              >
                <template slot-scope="scope">
                  <template v-if="!scope.row.isUpdate"
                    >{{ getValueStr(scope.row) }}
                  </template>
                  <el-input
                    v-model="scope.row.defaultValue"
                    placeholder="默认值"
                    v-if="scope.row.type != 2 && scope.row.isUpdate"
                    :ref="'reference_' + scope.$index"
                  ></el-input>
                  <el-select
                    v-if="scope.row.type == 2 && scope.row.isUpdate"
                    :ref="'reference_' + scope.$index"
                    v-model="scope.row.defaultValue"
                  >
                    <el-option
                      v-for="item in scope.row.sysDictItemList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </template>
              </el-table-column>
 
              <el-table-column label="单位" prop="unit" align="center">
              </el-table-column> -->
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    v-if="scope.row.isUpdate"
                    size="mini"
                    @click="saveSample(scope.$index, scope.row)"
                    >保存
                  </el-button>
                  <el-button
                    type="text"
                    v-if="!scope.row.isUpdate"
                    size="mini"
                    @click="editSample(scope.$index, scope.row)"
                    >编辑
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click.stop="insertTechnologyOperationParam(scope.row)"
                    >插入
                  </el-button>
                  <el-button
                    type="text"
                    size="mini"
                    @click.stop="deleteOperationParam(scope.row)"
                    >删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>
        </el-col>
      </el-row>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getData"
      ></table-form>
      <ParamDialog
        :currshowlist.sync="showParam"
        @handleSelectionChange="getJoinData"
        :paramSelArr="paramSelArr"
        :paramSelCol="paramSelCol"
      ></ParamDialog>
    </basic-container>
  </div>
</template>
<script>
import {
  fetchList,
  delObj,
  putRelateOperationParamTemplate
} from '@/api/basic/template'
import TableForm from './template-form'
import ttable from '@/views/common/ztt-table.vue'
import ParamDialog from '@/views/common/param.vue'
import { mapGetters } from 'vuex'
import {
  deleteOperationParamTemplate,
  getOperationParam,
  relateOperationParamTemplate
} from '../../../api/basic/template'
import { remote } from '@/api/admin/dict'
export default {
  data() {
    return {
      paramSelArr: [],
      paramSelCol: 'code',
      templateIndex: null,
      last: true,
      templateId: 0,
      newOperationParams: [],
      operationParams: [],
      showParam: false,
      ajaxFun: fetchList,
      typeOptions: [],
      multipleSelection: [],
      isShowQuery: false,
      uploadInfo: {
        // 是否展示上传EXCEL以及对应的url
        isShow: false,
        url: ''
      },
      prelang: 'operation',
      options: {
        height: 300, // 默认高度-为了表头固定
        stripe: true, // 是否为斑马纹 table
        highlightCurrentRow: false, // 是否要高亮当前行
        border: true, // 是否有纵向边框
        lazy: false, // 是否需要懒加载
        fit: true, // 列的宽度是否自撑开
        multiSelect: false, //
        seqNo: true,
        isShowHide: true, // 是否显示显影按钮
        isSearch: true, // 高级查询按钮
        defaultOrderBy: { column: 'id', direction: 'desc' }
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // 标题
        column: [
          {
            minWidth: 'code',
            prop: 'templateName',
            label: '模板名称',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text',
            render: { fun: this.addOrUpdateHandle }
          },
          {
            minWidth: '120',
            prop: 'templateNo',
            label: '模板编号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '140',
            prop: 'templateType',
            label: '模板类型',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            prop: 'dataType',
            label: '所在页面',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          {
            minWidth: '120',
            prop: 'remark',
            label: '备注',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          }
        ],
        toolbar: [
          {
            text: '新增',
            type: 'primary',
            fun: this.addOrUpdateHandle
          }
        ],
        operator: [
          {
            text: '删除',
            icon: 'el-icon-delete',
            type: 'text',
            size: 'small',
            fun: this.deleteHandle
          }
        ],
        operatorConfig: {
          fixed: 'right',
          label: '操作',
          width: 100,
          minWidth: 100
        }
      },
      addOrUpdateVisible: false
    }
  },
  components: {
    ttable,
    TableForm,
    ParamDialog
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  mounted() {
    this.getParamType()
    this.rowDrop()
  },
  methods: {
    // 获取数据列表
    getData() {
      this.$refs.templateTable.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row == null ? null : row.id)
      })
    },
    handleCurrentChange(val) {
      this.templateId = val.id
      if (val != null) {
        this.operationParams = []
        this.getJoinParamTemplateData()
      } else {
        this.operationParams = []
      }
    },
    // 插入工序参数
    insertTechnologyOperationParam(row) {
      // 筛选出当前页面已有的参数
      this.paramSelArr = []
      if (this.operationParams.length > 0) {
        this.operationParams.forEach((ele) => {
          if (ele.code != null && ele.code != '') {
            this.paramSelArr.push(ele.code)
          }
        })
      }
      this.showParam = true
      this.last = false
      this.templateIndex = row.index
    },
    // 获取关联的工序参数信息
    getJoinParamTemplateData() {
      getOperationParam(
        Object.assign({
          current: 1,
          size: 999,
          technologyOperationTemplateId: this.templateId
        })
      ).then((response) => {
        this.operationParams = response.data.data.records
      })
    },
    rowDrop() {
      const that = this
      const tbody = document.querySelector(
        '#templateParamTable .el-table__body-wrapper tbody'
      )
      Sortable.create(tbody, {
        // 结束拖拽
        onEnd({ newIndex, oldIndex }) {
          if (newIndex > oldIndex) {
            // 下移
            that.operationParams
              .filter((e) => e.index == oldIndex + 1)
              .forEach((e) => (e.index = 'x'))
            that.operationParams
              .filter((e) => e.index > oldIndex + 1 && e.index <= newIndex + 1)
              .forEach((e) => (e.index = e.index - 1))
            that.operationParams
              .filter((e) => e.index == 'x')
              .forEach((e) => (e.index = newIndex + 1))
          } else if (oldIndex > newIndex) {
            // 上移
            that.operationParams
              .filter((e) => e.index == oldIndex + 1)
              .forEach((e) => (e.index = 'x'))
            that.operationParams
              .filter((e) => e.index < oldIndex + 1 && e.index >= newIndex + 1)
              .forEach((e) => (e.index = e.index + 1))
            that.operationParams
              .filter((e) => e.index == 'x')
              .forEach((e) => (e.index = newIndex + 1))
          }
          // 拖拽结束后,保存页面工步
          const allOperationParams = []
          let allOperationParam
          // 将原有工步放入allSteps
          for (let j = 0, len = that.operationParams.length; j < len; j++) {
            allOperationParam = {}
            allOperationParam.technologyOperationTemplateId = that.templateId
            allOperationParam.technologyOperationParamId =
              that.operationParams[j].id
            allOperationParam.sort = that.operationParams[j].index
            allOperationParams.push(allOperationParam)
          }
          // 保存
          that.operationParams = []
          that.$nextTick(() => {
            relateOperationParamTemplate(allOperationParams).then(
              (response) => {
                const resData = response.data
                if (resData.code === 0) {
                  const resSteps = resData.data
                  if (resSteps.length > 0) {
                    let operationParam
                    for (let i = 0; i < resSteps.length; i++) {
                      operationParam = {}
                      operationParam.id = resSteps[i].id
                      operationParam.code = resSteps[i].code
                      operationParam.parameterItem = resSteps[i].parameterItem
                      operationParam.unit = resSteps[i].unit
                      operationParam.index = resSteps[i].index
                      operationParam.type = resSteps[i].type
                      operationParam.defaultValue = resSteps[i].defaultValue
                      operationParam.dict = resSteps[i].dict
                      operationParam.sysDictItemList =
                        resSteps[i].sysDictItemList
                      operationParam.technologyOperationTemplateId =
                        resSteps[i].technologyOperationTemplateId
                      that.operationParams.push(operationParam)
                    }
                  }
                  that.$message.success('参数关联成功')
                } else {
                  that.message.error('参数关联失败')
                }
                that.newOperationParams = []
              }
            )
          })
        }
      })
    },
    // 删除
    deleteHandle(row) {
      this.$confirm('是否确认删除模板编号为' + row.templateNo, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delObj(row.id)
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    },
    // 添加
    relateOperationParam() {
      console.log(11111);
      if (this.templateId !== 0) {
        // 筛选出当前页面已有的参数
        this.paramSelArr = []
        if (this.operationParams.length > 0) {
          this.operationParams.forEach((ele) => {
            if (ele.code != null && ele.code != '') {
              this.paramSelArr.push(ele.code)
            }
          })
        }
        this.showParam = true
      } else {
        this.$message.error('请选择模板')
      }
    },
    // 提交工序模板与工序参数的关联
    dataFormRelateOperationParam(state) {
      // 提交用的工序模板与工序参数关联的数组
      if (this.operationParams.length > 0) {
        for (let j = 0, len = this.operationParams.length; j < len; j++) {
          this.newOperationParams.push(
            Object.assign({
              technologyOperationTemplateId: this.templateId,
              technologyOperationParamId: this.operationParams[j].id,
              sort: this.operationParams[j].index
            })
          )
        }
        relateOperationParamTemplate(this.newOperationParams).then(
          (response) => {
            const resData = response.data
            if (resData.code === 0) {
              const resSteps = resData.data
              if (resSteps.length > 0) {
                this.operationParams = []
                let operationParam
                for (let i = 0; i < resSteps.length; i++) {
                  operationParam = {
                    id: resSteps[i].id,
                    code: resSteps[i].code,
                    parameterItem: resSteps[i].parameterItem,
                    unit: resSteps[i].unit,
                    index: resSteps[i].index,
                    type: resSteps[i].type,
                    defaultValue: resSteps[i].defaultValue,
                    dict: resSteps[i].dict,
                    sysDictItemList: resSteps[i].sysDictItemList,
                    technologyOperationTemplateId:
                      resSteps[i].technologyOperationTemplateId
                  }
                  /* operationParam.id = resSteps[i].id
                  operationParam.code = resSteps[i].code
                  operationParam.parameterItem = resSteps[i].parameterItem
                  operationParam.unit = resSteps[i].unit
                  operationParam.index = resSteps[i].index
                  operationParam.type = resSteps[i].type
                  operationParam.defaultValue = resSteps[i].defaultValue */
                  this.operationParams.push(operationParam)
                }
              }
              if (state) {
                this.$message.success('参数关联成功')
              }
            } else {
              this.message.error('参数关联失败')
            }
            this.newOperationParams = []
          }
        )
      } else {
        this.$message.error('请先选择参数')
      }
    },
    // 选中的参数信息
    getJoinData(param) {
      const newDataList = this.operationParams
      this.operationParams = []
      this.$nextTick(() => {
        this.operationParams = newDataList
        for (let i = 0, len = param.length; i < len; i++) {
          if (this.last) {
            this.operationParams.push(
              Object.assign({
                technologyOperationTemplateId: this.templateId,
                id: param[i].id,
                code: param[i].code,
                parameterItem: param[i].parameterItem,
                type: param[i].type,
                unit: param[i].unit,
                defaultValue: null,
                index: this.operationParams.length + 1
              })
            )
          } else {
            this.operationParams
              .filter((e) => e.index >= this.templateIndex)
              .forEach((e) => (e.index = e.index + 1))
            this.operationParams.push(
              Object.assign({
                technologyOperationTemplateId: this.templateId,
                id: param[i].id,
                code: param[i].code,
                parameterItem: param[i].parameterItem,
                type: param[i].type,
                unit: param[i].unit,
                defaultValue: null,
                index: this.templateIndex
              })
            )
            this.last = true
          }
        }
        this.dataFormRelateOperationParam(true)
      })
    },
    deleteOperationParam(row) {
      this.$confirm('是否确认删除参数编号为:' + row.code, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((data) => {
        this.operationParams.splice(
          this.operationParams.findIndex((item) => item.index === row.index),
          1
        )
        this.operationParams
          .filter((e) => e.index >= row.index)
          .forEach((e) => (e.index = e.index - 1))
        deleteOperationParamTemplate(
          Object.assign({
            technologyOperationTemplateId: this.templateId,
            technologyOperationParamId: row.id
          })
        ).then((response) => {
          this.$message.success('删除关联成功')
        })
        if (this.operationParams.length > 0) {
          this.dataFormRelateOperationParam(false)
        }
      })
    },
    // 获取工序参数类型
    getParamType() {
      remote('technology_param').then((response) => {
        if (response.data.code === 0) {
          this.typeOptions = response.data.data
        } else {
          this.typeOptions = []
        }
      })
    },
    // 表格字段格式化
    getParam(row, column, cellValue) {
      for (let i = 0, len = this.typeOptions.length; i < len; i++) {
        if (cellValue == this.typeOptions[i].value) {
          return this.typeOptions[i].label
        }
      }
    },
    // 修改保存
    saveSample(index, row) {
      console.log('row', row)
      var obj = {}
      obj.technologyOperationParamId = row.id
      obj.technologyOperationTemplateId = row.technologyOperationTemplateId
      obj.defaultValue = row.defaultValue
      putRelateOperationParamTemplate(obj).then((response) => {
        this.$message.success('参数保存成功')
        this.$set(row, 'isUpdate', false)
        // this.getJoinParamTemplateData()
      })
    },
    editSample(index, row) {
      this.$set(row, 'isUpdate', true)
    },
    getValueStr(row) {
      let re = row.defaultValue
      if (row.dict && row.sysDictItemList && row.sysDictItemList.length > 0) {
        const index = row.sysDictItemList.findIndex(
          (el) => el.value == row.defaultValue
        )
        if (index > -1) {
          re = row.sysDictItemList[index].label
        }
      }
      return re
    }
  }
}
</script>
<style>
.basic-template-table .el-table__body .el-table__row td:first-child .cell {
  padding-left: 0px;
  padding-right: 0px;
}
 
.basic-template-table .el-table__body .el-table__row:hover {
  cursor: move;
}
 
.basic-template-table .el-table__body .el-table__row:hover .icon {
  display: inline-block;
}
 
.basic-template-table .el-table__body .el-table__row .icon {
  color: rgba(0, 0, 0, 0.45);
  font-size: 12px;
  line-height: 18px;
  display: none;
}
 
.aufontAll {
  font-family: aufontAll !important;
  font-size: 14px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
 
.h-icon-all-drag {
  background: url('/img/tz.png') center center no-repeat;
  background-size: cover;
  font-size: 14px;
}
.h-icon-all-drag:before {
  content: '\E63E';
  font-size: 14px;
  visibility: hidden;
}
</style>