zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-tabs type="card">
      <el-tab-pane label="主要信息">
        <el-card class="operation-capacity" header="不合格处理">
          <el-form
            :model="dataForm"
            :rules="dataRule"
            ref="dataForm"
            label-width="120px"
            class="l-mes"
            :disabled="showTable"
          >
            <el-row>
              <el-col :span="8">
                <el-form-item label="编号" prop="processNo">
                  <el-input
                    v-model="dataForm.processNo"
                    placeholder=""
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="申请人" prop="initiatingOrganization">
                  <el-input
                    v-model="dataForm.initiatingOrganization"
                    placeholder=""
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="种类" prop="type">
                  <el-select
                    v-model="dataForm.type"
                    placeholder="种类"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in typeOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="7">
                <el-form-item label="接收人" prop="receiver">
                  <el-input
                    v-model="dataForm.receiver"
                    placeholder=""
                  ></el-input>
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="不合格类别" prop="unqualifiedType">
                  <el-select
                    v-model="dataForm.unqualifiedType"
                    placeholder="不合格类别"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in unqualifiedTypeOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="原因类型" prop="causeType">
                  <el-select
                    v-model="dataForm.causeType"
                    placeholder="原因类型"
                    filterable
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in causeTypeOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="原因" prop="reason">
                  <el-input
                    type="textarea"
                    :rows="1"
                    placeholder=""
                    v-model="dataForm.reason"
                  ></el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="6">
                <el-form-item label="申请处理方式" prop="processMode">
                  <el-select
                    v-model="dataForm.processMode"
                    placeholder="申请处理方式"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in processModeOptions"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="不合格处理描述" prop="unqualifiedDesc">
                  <el-input
                    :maxlength="200"
                    v-model="dataForm.unqualifiedDesc"
                    type="textarea"
                    :rows="2"
                    placeholder=""
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="整改措施" prop="correctiveMeasures">
                  <el-input
                    v-model="dataForm.correctiveMeasures"
                    type="textarea"
                    :rows="2"
                    placeholder=""
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
              <el-col :span="8">
                <el-form-item label="处理结果" prop="processResult">
                  <el-select
                    v-model="dataForm.processResult"
                    placeholder="处理结果"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in processResultOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select> </el-form-item
              ></el-col>
            </el-row> -->
          </el-form>
        </el-card>
        <el-card class="operation-capacity">
          <div slot="header" class="clearfix">
            <span>不合格零件</span>
            <el-button
              v-if="!dataForm.id"
              style="float: right; padding: 3px 0"
              type="text"
              @click="openUnQualifiedPart"
              >添加零件</el-button
            >
          </div>
          <el-row>
            <el-col :span="24">
              <el-table
                stripe
                ref="applyPartList"
                :data="applyPartList"
                height="200px"
                :row-style="{ height: '26px' }"
              >
                <el-table-column
                  label="系统编号"
                  prop="systemNo"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column
                  label="零件批号"
                  prop="lotBatchNo"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column
                  label="零件编号"
                  prop="partNo"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column
                  label="零件名称"
                  prop="partDesc"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column
                  label="不合格数量"
                  prop="unqualifiedArrived"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column
                  label="备注"
                  prop="remark"
                  align="center"
                  min-width="75px"
                  :show-overflow-tooltip="true"
                />
                <el-table-column align="center" label="操作" width="100">
                  <template slot-scope="scope">
                    <el-button
                      v-if="!dataForm.id"
                      @click="delRow(scope.$index)"
                      type="text"
                      size="small"
                      class="red-but"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
        </el-card>
      </el-tab-pane>
      <el-tab-pane v-if="dataForm.id && !showTable" label="附件">
        <div style="height:516px;">
          <el-upload
            drag
            ref="upload"
            action="/mes/unqualifiedProcess/upload"
            :headers="headers"
            :auto-upload="true"
            :before-upload="submitUpload"
            :on-success="uploadSuccess"
            :data="paramData"
            :file-list="fileList"
            list-type="text"
            :on-preview="handlePreview"
            :with-credentials="true"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处,或<em>点击上传</em>
            </div>
            <div slot="file" slot-scope="{ file }">
              <span class="el-upload-list__item-actions">
                <span>{{ file.name }}</span>
                <span
                  style="position: absolute;right: 54px;font-size: 16px;color: #67c23a;cursor: pointer;"
                >
                  <el-image
                    style="width: 16px; height: 16px;vertical-align:middle;"
                    src="/img/zoom.png"
                    :preview-src-list="[file.url]"
                  >
                  </el-image>
                </span>
                <span
                  style="position: absolute;right: 32px;font-size: 16px;color: #409eff;cursor: pointer;"
                  @click="handleDownload(file)"
                >
                  <i class="el-icon-download" style="line-height:28px;"></i>
                </span>
                <span
                  style="position: absolute;right: 10px;font-size: 16px;color: #f56c6c;cursor: pointer;"
                  @click="handleDelete(file)"
                >
                  <i class="el-icon-delete" style="line-height:28px;"></i>
                </span>
              </span>
            </div>
          </el-upload>
        </div>
      </el-tab-pane>
    </el-tabs>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`dataFormSubmit`"
        >确定</el-button
      >
    </span>
    <!-- 关联不合格零件 -->
    <unqualifiedPartDialog
      :currshowlist.sync="relateVisible"
      :paramObj="paramObj"
      :paramSelArr="paramSelArr"
      :paramSelCol="paramSelCol"
      @handleSelectionChange="setApplyPartList"
    />
  </el-dialog>
