zss
2023-11-17 2518e47a3ac999978fbf14612c967c3bbf421d25
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
<template>
  <el-dialog
    top="5vh"
    :fullscreen="isFullScreen"
    :close-on-click-modal="false"
    :visible.sync="visible"
    append-to-body
  >
    <template slot="title">
      <i
        :class="isFullScreen ? 'icon-zuixiaohua' : 'icon-quanpingzuidahua'"
        style="position: absolute; right: 52px; float: right"
        @click="fullscreen"
      >
      </i>
      <span>{{ !dataForm.id ? '新增' : '修改' }}</span>
    </template>
 
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
      class="l-mes"
      :disabled="!editable"
    >
      <el-tabs type="border-card" ref="tabs">
        <el-tab-pane label="主要">
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="工厂" prop="factoryId">
                <el-select
                  v-model="dataForm.factoryId"
                  filterable
                  placeholder=""
                  style="width:100%"
                >
                  <el-option
                    v-for="item in this.factoryOptions"
                    :key="item.id"
                    :label="item.factoryName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="零件" prop="partId">
                <el-input v-model="partStr" placeholder="" readonly>
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    @click="openRoutingDialog()"
                  ></el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="需求数量" prop="qtyRequired">
                <el-input
                  v-model="dataForm.qtyRequired"
                  placeholder=""
                  @change="checkNumber()"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="需求日期" prop="requiredDate">
                <el-date-picker
                  v-model="dataForm.requiredDate"
                  style="width: 100%"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  @change="checkDate()"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="dataForm.remark" placeholder=""></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
 
        <el-tab-pane label="工艺路线">
          <!-- 之后把工艺界面嵌入进来 -->
 
          <el-row :gutter="10">
            <el-col :span="8">
              <el-form-item label="工艺路线号">
                <el-select
                  @change="routingSelectChanged"
                  v-model="dataForm.technologyRoutingId"
                  placeholder=""
                >
                  <el-option
                    v-for="item in dataForm.routingList"
                    :key="item.id"
                    :label="item.routingNo"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label-width="0px">
                <el-checkbox v-model="currentRouting.master" disabled
                  >默认工艺路线</el-checkbox
                >
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工艺路线备注">
                <el-input
                  v-model="currentRouting.description"
                  placeholder=""
                  disabled
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-table
              :data="operations"
              border
              style="width: 100%"
              height="240px"
              highlight-current-row
              :default-sort="{ prop: 'index' }"
            >
              <el-table-column type="selection" width="55" fixed="left" />
              <el-table-column prop="index" label="序号"></el-table-column>
              <el-table-column
                prop="operationNo"
                header-align="center"
                align="center"
                label="工序号"
              />
              <el-table-column
                prop="operationName"
                header-align="center"
                align="center"
                label="工序描述"
              />
              <el-table-column
                prop="remark"
                header-align="center"
                align="center"
                label="备注"
              />
            </el-table>
          </el-row>
        </el-tab-pane>
 
        <el-tab-pane label="产品结构">
          <el-row :gutter="10">
            <el-col :span="11">
              <el-form-item label="产品结构号">
                <el-select
                  @change="structureSelectChanged"
                  v-model="dataForm.technologyStructureId"
                  placeholder=""
                >
                  <el-option
                    v-for="item in dataForm.structureList"
                    :key="item.id"
                    :label="item.structureType"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="产品结构备注">
                <el-input
                  v-model="currentStructure.remark"
                  placeholder=""
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="2" style="text-align: center">
              <el-form-item label-width="0px">
                <el-button
                  type="success"
                  plain
                  circle
                  icon="el-icon-plus"
                  @click="addOrUpdateHandle()"
                ></el-button>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-table
              :data="components"
              border
              style="width: 100%"
              height="240px"
              :default-sort="{ prop: 'index' }"
            >
              <el-table-column type="selection" width="40" fixed="left" />
              <el-table-column
                type="index"
                width="60"
                header-align="center"
                align="center"
                label="行项号"
              />
              <el-table-column
                prop="operationNo"
                width="60"
                header-align="center"
                align="center"
                label="工序号"
              />
              <el-table-column
                prop="operationName"
                width="80"
                header-align="center"
                align="center"
                label="工序描述"
              />
              <el-table-column
                prop="partNo"
                width="80"
                header-align="center"
                align="center"
                label="零件号"
              />
              <el-table-column
                prop="partName"
                width="80"
                header-align="center"
                align="center"
                label="零件"
              />
              <el-table-column
                prop="qpa"
                width="120"
                header-align="center"
                align="center"
                label="单位产出所需数量"
              />
              <el-table-column
                prop="total"
                width="80"
                header-align="center"
                align="center"
                label="需求总量"
              >
                <template slot-scope="scope">
                  {{ mul(scope.row.qpa, dataForm.qtyRequired) }}
                </template>
              </el-table-column>
              <el-table-column
                prop="remark"
                width=""
                header-align="center"
                align="center"
                label="备注"
              />
              <el-table-column
                header-align="center"
                align="center"
                label="操作"
                fixed="right"
                width="130"
              >
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="small"
                    icon="el-icon-edit"
                    @click="addOrUpdateHandle(scope.row, scope.$index)"
                    >修改
                  </el-button>
                  <el-button
                    type="text"
                    size="small"
                    icon="el-icon-delete"
                    @click="deleteRow(scope.$index, components)"
                    >删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-tab-pane>
 
        <el-tab-pane label="产出批次" v-if="dataForm.id">
          <el-row :gutter="10">
            <el-table
              :data="dataForm.outBatchList"
              border
              style="width: 100%"
              height="250px"
            >
              <el-table-column type="selection" width="55" fixed="left" />
              <el-table-column
                prop="partNo"
                header-align="center"
                align="center"
                label="零件号"
              />
              <el-table-column
                prop="partDescription"
                header-align="center"
                align="center"
                label="零件名称"
              />
              <el-table-column
                prop="batchNo"
                header-align="center"
                align="center"
                label="批次号"
              />
              <el-table-column
                prop="batchQty"
                header-align="center"
                align="center"
                label="需求总量"
              />
              <el-table-column
                prop="canBeSplited"
                header-align="center"
                align="center"
                label="允许拆分"
              >
                <template slot-scope="scope">
                  <el-checkbox
                    v-model="scope.row.canBeSplited"
                    onclick="return false"
                  ></el-checkbox>
                </template>
              </el-table-column>
              <el-table-column
                prop="canBeMerged"
                header-align="center"
                align="center"
                label="允许合并"
              >
                <template slot-scope="scope">
                  <el-checkbox
                    v-model="scope.row.canBeMerged"
                    onclick="return false"
                  ></el-checkbox>
                </template>
              </el-table-column>
              <el-table-column
                prop="remark"
                header-align="center"
                align="center"
                label="备注"
              />
            </el-table>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
 
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="editable"
        >确定</el-button
      >
    </span>
 
    <!-- 结构组件弹窗, 新增 / 修改 -->
    <component-form
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
    ></component-form>
    <routingDialog
      :currshowlist.sync="showRouting"
      :queryParam="queryParam"
      @listenToRoutingEvent="selectRouting"
    />
  </el-dialog>
