Fixiaobai
2023-10-27 87ac437f65b5595c4f17c4474c525cf48623065c
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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<template>
  <div class="mod-config">
    <basic-container>
      <ttable :table="table" @handleSelectionChange="handleSelectionChange" :uploadInfo="uploadInfo" :isShowHide="true"
        :prelang="prelang" :options="options" :bottomOffset="125" :ajaxFun="ajaxFun" ref="partTable">
        <template #toolbar></template>
      </ttable>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getData"></table-form>
      <PrintLabelForm :currshowlist.sync="showPrintLabelForm" :printLabelInfo="printLabelInfo" />
    </basic-container>
    <el-dialog title="获取IFS零件" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <el-row>
        <el-col :span="6" style="height: 40px;line-height: 30px;">
          同步日期:
        </el-col>
        <el-col :span="18">
          <el-date-picker style="width: 100%;height: 100%;" v-model="selectDate" type="date" placeholder="选择日期">
          </el-date-picker>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="syncIfs">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import { fetchList, delObj, syncIfs, syncPart } from '@/api/basic/part'
import TableForm from './part-form'
import { mapGetters } from 'vuex'
import ttable from '@/views/common/ztt-table.vue'
import { remote } from '../../../api/admin/dict'
import { dateFormat,dateFormatYearMonthDate,dateFormatPlus } from '@/util/date'
import PrintLabelForm from './print-label-form.vue'
export default {
  data() {
    return {
      selectDate: "",
      dialogVisible: false,
      ajaxFun: fetchList,
      addOrUpdateVisible: false,
      multipleSelection: [],
      uploadInfo: {
        // 是否展示上传EXCEL以及对应的url
        isShow: true,
        url: '/mes/part/upload'
      },
      prelang: 'operation',
      options: {
        height: 300, // 默认高度-为了表头固定
        stripe: true, // 是否为斑马纹 table
        highlightCurrentRow: false, // 是否要高亮当前行
        border: true, // 是否有纵向边框
        lazy: false, // 是否需要懒加载
        fit: true, // 列的宽度是否自撑开
        multiSelect: true, //
        seqNo: true,
        isShowHide: true, // 是否显示显影按钮
        isSearch: false, // 高级查询按钮
        defaultOrderBy: { column: 'id', direction: 'desc' }
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // 标题
        column: [
          // 零件号
          {
            minWidth: '30',
            prop: 'partNo',
            label: '零件号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text',
            render: { fun: this.addOrUpdateHandle }
          },
          // 名称
          {
            minWidth: '120',
            prop: 'partName',
            label: '名称',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 零件类型
          {
            minWidth: '140',
            prop: 'materialType',
            label: '零件类型',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getMaterialTypeType,
            optList: () => {
              return this.getMaterialTypeList()
            }
          },
          {
            minWidth: '140',
            prop: 'materialAttribute',
            label: '零件属性',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getMaterialAttribute,
            optList: () => {
              return this.getMaterialAttributeList()
            }
          },
          // 单位
          {
            minWidth: '120',
            prop: 'unit',
            label: '单位',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getUnit,
            optList: () => {
              return this.getUnitList()
            }
          },
          // 单位
          {
            minWidth: '120',
            prop: 'sunit',
            label: '单位2',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.getUnit,
            optList: () => {
              return this.getUnitList()
            }
          },
          // 描述
          {
            minWidth: '140',
            prop: 'description',
            label: '备注',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 一级分类
          {
            minWidth: '120',
            prop: 'assortment',
            label: '一级分类',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            optList: () => {
              return this.getAssortment()
            }
          },
          // 二级分类
          {
            minWidth: '140',
            prop: 'category',
            label: '二级分类',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            optList: () => {
              return this.getCategory()
            }
          },
          // 三级分类
          {
            minWidth: '140',
            prop: 'threeLevelClassification',
            label: '三级分类',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            optList: () => {
              return this.getThreeLevelClassification()
            }
          },
          // 规格
          {
            minWidth: '140',
            prop: 'specs',
            label: '规格',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 型号
          {
            minWidth: '140',
            prop: 'partModel',
            label: '型号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 电压等级
          {
            minWidth: '140',
            prop: 'voltageLevel',
            label: '电压等级',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 特性代号1
          {
            minWidth: '140',
            prop: 'characteristic1',
            label: '特性代号1',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 特性代号2
          {
            minWidth: '140',
            prop: 'characteristic2',
            label: '特性代号2',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 特性代号3
          {
            minWidth: '140',
            prop: 'characteristic3',
            label: '特性代号3',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // IFS启用批次管理  !!this.permissions.basic_has_ifs
          {
            minWidth: '140',
            prop: 'lotTrackingIfs',
            label: 'IFS启用批次管理',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.formatLotTrackingIfs,
            optList: () => {
              return this.lotTrackingIfsOptions
            }
          },
          // 版本号
          {
            minWidth: '140',
            prop: 'engChgLevel',
            label: '版本号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 计划方法
          {
            minWidth: '140',
            prop: 'planningMethod',
            label: '计划方法',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            formatter: this.formatPlanningMethodIfs,
            optList: () => {
              return this.planningMethodOptions
            }
          },
          // 图号
          {
            minWidth: '140',
            prop: 'drawingNumber',
            label: '图号',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // EAN编码
          {
            minWidth: '120',
            prop: 'ean',
            label: 'EAN编码',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 零件族
          {
            minWidth: '120',
            prop: 'partFamilyName',
            label: '零件族',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 检验员
          {
            minWidth: '140',
            prop: 'examiner',
            label: '检验员',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'select',
            optList: () => {
              return this.getExaminerOptions()
            }
          },
          // 产品名称
          {
            minWidth: '140',
            prop: 'prodName',
            label: '产品名称',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          },
          // 节距
          {
            minWidth: '140',
            prop: 'partPitch',
            label: '节距',
            sort: true,
            isTrue: true,
            isSearch: true,
            searchInfoType: 'text'
          }
        ],
        toolbar: [
          {
            text: '新增',
            type: 'primary',
            fun: this.addOrUpdateHandle
          },
          {
            text: '获取IFS零件',
            type: 'primary',
            fun: this.syncISDate,
            loading: false
          },
          {
            text: '大标签',
            type: 'primary',
            fun: this.printLabel,
            loading: false
          }
        ],
        operator: [
          {
            text: '删除',
            type: 'text',
            size: 'small',
            fun: this.deleteHandle
          }
        ],
        operatorConfig: {
          fixed: 'right',
          label: '操作',
          width: 100,
          minWidth: 100
        }
      },
      unitList: [],
      materialTypeList: [],
      materialAttributeList: [],
      categoryList: [],
      assortmentList: [],
      lotTrackingIfsOptions: [
        { value: false, label: '否' },
        { value: true, label: '是' }
      ],
      planningMethodOptions: [],
      threeLevelClassificationOptions: [],
      showPrintLabelForm: false,
      printLabelInfo: null,
      examinerOptions: []
    }
  },
  components: {
    TableForm,
    ttable,
    PrintLabelForm
  },
  created() {
    this.table.column.find((e) => e.label === 'IFS启用批次管理').isTrue = false
    this.table.column.find((e) => e.label === '计划方法').isTrue = false
    this.getUnitType('unit')
    this.getMaterialType('material_type')
    this.getCategoryType('category')
    this.getAssortmentType('assortment')
    this.getPlanningMethodType('planning_method_type')
    this.getThreeLevelClassificationType('three_classification_type')
    this.getMaterialAttributeType()
    this.getExaminerDict('examiner_type')
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    handleClose() {
      this.selectDate = "";
      this.dialogVisible = false
    },
    // 获取数据列表
    getData() {
      this.$refs.partTable.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row == null ? null : row.id)
      })
    },
    // 删除
    deleteHandle(row) {
      this.$confirm('是否确认零件名为:' + row.partName, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      })
        .then(function () {
          return delObj(row.id)
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    },
    /**
     * 获取字典显示名称并缓存
     */
    getUnitType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.unitList = _data
        }
      })
    },
    getMaterialType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.materialTypeList = _data
        }
      })
    },
    getMaterialAttributeType() {
      remote('material_attribute').then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.materialAttributeList = _data
        }
      })
    },
    getCategoryType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.categoryList = _data
        }
      })
    },
    getAssortmentType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.assortmentList = _data
        }
      })
    },
    getPlanningMethodType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.planningMethodOptions = _data
        }
      })
    },
    getThreeLevelClassificationType(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.threeLevelClassificationOptions = _data
        }
      })
    },
    getExaminerDict(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.examinerOptions = _data
        }
      })
    },
    getUnit(row, column, cellValue) {
      this.unitList.forEach((obj) => {
        if (obj.value == cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    getMaterialTypeType(row, column, cellValue) {
      this.materialTypeList.forEach((obj) => {
        if (obj.value == cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    getMaterialAttribute(row, column, cellValue) {
      this.materialAttributeList.forEach((obj) => {
        if (obj.value == cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    // 单位下拉框查询
    getUnitList() {
      return this.unitList
    },
    // 零件类型下拉框查询
    getMaterialTypeList() {
      return this.materialTypeList
    },
    // 零件属性下拉框查询
    getMaterialAttributeList() {
      return this.materialAttributeList
    },
    // 二级分类下拉框查询
    getCategory() {
      return this.categoryList
    },
    // 二级分类下拉框查询
    getAssortment() {
      return this.assortmentList
    },
    // 三级分类下拉框查询
    getThreeLevelClassification() {
      return this.threeLevelClassificationOptions
    },
    // 检验员
    getExaminerOptions() {
      return this.examinerOptions
    },
    formatLotTrackingIfs(row, column, cellValue) {
      this.lotTrackingIfsOptions.forEach((obj) => {
        if (obj.value === cellValue) {
          cellValue = obj.label
        }
      })
      return cellValue
    },
    formatPlanningMethodIfs(row, column, cellValue) {
      this.planningMethodOptions.forEach((obj) => {
        if (obj.value === cellValue) {
          cellValue = obj.label + '、 ' + obj.description
        }
      })
      return cellValue
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 零件同步至ifs
    // syncIfs() {
    //   if (this.multipleSelection.length > 0) {
    //     const toolbars = this.table.toolbar
    //     toolbars[1].loading = true
    //     const ids = []
    //     this.multipleSelection.forEach((item) => {
    //       ids.push(item.id)
    //     })
    //
    //     syncIfs(ids)
    //       .then((res) => {
    //         const data = res.data
    //         if (data.code === 0) {
    //           this.$message.success('同步ERP成功')
    //         } else {
    //           this.$message.error('同步ERP失败')
    //         }
    //         toolbars[1].loading = false
    //       })
    //       .catch(() => {
    //         toolbars[1].loading = false
    //       })
    //   } else {
    //     this.$message.warning('请先选择零件,再进行同步!')
    //   }
    // },
    syncISDate() {
      this.dialogVisible = true
      this.selectDate = ''
    },
    dateFormat(longTypeDate) {
      var dateTypeDate = "";
      var date = new Date();
      date.setTime(longTypeDate);
      dateTypeDate += date.getFullYear();   //年    
      dateTypeDate += "-" + getMonth(date); //月     
      dateTypeDate += "-" + getDay(date);   //日    
      return dateTypeDate;
    },
    syncIfs() {
      this.table.toolbar.find((e) => e.text === '获取IFS零件').loading = true
      this.dialogVisible = false
      let datas = new FormData()
      let times = null;
      if (this.selectDate != '' && this.selectDate != null) {
        times=dateFormatPlus(this.selectDate)
      }else{
        times=null
      }
      datas.set("date", times)
      // console.log(datas.get("date"));
      // return ;np
      // console.log(datas.get("date"));
      // console.log(this.selectDate);
      // return
      syncPart(datas)
        .then((res) => {
          const data = res.data
          console.log(data);
          if (data.code === 0) {
            if (data.data > 0) {
              this.$message.success('同步成功' + data.data + "条数据")
            }
            if (data.data < 1) {
              this.$message.warning("该日期没有新的零件数据");
            }
            this.table.toolbar.find((e) => e.text === '获取IFS零件').loading = false
            this.getData()
          } else {
            this.$message.error('同步IFS失败')
            this.table.toolbar.find((e) => e.text === '获取IFS零件').loading = false
            this.getData()
          }
        })
        .catch((e) => {
          // this.$message.error('同步ERP失败:' + e)
        })
    },
    printLabel() {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        if (this.multipleSelection && this.multipleSelection.length === 1) {
          this.showPrintLabelForm = true
          this.printLabelInfo = {
            partId: null,
            partNo: this.multipleSelection[0].partNo,
            partName: this.multipleSelection[0].partName,
            outBatchNo: null,
            ifsBatchNo: null,
            productQty: null,
            lotTrackingIfs: this.multipleSelection[0].lotTrackingIfs,
            unit: this.multipleSelection[0].unit,
            customerOrderNo: null,
            customerName: null,
            operationName: null,
            workstationName: null,
            grossWeight: null,
            netWeight: null,
            theoryWeight: null,
            segmentDesc: null,
            reelNumber: null,
            reelWeight: null,
            nowTime: dateFormat(new Date()),
            productionPerson: null,
            remark: null,
            startMeterMark: null,
            endMeterMark: null
          }
        } else {
          this.$message.error('只能选择一条零件')
        }
      } else {
        this.$message.error('请选择零件')
      }
    }
  }
}
</script>