spring
2025-03-19 1f69274b3f62e60378d7c5dbce05357366aaf2a6
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
<template>
  <div>
    <el-dialog title="零件绑定" :visible.sync="isShow" width="800px" @close="$emit('closeBindPartDialog')">
      <lims-table :tableData="tableData" :column="column" height="460" :page="page" :tableLoading="tableLoading"
        :key="1"></lims-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('closeBindPartDialog')">取 消</el-button>
        <el-button type="primary" @click="addBindPart('add')" :loading="addBindLoad">新 增</el-button>
      </span>
    </el-dialog>
    <el-dialog :title="dialogTitle" :visible.sync="addBindPartDialog" width="400px" @close="closeBindPartDialog"
      :close-on-click-modal="false">
      <div class="body" v-if="addBindPartDialog">
        <el-form label-position="right" label-width="80px" ref="bindPartData" :rules="bindPartDataRules"
          :model="bindPartData">
          <el-form-item label="零件号:" prop="partNo">
            <el-input v-model="bindPartData.partNo" size="small" :disabled="dialogTitle == '修改零件绑定'"></el-input>
          </el-form-item>
          <el-form-item label="颜色:" prop="color">
            <el-input v-model="bindPartData.color" size="small"></el-input>
          </el-form-item>
          <el-form-item label="色标:" prop="colorCode">
            <el-input v-model="bindPartData.colorCode" size="small"></el-input>
          </el-form-item>
          <el-form-item label="进厂检验项:" prop="inspectionItem" v-if="currentObj.objectType == '原材料'" label-width="100px">
            <!-- <el-input v-model="bindPartData.inspectionItem" disabled placeholder="选择检验项" size="small">
              <template slot="append">
                <el-button slot="append" icon="el-icon-search" @click="openItems"></el-button>
              </template>
</el-input> -->
            <el-select v-model="bindPartData.inspectionItem" multiple collapse-tags placeholder="请选择" size="small">
              <el-option v-for="item in itemList" :key="item.inspectionItem" :label="item.inspectionItem"
                :value="item.inspectionItem">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeBindPartDialog">取 消</el-button>
        <el-button type="primary" @click="submitBind">确 认</el-button>
      </span>
    </el-dialog>
    <el-dialog title="修改记录" :visible.sync="editItem" width="900px">
      <div class="body" v-if="editItem">
        <lims-table :tableData="editList" :column="editColumn" height="460px" :tableLoading="tableLoading0" :key="2"
          :page="editPage" @pagination="editPagination"></lims-table>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import limsTable from "@/components/Table/lims-table.vue";
import {
  addProductPart,
  addTestObjectPart,
  deleteProductPart,
  deleteTestObjectPart,
  selectByProductId,
  selectByTestObjectId,
  updateProductPart,
  updateTestObjectPart,
  inspectionItems,
  productPartReview,
  productPartLogList
} from "@/api/structural/structureTestObjectPart";
 