</template>
 
<script>
import {
  getManufacturingOrder,
  addManufacturingOrder,
  putManufacturingOrder,
  checkPart
} from '@/api/plan/manufacturingorder'
import { loadFactoryList } from '@/api/basic/factory'
import { getObj } from '@/api/technology/routing'
import { getObj as getStructure } from '@/api/technology/structure'
import ComponentForm from './structurecomponent-form'
import { validateSixDecimalNotNull } from '@/util/validate'
import { highPrecisionMul } from '@/util/highPrecision'
import routingDialog from './routing'
export default {
  components: {
    ComponentForm,
    routingDialog
  },
  data() {
    return {
      state: '',
      numberState: false,
      dateState: false,
      queryParam: {},
      showRouting: false,
      isFullScreen: false,
      addOrUpdateVisible: false,
      visible: false,
      showPart: false,
      dataForm: {
        id: 0,
        factoryId: '',
        moNo: '',
        partName: '',
        partNo: '',
        partId: '',
        qtyRequired: '',
        requiredDate: '',
        remark: '',
        technologyRoutingId: null,
        technologyStructureId: null,
        routingList: [],
        structureList: [],
        outBatchList: [],
        componentList: []
      },
      currentRouting: {}, // 当前选择的工艺
      operations: [], // 当前选择工艺对应的工序
      currentStructure: {}, // 当前选择的产品结构
      components: [], // 当前选择产品结构对应的结构组件
      factoryOptions: [],
      dataRule: {
        factoryId: [
          { required: true, message: '工厂不能为空', trigger: 'blur' }
        ],
        partId: [{ required: true, message: '零件不能为空', trigger: 'blur' }],
        qtyRequired: [
          { required: true, message: '需求数量不能为空', trigger: 'blur' },
          { validator: validateSixDecimalNotNull, trigger: 'blur' }
        ],
        requiredDate: [
          { required: true, message: '需求日期不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.initFactorySelect()
  },
  watch: {
    'dataForm.partId'(newValue, oldValue) {
      if (this.dataForm.id) {
        if (oldValue != '' && newValue != oldValue && newValue != '') {
          this.getFacturing(newValue)
        }
      } else {
        if (newValue != oldValue) {
          this.getFacturing(newValue)
        }
      }
    },
 
    currentRouting(newValue, oldValue) {
      if (newValue && newValue.id) {
        // 查询工艺对应的工序
        getObj(newValue.id).then((response) => {
          if (response.data.data) {
            this.operations = response.data.data.operations
          }
        })
      }
    },
    currentStructure(newValue, oldValue) {
      if (newValue && newValue.id) {
        // 查询产品结构对应的组件
        getStructure(newValue.id).then((response) => {
          if (
            this.dataForm.technologyStructureId &&
            this.dataForm.componentList &&
            this.dataForm.componentList.length > 0
          ) {
            this.components = this.dataForm.componentList
          } else {
            if (response.data.data) {
              this.components = response.data.data.components
            }
          }
        })
      }
    }
  },
  computed: {
    partStr: function() {
      return this.dataForm.partId
        ? this.dataForm.partName +
            '  ' +
            (this.dataForm.partNo ? this.dataForm.partNo : '')
        : ''
    },
    editable: function() {
      if (!this.dataForm.id) {
        return true
      }
      if (this.dataForm.id && this.state == '01planned') {
        return true
      }
      if (this.dataForm.id && this.state == '02issued') {
        return true
      }
      return false
    }
  },
  methods: {
    init(id, state, part) {
      this.dataForm.id = id || 0
      this.visible = true
      this.state = state
      this.$nextTick(() => {
        this.clearData()
        if (this.dataForm.id) {
          getManufacturingOrder(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
            // 把工艺挂上去
            if (
              this.dataForm.technologyRoutingId &&
              this.dataForm.routingList &&
              this.dataForm.routingList.length > 0
            ) {
              var currentRouting = this.dataForm.routingList.find(
                (item) => item.id == this.dataForm.technologyRoutingId
              )
              if (currentRouting) {
                this.currentRouting = currentRouting
                this.dataForm.technologyRoutingId = this.currentRouting.id
              }
            }
            // 把产品结构组件挂上去
            if (
              this.dataForm.technologyStructureId &&
              this.dataForm.componentList &&
              this.dataForm.componentList.length > 0
            ) {
              this.components = this.dataForm.componentList
            }
          })
        } else {
          this.$refs.tabs.currentName = '0'
          if (part) {
            this.dataForm = part
          }
        }
      })
    },
    // 根据零件号去获取制造订单对应的数据
    getFacturing(value) {
      checkPart(value)
        .then((response) => {
          var manufacturingOrderDTO = response.data.data
          this.dataForm.routingList = manufacturingOrderDTO.routingList
          this.dataForm.structureList = manufacturingOrderDTO.structureList
          this.dataForm.technologyRoutingId =
            manufacturingOrderDTO.technologyRoutingId
          if (manufacturingOrderDTO.technologyRoutingId) {
            this.routingSelectChanged(manufacturingOrderDTO.technologyRoutingId)
          } else {
            this.operations = []
          }
          this.dataForm.technologyStructureId =
            manufacturingOrderDTO.technologyStructureId
          if (manufacturingOrderDTO.technologyStructureId) {
            this.structureSelectChanged(
              manufacturingOrderDTO.technologyStructureId
            )
          } else {
            this.components = []
          }
        })
        .catch((e) => {
          this.operations = []
          this.components = []
          this.dataForm.technologyRoutingId = null
          this.dataForm.routingList = []
          this.dataForm.structureList = []
          this.dataForm.technologyStructureId = null
        })
    },
    // 需求数量与订单需求数量的比较
    checkNumber() {
      if (this.dataForm.qtyRequired > this.dataForm.qtyProductionRequired) {
        this.$message.error('需求数量大于订单需求数量')
        this.numberState = true
      } else {
        this.numberState = false
      }
    },
    checkDate() {
      if (this.dataForm.requiredDate > this.dataForm.requiredProductionDate) {
        this.$message.error('制造订单需求日期大于主生产计划需求日期')
        this.dateState = true
      } else {
        this.dateState = false
      }
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.dataForm.componentList = this.components
          if (this.numberState) {
            this.$message.error('需求数量大于订单需求数量')
            return
          }
          if (this.dateState) {
            this.$message.error('制造订单需求日期大于主生产计划需求日期')
            return
          }
          if (this.dataForm.id) {
            putManufacturingOrder(this.dataForm).then((data) => {
              this.$message.success('修改成功')
              this.visible = false
              this.$emit('refreshDataList')
            })
          } else {
            addManufacturingOrder(this.dataForm).then((data) => {
              this.$message.success('添加成功')
              this.visible = false
              this.$emit('refreshDataList')
            })
          }
        }
      })
    },
    // 1.tabs-主要
    // 零件选择
    openRoutingDialog() {
      this.showRouting = true
    },
    selectRouting(param) {
      if (param) {
        this.dataForm.partNo = param.partNo
        this.dataForm.partName = param.partName
        this.dataForm.partId = param.partId
        this.$refs.dataForm.validateField('partId', (valid) => {})
      }
    },
    // 获取工厂的数据
    initFactorySelect() {
      loadFactoryList().then((res) => {
        this.factoryOptions = res.data
      })
    },
    // 2.tabs-工艺路线
    // 工艺路线选择
    routingSelectChanged(routingId) {
      this.currentRouting = this.dataForm.routingList.find(
        (item) => item.id === routingId
      )
    },
    // 产品结构选择
    structureSelectChanged(structureId) {
      // ********这边默认选择产品结构组件的表,而不是使用制造订单的备份组件表********
      this.currentStructure = this.dataForm.structureList.find(
        (item) => item.id === structureId
      )
    },
    // 3.tabs-产品结构
    // 新增 / 修改
    addOrUpdateHandle(row, index) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row, index, this.components)
      })
    },
    // 删除
    deleteRow(index, rows) {
      rows.splice(index, 1)
    },
    // 精度计算需求总量
    mul(a, b) {
      if (!b) {
        return
      }
      return highPrecisionMul(a, b)
    },
    // 4.其他辅助方法
    // 全屏
    fullscreen() {
      this.isFullScreen = !this.isFullScreen
    },
    // 清数据
    clearData() {
      this.$refs.dataForm.resetFields()
      this.currentRouting = {}
      this.currentStructure = {}
      this.operations = []
      this.components = []
      this.dataForm.routingList = []
      this.dataForm.structureList = []
      this.dataForm.technologyRoutingId = null
      this.dataForm.technologyStructureId = null
    }
  }
}
</script>