</template>
 
<script>
import {
  getUnqualifiedProcess,
  addUnqualifiedProcess,
  putUnqualifiedProcess,
  getUnqualifiedProcessAttachment,
  delUnqualifiedProcessAttachment,
  updateProcessResult
} from '@/api/quality/unqualifiedprocess'
import { remote } from '@/api/admin/dict'
import unqualifiedPartDialog from './unqualifiedpart'
import { getStore } from '@/util/store.js'
import { mapGetters } from 'vuex'
 
export default {
  data() {
    return {
      headers: {
        Authorization: 'Bearer ' + getStore({ name: 'access_token' })
      },
      paramData: { mainProcessNo: null },
      fileList: [],
      visible: false,
      dataForm: {
        id: 0,
        processNo: '',
        reason: '',
        // processMode: '',
        initiatingOrganization: null,
        receiver: null,
        correctiveMeasures: null,
        causeType: null,
        mainProcessNo: null,
        unqualifiedDesc: null,
        type: null,
        unqualifiedType: null,
        // processResult: null,
        state: null,
        workShop: null
      },
      dataRule: {
        type: [
          { required: true, message: '产品种类不能为空', trigger: 'blur' }
        ],
        unqualifiedType: [
          { required: true, message: '不合格类别不能为空', trigger: 'blur' }
        ],
        causeType: [
          { required: true, message: '原因类型不能为空', trigger: 'blur' }
        ],
        unqualifiedDesc: [
          { required: true, message: '不合格处理描述', trigger: 'blur' }
        ]
      },
      applyPartList: [],
      isSubmit: false,
      relateVisible: false,
      showTable: false,
      paramObj: {},
      paramSelArr: [],
      paramSelCol: 'id',
      causeTypeOptions: [],
      processModeOptions: [],
      typeOptions: [],
      unqualifiedTypeOptions: [],
      processResultOptions: [
        { value: '01pass', label: '通过' },
        { value: '02reject', label: '退回' }
      ]
    }
  },
  components: {
    unqualifiedPartDialog
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    getCauseType() {
      remote('unqualified_reason_type').then((response) => {
        if (response.data.code === 0) {
          this.causeTypeOptions = response.data.data
        }
      })
    },
    getProcessMode() {
      remote('unqualified_process_mode').then((response) => {
        if (response.data.code === 0) {
          this.processModeOptions = response.data.data
        }
      })
    },
    getType() {
      remote('unqualified_handle_type').then((response) => {
        if (response.data.code === 0) {
          this.typeOptions = response.data.data
        }
      })
    },
    getUnqualifiedType() {
      remote('unqualified_handle_category').then((response) => {
        if (response.data.code === 0) {
          this.unqualifiedTypeOptions = response.data.data
        }
      })
    },
    init(id) {
      this.getCauseType()
      this.getProcessMode()
      this.getType()
      this.getUnqualifiedType()
      this.dataForm.id = id || 0
      this.applyPartList = []
      this.visible = true
      this.dataForm.state = null
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        if (this.dataForm.id) {
          getUnqualifiedProcess(this.dataForm.id).then((response) => {
            const resData = response.data.data
            console.log(resData)
            this.dataForm.id = resData.id
            this.dataForm.processNo = resData.processNo
            this.dataForm.reason = resData.reason
            // this.dataForm.processMode = resData.processMode
            this.dataForm.initiatingOrganization =
              resData.initiatingOrganization
            this.dataForm.receiver = resData.receiver
            this.dataForm.correctiveMeasures = resData.correctiveMeasures
            this.dataForm.causeType = resData.causeType
            this.dataForm.mainProcessNo = resData.mainProcessNo
            this.dataForm.unqualifiedDesc = resData.unqualifiedDesc
            this.dataForm.type = resData.type
            this.dataForm.unqualifiedType = resData.unqualifiedType
            // this.dataForm.processResult = resData.processResult
            this.dataForm.state = resData.state
            this.dataForm.workShop = resData.workShop
 
            const applyPart = {
              applyPartId: resData.applyPartId,
              systemNo: resData.systemNo,
              lotBatchNo: resData.lotBatchNo,
              partNo: resData.partNo,
              partDesc: resData.partDesc,
              unqualifiedArrived: resData.unqualifiedArrived,
              remark: resData.remark
            }
            this.applyPartList.push(applyPart)
            this.getFileList()
            if (
              this.dataForm.initiatingOrganization == this.userInfo.staffName
            ) {
              this.showTable = false
            } else {
              this.showTable = true
            }
          })
        } else {
          this.showTable = false
          this.dataForm.initiatingOrganization = this.userInfo.staffName
        }
      })
    },
    // 打开不合格零件对话框
    openUnQualifiedPart() {
      if (!this.dataForm.id && this.dataForm.id != null) {
        this.paramObj = { unqualifiedProcessId: this.dataForm.id }
      } else {
        this.paramObj = {}
      }
      this.paramSelArr = []
      if (this.applyPartList.length > 0) {
        this.applyPartList.forEach((e) => {
          this.paramSelArr.push(e.applyPartId)
        })
      }
      this.relateVisible = true
    },
    // 添加不合格零件
    setApplyPartList(params) {
      if (params && params.length > 0) {
        let param
        let applyPart
        for (let i = 0; i < params.length; i++) {
          param = params[i]
          applyPart = {
            applyPartId: param.id,
            systemNo: param.systemNo,
            lotBatchNo: param.lotBatchNo,
            partNo: param.partNo,
            partDesc: param.partDesc,
            unqualifiedArrived: param.unqualifiedArrived,
            remark: param.remark
          }
          this.applyPartList.push(applyPart)
        }
      }
    },
    // 删除零件行
    delRow(index) {
      this.applyPartList.splice(index, 1)
    },
    // 表单提交
    dataFormSubmit() {
      if (this.dataForm.state == null || this.dataForm.state === '01draft') {
        this.isSubmit = true
        this.$refs.dataForm.validate((valid) => {
          if (valid) {
            if (this.dataForm.id) {
              const qualityUnqualifiedProcess = {
                id: this.dataForm.id,
                processNo: this.dataForm.processNo,
                reason: this.dataForm.reason,
                // processMode: this.dataForm.processMode,
                initiatingOrganization: this.dataForm.initiatingOrganization,
                receiver: this.dataForm.receiver,
                correctiveMeasures: this.dataForm.correctiveMeasures,
                causeType: this.dataForm.causeType,
                unqualifiedDesc: this.dataForm.unqualifiedDesc,
                type: this.dataForm.type,
                unqualifiedType: this.dataForm.unqualifiedType,
                workShop: this.dataForm.workShop,
                applyPartId: this.applyPartList[0].applyPartId
                // processResult: this.dataForm.processResult
              }
              putUnqualifiedProcess(qualityUnqualifiedProcess)
                .then((data) => {
                  this.$message.success('修改成功')
                  this.visible = false
                  this.isSubmit = false
                  this.$emit('refreshDataList')
                })
                .catch(() => {
                  this.isSubmit = false
                })
            } else {
              if (this.applyPartList.length > 0) {
                const qualityUnqualifiedProcess = []
 
                this.applyPartList.forEach((applyPart) => {
                  qualityUnqualifiedProcess.push({
                    id: 0,
                    processNo: this.dataForm.processNo,
                    reason: this.dataForm.reason,
                    // processMode: this.dataForm.processMode,
                    initiatingOrganization: this.dataForm
                      .initiatingOrganization,
                    receiver: this.dataForm.receiver,
                    correctiveMeasures: this.dataForm.correctiveMeasures,
                    causeType: this.dataForm.causeType,
                    unqualifiedDesc: this.dataForm.unqualifiedDesc,
                    type: this.dataForm.type,
                    unqualifiedType: this.dataForm.unqualifiedType,
                    applyPartId: applyPart.applyPartId,
                    // processResult: this.dataForm.processResult,
                    unqualifiedQuantity: applyPart.unqualifiedArrived
                  })
                })
 
                addUnqualifiedProcess(qualityUnqualifiedProcess)
                  .then((data) => {
                    this.$message.success('添加成功')
                    this.visible = false
                    this.isSubmit = false
                    this.$emit('refreshDataList')
                  })
                  .catch(() => {
                    this.isSubmit = false
                  })
              } else {
                this.$message.warning('请先添加不合格零件')
              }
            }
          } else {
            this.isSubmit = false
          }
        })
      } else {
        this.$message.warning('当前状态下,不能进行保存')
      }
    },
    getFileList() {
      this.fileList = []
      getUnqualifiedProcessAttachment(this.dataForm.mainProcessNo).then(
        (response) => {
          var attachments = response.data.data
          // 渲染附件
          if (attachments != null && attachments.length > 0) {
            var attachment
            var fileEl
            for (var i = 0; i < attachments.length; i++) {
              attachment = attachments[i]
              fileEl = {}
              fileEl.name = attachment.original
              fileEl.url = attachment.path
              fileEl.id = attachment.id
              fileEl.fileName = attachment.fileName
              this.fileList.push(fileEl)
            }
          }
        }
      )
    },
    // 附件上传
    submitUpload() {
      this.paramData.mainProcessNo = this.dataForm.mainProcessNo
    },
    uploadSuccess(response, file, fileList) {
      this.getFileList()
    },
    handlePreview(file) {
      window.open(file.url)
    },
    // 附件下载
    handleDownload(file) {
      window.open(file.url)
    },
    // 删除附件
    handleDelete(file) {
      delUnqualifiedProcessAttachment(file.id).then((response) => {
        this.getFileList()
      })
    },
    changeResult() {
      const changeResultParam = {
        id: this.dataForm.id
        // processResult: this.dataForm.processResult
      }
      updateProcessResult(changeResultParam)
        .then((response) => {
          const resData = response.data
          if (resData.code === 0) {
            this.$message.success('处理成功')
            this.$emit('refreshDataList')
          } else {
            this.$message.error('处理失败')
          }
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="scss" scoped>
.red-but {
  color: red;
}
</style>