export default {
  name: "bindPartDialog",
  // import 引入的组件需要注入到对象中才能使用
  components: { limsTable },
  props: {
    bindPartDialog: {
      type: Boolean,
      default: () => false
    },
    type: { // 零件绑定的类型--0:检验对象,1:产品维护
      type: Number,
      default: () => null
    },
    currentRow: { // 选择本条数据的信息
      type: Object,
      default: () => { }
    },
    currentObj: {//当前对象
      type: Object,
      default: () => { }
    },
  },
  data() {
    // 这里存放数据
    return {
      isShow: this.bindPartDialog,
      dialogTitle: '新增零件绑定',
      operationType: '',
      tableData: [],
      tableLoading: false,
      column: [
        { label: '零件号', prop: 'partNo' },
        { label: '颜色', prop: 'color' },
        { label: '色标', prop: 'colorCode' },
        { label: '进厂检验项', prop: 'inspectionItem' },
        {
          label: '状态', prop: 'review',
          dataType: "tag",
          formatType: (params) => {
            if (params == '待复核') {
              return 'danger'
            } else {
              return 'success'
            }
          },
        },
        {
          dataType: 'action',
          fixed: 'right',
          label: '操作',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.addBindPart('edit', row);
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.delete(row);
              },
            },
            {
              name: '复核',
              type: 'text',
              clickFun: (row) => {
                this.$confirm("是否复核通过?", "复核", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                })
                  .then(() => {
                    productPartReview({ id: row.id }).then((res) => {
                      if (res.code == 200) {
                        this.$message.success("复核通过");
                        this.getList();
                      }
                    });
                  })
                  .catch(() => { });
              },
            },
            {
              name: '记录',
              type: 'text',
              clickFun: (row) => {
                this.lookList(row);
              },
            },
          ]
        }
      ],
      page: {
        total: 0,
        size: 10,
        current: 1,
        layout: 'total, prev, pager, next'
      },
      bindPartComponent: {
        entity: {
          orderBy: {
            field: 'id',
            order: 'asc'
          }
        },
        isPage: true,
        isIndex: true,
        showSelect: false,
        select: true,
        do: [{
          id: 'update',
          font: '编辑',
          type: 'text',
          method: 'doDiy',
          field: []
        }, {
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        }],
        tagField: {},
        selectField: {},
        requiredAdd: ['partNo'],
        requiredUp: ['partNo'],
      },
      addBindPartDialog: false,
      bindPartData: {
        partNo: '', // 零件号
        color: '', // 颜色
        colorCode: '', // 色标
        inspectionItem: [],//原材料进厂检验对象列表
      },
      bindPartDataRules: {
        partNo: [
          { required: true, message: '请填写零件号', trigger: 'blur' }
        ]
      },
      bindLoad: false,
      upIndex: 0,
 
      addBindLoad: false,
      itemList: [],//原材料进厂检验对象列表
      editItem: false,
      editList: [],
      editColumn: [
        { label: '零件号', prop: 'partNo' },
        { label: '颜色', prop: 'color' },
        { label: '色标', prop: 'colorCode' },
        { label: '进厂检验项', prop: 'inspectionItem' },
        {
          label: '状态', prop: 'review',
          dataType: "tag",
          formatType: (params) => {
            if (params == '待复核') {
              return 'danger'
            } else {
              return 'success'
            }
          },
        },
        { label: '修改时间', prop: 'operTime' },
        { label: '修改人', prop: 'operName' },
      ],
      editPage: {
        total: 0,
        size: 10,
        current: 0,
      },
      tableLoading0: false,
      currentPart: {},//当前零件
      // mutilSelect: []
    }
  },
  mounted() {
    this.getList()
    this.getItemList()
  },
  // 方法集合
  methods: {
    getItemList() {
      // this.tableLoading0 = true;
      inspectionItems({
        sample: this.currentObj.specimenName,
        productName: this.type == 0 ? null : this.currentRow.name
      }).then(res => {
        this.itemList = res.data
        // this.tableLoading0 = false;
      })
    },
    // 修改记录
    lookList(row) {
      this.currentPart = row;
      this.editItem = true;
      this.getEditList()
    },
    getEditList() {
      this.tableLoading0 = true
      productPartLogList({ id: this.currentPart.id, ...this.editPage }).then(res => {
        this.tableLoading0 = false
        if (res.code == 200) {
          this.editList = res.data.records
          this.editPage.total = res.data.total
        }
      })
    },
    editPagination() {
      this.editPage.current = page;
      this.editPage.size = limit;
      this.getEditList();
    },
    getList() {
      this.tableLoading = true
      // 根据类型判断是检验对象零件绑定还是产品维护零件绑定
      if (this.type === 0) {
        selectByTestObjectId({ testObjectId: this.currentRow.id }).then(res => {
          this.tableLoading = false
          if (res.code === 200) {
            this.tableData = res.data.records
            this.page.total = res.data.total
          }
        }).catch(err => {
          this.tableLoading = false
        })
      } else {
        selectByProductId({ productId: this.currentRow.id }).then(res => {
          this.tableLoading = false
          if (res.code === 200) {
            this.tableData = res.data.records
            this.page.total = res.data.total
          }
        }).catch(err => {
          this.tableLoading = false
        })
      }
    },
    addBindPart(type, row) {
      this.addBindPartDialog = true
      this.dialogTitle = type === 'add' ? '新增零件绑定' : '修改零件绑定'
      this.operationType = type
      if (type === 'edit') {
        this.bindPartData = this.HaveJson(row)
        this.bindPartData.inspectionItem = this.bindPartData.inspectionItem ? this.bindPartData.inspectionItem.split(',') : []
      } else {
        this.bindPartData = {}
      }
    },
    // 提交零件绑定
    submitBind() {
      this.$refs['bindPartData'].validate((valid) => {
        if (valid) {
          // 根据类型判断是检验对象零件绑定还是产品维护零件绑定
          const params = this.type === 0 ? {
            testObjectId: this.currentRow.id,
            color: this.bindPartData.color,
            colorCode: this.bindPartData.colorCode,
            partNo: this.bindPartData.partNo,
            id: this.bindPartData.id,
            inspectionItem: this.bindPartData.inspectionItem && this.bindPartData.inspectionItem.length > 0 ? this.bindPartData.inspectionItem.join(',') : ''
          } : {
            productId: this.currentRow.id,
            color: this.bindPartData.color,
            colorCode: this.bindPartData.colorCode,
            partNo: this.bindPartData.partNo,
            id: this.bindPartData.id,
            inspectionItem: this.bindPartData.inspectionItem && this.bindPartData.inspectionItem.length > 0 ? this.bindPartData.inspectionItem.join(',') : ''
          }
          this.bindLoad = true
          if (this.operationType === 'add') {
            if (this.type === 0) {
              addTestObjectPart(params).then(res => {
                this.bindLoad = false
                if (res.code === 200) {
                  this.resetForm('bindPartData')
                  this.addBindPartDialog = false
                  this.$message.success('新增成功')
                  this.getList()
                }
              }).catch(err => {
                this.bindLoad = false
                console.log(err)
              })
            } else {
              addProductPart(params).then(res => {
                this.bindLoad = false
                if (res.code === 200) {
                  this.resetForm('bindPartData')
                  this.addBindPartDialog = false
                  this.$message.success('新增成功')
                  this.getList()
                }
              }).catch(err => {
                this.bindLoad = false
                console.log(err)
              })
            }
          } else {
            if (this.type === 0) {
              updateTestObjectPart(params).then(res => {
                if (res.code === 200) {
                  this.resetForm('bindPartData')
                  this.addBindPartDialog = false
                  this.$message.success('修改成功')
                  this.getList()
                }
              }).catch(err => {
                this.bindLoad = false
                console.log(err)
              })
            } else {
              updateProductPart(params).then(res => {
                if (res.code === 200) {
                  this.resetForm('bindPartData')
                  this.addBindPartDialog = false
                  this.$message.success('修改成功')
                  this.getList()
                }
              }).catch(err => {
                this.bindLoad = false
                console.log(err)
              })
            }
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      })
    },
    delete(row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.type === 0) {
          deleteTestObjectPart({ id: row.id }).then(res => {
            if (res.code === 200) {
              this.$message.success('删除成功')
              this.getList();
            }
          })
        } else {
          deleteProductPart({ id: row.id }).then(res => {
            if (res.code === 200) {
              this.$message.success('删除成功')
              this.getList();
            }
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      })
    },
    closeBindPartDialog() {
      this.resetForm('bindPartData')
      this.addBindPartDialog = false
    },
    // openItems() {
    //   this.mutilSelect = this.bindPartData.inspectionItem ? this.bindPartData.inspectionItem.split(',') : []
    //   this.$refs.itemTable.toggleRowSelection(this.mutilSelect)
    //   this.addBindItem = true;
    // },
    // submitBindItem() {
    //   this.bindPartData.inspectionItem = this.mutilSelect.join(',')
    // },
    // handleSelectionChange(val) {
    //   this.mutilSelect = val
    // }
  },
}
</script>
 
<style scoped></style>