zouyu
2023-11-10 af3baa8feeef4f4cd9a0866884f3bc68d1512683
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
<template>
  <div>
    <div style="display:flex;justify-content:space-around;">
      <div style="width:32%">
        <el-card class="document-params-template">
          <div slot="header">
            <span>检测标准</span>
            <div style="float: right;">
              <el-button
                style="padding: 3px 0"
                type="text"
                size="medium"
                v-if="editable && dataFormId && routingOperationId"
                @click="openTestStandardDialog"
                >添加
              </el-button>
            </div>
          </div>
          <el-table
            ref="operationTestStandardTable"
            :data="operationTestStandardList"
            class="l-mes"
            highlight-current-row
            @row-click="testStandardRowClick"
            height="400px"
          >
            <el-table-column
              label="标准编号"
              prop="standardNo"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              label="标准名称"
              prop="standardName"
              align="center"
              show-overflow-tooltip
            />
          </el-table>
        </el-card>
      </div>
      <div style="width:64%">
        <el-card class="document-template-rule">
          <div slot="header">
            <span>标准参数</span>
            <div style="float: right;">
              <el-button
                style="padding: 3px 0"
                type="text"
                size="medium"
                @click="dataFormTestStandardParam()"
                v-if="editable && currentOperationTestStandardId"
                >提交参数
              </el-button>
              <el-button
                style="padding: 3px 0"
                type="text"
                size="medium"
                v-if="editable && currentOperationTestStandardId"
                @click="relateOperationParam()"
                >添加
              </el-button>
            </div>
          </div>
          <el-table
            :data="operationTestStandardParamList"
            id="testStandardParamTable"
            ref="testStandardParam"
            :default-sort="{ prop: 'index' }"
            highlight-current-row
            height="400px"
            style="width: 100%"
          >
            <el-table-column
              prop="index"
              label="序号"
              align="center"
              width="50"
            />
            <el-table-column label="参数编号" prop="code" align="center" />
            <el-table-column
              label="参数项"
              prop="parameterItem"
              align="center"
            />
            <el-table-column
              label="检测范围"
              prop="referenceValue"
              align="center"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column label="检测类型" prop="paramType" align="center">
              <template slot-scope="scope">
                <span>{{
                  scope.row.paramType
                    ? paramTypeOptions.find((item) => {
                        return item.value === scope.row.paramType
                      }).label
                    : ''
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="参数格式"
              prop="parameterFormat"
              align="center"
            >
            </el-table-column>
            <el-table-column label="单位" prop="unit" align="center" />
          </el-table>
        </el-card>
      </div>
    </div>
    <testStandardDialog
      :currshowlist.sync="showTestStandard"
      @handleSelectionTestStandardChange="selectTestStandard"
    />
    <!-- 弹窗, 基础参数选择 -->
    <!--<ParamDialog
      :currshowlist.sync="showParam"
      @handleSelectionChange="getJoinData"
      :paramSelArr="paramSelArr"
      :paramSelCol="paramSelCol"
    ></ParamDialog>-->
    <edit-order-param-form
      v-if="editOrderParamVisible"
      ref="editOrderParam"
      @refreshOrderParamList="refreshOrderParamList"
    ></edit-order-param-form>
  </div>
</template>
<style lang="scss" scoped>
.document-params-template >>> .el-card__body {
  padding: 0px 0px 5px;
}
.document-template-rule >>> .el-card__body {
  padding: 0px 0px 5px;
}
</style>
<script>
import {
  addRoutingTestStandard,
  getRoutingTestStandardList,
  deleteRoutingTestStandard,
  getOperationTestStandardParam,
  addOperationTestStandardParam
} from '@/api/plan/moteststandard'
import { getTestStandardParams } from '@/api/quality/teststandard'
import testStandardDialog from '@/views/common/teststandard'
import EditOrderParamForm from './editparamform'
import ParamDialog from '@/views/common/param.vue'
import { remote } from '../../../api/admin/dict'
 
export default {
  props: {
    editable: {
      type: Boolean,
      default: false
    },
    dataFormId: {
      type: Number,
      default: 0
    },
    routingOperationId: {
      type: Number,
      default: 0
    },
    paramTypeOptions: {
      type: Array,
      default: () => {
        return []
      }
    },
    operationTestStandardList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      addCustomizeTestStandardVisible: false,
      showTestStandard: false,
      operationTestStandardParamList: [],
      currentOperationTestStandardId: 0,
      paramSelArr: [],
      paramSelCol: 'code',
      showParam: false,
      insertIndex: null,
      last: true,
      editOrderParamVisible: false
    }
  },
  components: {
    testStandardDialog,
    EditOrderParamForm
  },
  mounted() {
    // this.rowDrop()
  },
  created() {
    // this.initDirParamType()
  },
  methods: {
    initDirParamType() {
      remote('quality_param_type').then((response) => {
        if (response.data.code === 0) {
          this.paramTypeOptions = response.data.data
        }
      })
    },
    selectLastTestStandard() {
      if (
        this.operationTestStandardList &&
        this.operationTestStandardList.length > 0
      ) {
        const lastTestStandard = this.operationTestStandardList[
          this.operationTestStandardList.length - 1
        ]
        this.$refs.operationTestStandardTable.setCurrentRow(lastTestStandard)
        this.getOperationTestStandardParam(lastTestStandard.id)
      }
    },
    // 根据制造订单id和工艺工序id查询检测标准
    getRoutingTestStandard(param) {
      getRoutingTestStandardList(param).then((response) => {
        const resData = response.data
        if (resData.code === 0) {
          this.currentOperationTestStandardId = 0
          this.operationTestStandardList = resData.data
          if (this.operationTestStandardList) {
            this.$refs.operationTestStandardTable.setCurrentRow(
              this.operationTestStandardList[0]
            )
            this.testStandardRowClick(this.operationTestStandardList[0])
          }
          this.operationTestStandardParamList = []
        } else {
          this.currentOperationTestStandardId = 0
          this.operationTestStandardList = []
          this.operationTestStandardParamList = []
          this.$message.error('检测标准请求异常')
        }
      })
    },
    // 弹出基础检测标准选择列表
    openTestStandardDialog() {
      this.showTestStandard = true
    },
    // 检测标准的选中结果返回
    selectTestStandard(param) {
      if (param.length > 0) {
        // 进行urlencoding
        // debugger;
        for (var i = 0; i < param.length; i++) {
          // 遍历数组
          if (param[i].judgeFormula) {
            var reg = new RegExp('&', 'g')
            // var newstr = str.replace( reg , '天朝' );
            param[i].judgeFormula = param[i].judgeFormula.replace(reg, '&amp;')
          }
        }
 
        const mo = {
          id: this.dataFormId,
          routingOperationId: this.routingOperationId,
          moTestStandardList: param
        }
        addRoutingTestStandard(mo).then((response) => {
          const data = response.data
          if (data.code === 0) {
            const newTestStandardList = response.data.data
            for (let i = 0; i < newTestStandardList.length; i++) {
              this.operationTestStandardList.push(newTestStandardList[i])
            }
            this.$message.success('检测标准添加成功')
            // 选中最后一个检测标准
            this.selectLastTestStandard()
          } else {
            this.$message.error('检测标准添加失败')
          }
        })
      }
    },
    // 删除检测标准
    handleTestStandardDelete(row, index) {
      deleteRoutingTestStandard(row.id).then((response) => {
        const data = response.data
        if (data.code === 0) {
          // 清空参数、删除当前行、清空选中、清空当前的routingTemplateId
          this.operationTestStandardList.splice(index, 1)
          this.operationTestStandardParamList = []
          this.currentOperationTestStandardId = null
          this.$refs.operationTestStandardTable.setCurrentRow()
          this.$message.success('删除成功')
        } else {
          this.$message.error('删除失败')
        }
      })
    },
    // 检测标准点击事件,显示检测标准参数
    testStandardRowClick(row) {
      this.getOperationTestStandardParam(row.standardId)
    },
    // 根据工艺工序id、模板id去获取模板下的参数
    getOperationTestStandardParam(standardId) {
      this.currentOperationTestStandardId = standardId
      getTestStandardParams(
        Object.assign({
          testStandardId: standardId
        })
      ).then((response) => {
        this.operationTestStandardParamList = response.data.data
      })
    },
 
    rowDrop() {
      const that = this
      const tbody = document.querySelector(
        '#testStandardParamTable .el-table__body-wrapper tbody'
      )
      Sortable.create(tbody, {
        // 结束拖拽
        onEnd({ newIndex, oldIndex }) {
          if (newIndex > oldIndex) {
            // 下移
            that.operationTestStandardParamList
              .filter((e) => e.index === oldIndex + 1)
              .forEach((e) => (e.index = 'x'))
            that.operationTestStandardParamList
              .filter((e) => e.index > oldIndex + 1 && e.index <= newIndex + 1)
              .forEach((e) => (e.index = e.index - 1))
            that.operationTestStandardParamList
              .filter((e) => e.index === 'x')
              .forEach((e) => (e.index = newIndex + 1))
          } else if (oldIndex > newIndex) {
            // 上移
            that.operationTestStandardParamList
              .filter((e) => e.index === oldIndex + 1)
              .forEach((e) => (e.index = 'x'))
            that.operationTestStandardParamList
              .filter((e) => e.index < oldIndex + 1 && e.index >= newIndex + 1)
              .forEach((e) => (e.index = e.index + 1))
            that.operationTestStandardParamList
              .filter((e) => e.index === 'x')
              .forEach((e) => (e.index = newIndex + 1))
          }
        }
      })
    },
    // 提交检测标准参数
    dataFormTestStandardParam() {
      if (this.operationTestStandardParamList.length > 0) {
        addOperationTestStandardParam(this.operationTestStandardParamList).then(
          (response) => {
            this.$message.success('检测标准参数保存成功')
          }
        )
      } else {
        this.$message.warning('请先添加参数')
      }
    },
    editTestStandardParam(row) {
      this.editOrderParamVisible = true
      this.$nextTick(() => {
        this.$refs.editOrderParam.init(row)
      })
    },
    deleteTestStandardParam(row) {
      this.$confirm('是否确认删除参数编号为:' + row.code, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((data) => {
        this.operationTestStandardParamList.splice(
          this.operationTestStandardParamList.findIndex(
            (item) => item.index === row.index
          ),
          1
        )
        this.operationTestStandardParamList
          .filter((e) => e.index >= row.index)
          .forEach((e) => (e.index = e.index - 1))
        this.$message.success('删除参数成功')
      })
    },
    // 选择基础参数(添加)
    relateOperationParam() {
      if (this.currentOperationTestStandardId !== 0) {
        this.selectedParamCode()
        this.showParam = true
      } else {
        this.$message.error('请选择检测标准')
      }
    },
    // 选择基础参数(插入)
    insertOperationParam(row) {
      this.selectedParamCode()
      this.showParam = true
      this.last = false
      this.insertIndex = row.index
    },
    selectedParamCode() {
      // 筛选出当前页面已有的参数
      this.paramSelArr = []
      if (this.operationTestStandardParamList.length > 0) {
        this.operationTestStandardParamList.forEach((ele) => {
          if (ele.code != null && ele.code !== '') {
            this.paramSelArr.push(ele.code)
          }
        })
      }
    },
    refreshOrderParamList() {
      getOperationTestStandardParam(
        Object.assign({
          moTestStandardId: this.currentOperationTestStandardId
        })
      ).then((response) => {
        this.operationTestStandardParamList = response.data.data
      })
    },
    // 选中的基础参数信息
    getJoinData(param) {
      const newDataList = this.operationTestStandardParamList
      this.operationTestStandardParamList = []
      this.$nextTick(() => {
        this.operationTestStandardParamList = newDataList
        for (let i = 0, len = param.length; i < len; i++) {
          if (this.last) {
            this.operationTestStandardParamList.push(
              Object.assign({
                moTestStandardId: this.currentOperationTestStandardId,
                code: param[i].code,
                parameterItem: param[i].parameterItem,
                type: param[i].type,
                unit: param[i].unit,
                parameterFormat: param[i].parameterFormat,
                referenceValue: null,
                index: this.operationTestStandardParamList.length + 1
              })
            )
          } else {
            this.operationTestStandardParamList
              .filter((e) => e.index >= this.insertIndex)
              .forEach((e) => (e.index = e.index + 1))
            this.operationTestStandardParamList.push(
              Object.assign({
                moTestStandardId: this.currentOperationTestStandardId,
                code: param[i].code,
                parameterItem: param[i].parameterItem,
                type: param[i].type,
                unit: param[i].unit,
                parameterFormat: param[i].parameterFormat,
                referenceValue: null,
                index: this.insertIndex
              })
            )
          }
        }
      })
    }
  },
  watch: {
    operationTestStandardList: {
      handler(newValue, oldValue) {
        this.operationTestStandardParamList = []
      },
      deep: true
    }
  }
}
</script>