zouyu
2023-11-16 a4add192450f06f9e4748e6513234510f431b21e
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
<template>
  <el-dialog
    v-diadrag
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    style="min-width: 2000px"
  >
    <el-row>
      <el-form
        :model="dataForm"
        :rules="dataRule"
        ref="dataForm"
        label-width="100px"
        class="l-mes"
      >
        <el-col :span="12">
          <el-form-item label="工作站编号" prop="workstationNo">
            <el-input
              v-model="dataForm.workstationNo"
              placeholder="工作站编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="工作站名称" prop="name">
            <el-input
              v-model="dataForm.name"
              placeholder="工作站名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
          </el-form-item>
          <el-form-item label="工作中心" prop="workCenter">
            <el-select
              v-model="dataForm.workCenter"
              placeholder="工作中心"
              filterable
              style="width: 100%"
            >
              <el-option
                v-for="item in workCenterOptions"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
 
        <el-col :span="12">
          <el-form-item label="工作站类型" prop="type">
            <el-select
              v-model="dataForm.type"
              placeholder="工作站类型"
              filterable
              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-form-item label="工厂" prop="factoryId">
            <el-select 
              v-model="dataForm.factoryId"
              placeholder="工厂"
              filterable
              style="width: 100%"
            >
              <el-option
                v-for="item in factoryOptions"
                :label="item.factoryName"
                :value="item.id"
                :key="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="人工类型" prop="artificialType">
            <el-radio-group v-model="dataForm.artificialType">
              <el-radio :label="false">按组报工</el-radio>
              <el-radio :label="true">按人员报工</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-row style="width: 100%;">
      <el-tabs
        type="card"
        v-model="activeTabName"
        ref="tabs"
        style="height: 400px;width: 100%;"
      >
        <el-tab-pane label="设备" name="equip">
          <el-transfer
            filterable
            v-model="ids"
            ref="workstation"
            :data="allEquipList"
            :titles="['未关联', '已关联']"
            @change="handleChange"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="线边仓" name="feed">
          <el-transfer
            filterable
            v-model="feedLocationIds"
            ref="location"
            :data="allFeedLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangeFeedLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="机台已投料库位" name="fed">
          <el-transfer
            filterable
            v-model="fedLocationIds"
            ref="location"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangeFedLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="产出待检库位" name="inspection">
          <el-transfer
            filterable
            v-model="inspectionLocationIds"
            ref="location"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangeInspectionLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="产出不合格库位" name="disqualified">
          <el-transfer
            filterable
            v-model="disqualifiedLocationIds"
            ref="location"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangeDisqualifiedLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="产出合格库位" name="qualified">
          <el-transfer
            filterable
            v-model="qualifiedLocationIds"
            ref="location"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangeQualifiedLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <!-- <el-tab-pane label="检验待处理库位" name="pending">
          <el-transfer
            filterable
            v-model="pendingLocationIds"
            ref="location"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleChangePendingLocation"
          >
          </el-transfer>
        </el-tab-pane>
        <el-tab-pane label="成品待检库位" name="product">
          <el-transfer
            filterable
            v-model="productInspectionLocationIds"
            ref="product"
            :data="allLocation"
            :titles="['未关联', '已关联']"
            @change="handleProductInspectionLocation"
          >
          </el-transfer>
        </el-tab-pane> -->
        <el-tab-pane label="人工模板" name="handyman">
          <el-transfer
            filterable
            v-model="handymanTypeIds"
            ref="handyman"
            :data="allHandyman"
            :props="{ key: 'id', label: 'templateDescription' }"
            :titles="['未关联', '已关联']"
            @change="handleChangeHandyman"
          >
          </el-transfer>
        </el-tab-pane>
      </el-tabs>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">提交</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import { getObj, addObj, putObj } from '@/api/basic/workstation'
import { remote } from '../../../api/admin/dict'
import { loadFactoryList } from '@/api/basic/factory'
import { loadLocation } from '../../../api/warehouse/location'
import { getAllHandymanTemplate } from '../../../api/product/handymantemplate'
import { getEquipmentByFactoryId } from '../../../api/basic/workstation'
 
export default {
  data() {
    return {
      change: 'false',
      visible: false,
      dataForm: {
        id: 0,
        workstationNo: '',
        name: '',
        type: '',
        factoryId: '',
        remark: '',
        artificialType: '',
        workCenter: '',
        workstationEquipment: [],
        workstationLocation: [],
        workstationTemplate: [],
        equipments: [],
        equipmentIds: [],
        allEquipmentIds: [],
        handymanTypeIds: [],
        productInspectionLocationIds: [],
        locations: []
      },
      dataRule: {
        workstationNo: [
          { required: true, message: '工作站编号不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '工作站名称不能为空', trigger: 'blur' }
        ],
        type: [
          { required: true, message: '工作站类型不能为空', trigger: 'blur' }
        ],
        factoryId: [
          { required: true, message: '工厂不能为空', trigger: 'blur' }
        ]
      },
      allEquipmentIds: [],
      allData: [],
      ids: [],
      handymanTypeIds: [],
      feedLocationIds: [],
      fedLocationIds: [],
      inspectionLocationIds: [],
      qualifiedLocationIds: [],
      disqualifiedLocationIds: [],
      pendingLocationIds: [],
      productInspectionLocationIds: [],
      typeOptions: [],
      factoryOptions: [],
      allEquipList: [],
      allFeedLocation: [],
      allLocation: [],
      allHandyman: [],
      myHandyman: [],
      myEquipList: [],
      myFeedLocation: [],
      myFedLocation: [],
      myInspectionLocation: [],
      myQualifiedLocation: [],
      myDisqualifiedLocation: [],
      myPendingLocation: [],
      myProductInspectionLocation: [],
      workstation: [],
      equipList: [],
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false,
      workId: '',
      workstationFactory: {},
      clickDateArr: [],
      activeTabName: 'equip',
      workCenterOptions: []
    }
  },
  created() {
    this.getType()
    this.getFactory()
    this.getWorkCenter()
  },
  watch: {
    'dataForm.factoryId': {
      handler(newValue, oldValue) {
        if (!this.dataForm.id) {
          console.log(1);
          if (newValue) {
            this.workstationFactory.factoryId = this.dataForm.factoryId
            getEquipmentByFactoryId(this.workstationFactory).then(
              (response) => {
                this.allEquipList = response.data.data.equipments
              }
            )
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    handleChange(value, direction, movedKeys) {
      this.myEquipList = value
    },
    // 4个库位(投料,待检,不合格,合格)
    handleChangeFeedLocation(value, direction, movedKeys) {
      this.myFeedLocation = value
    },
    handleChangeFedLocation(value, direction, movedKeys) {
      if (value && value.length > 1) {
        this.fedLocationIds = this.myFedLocation
        this.$message.warning('该库位只能存在一个')
      } else {
        this.myFedLocation = value
      }
    },
    handleChangeInspectionLocation(value, direction, movedKeys) {
      if (value && value.length > 1) {
        this.inspectionLocationIds = this.myInspectionLocation
        this.$message.warning('该库位只能存在一个')
      } else {
        this.myInspectionLocation = value
      }
    },
    handleChangeQualifiedLocation(value, direction, movedKeys) {
      // if (value && value.length > 1) {
      //   this.qualifiedLocationIds = this.myQualifiedLocation
      //   this.$message.warning('该库位只能存在一个')
      // } else {
      this.myQualifiedLocation = value
      // }
    },
    handleChangeDisqualifiedLocation(value, direction, movedKeys) {
      if (value && value.length > 1) {
        this.disqualifiedLocationIds = this.myDisqualifiedLocation
        this.$message.warning('该库位只能存在一个')
      } else {
        this.myDisqualifiedLocation = value
      }
    },
    handleChangePendingLocation(value, direction, movedKeys) {
      if (value && value.length > 1) {
        this.pendingLocationIds = this.myPendingLocation
        this.$message.warning('该库位只能存在一个')
      } else {
        this.myPendingLocation = value
      }
    },
    handleProductInspectionLocation(value, direction, movedKeys) {
      if (value && value.length > 1) {
        this.productInspectionLocationIds = this.myProductInspectionLocation
        this.$message.warning('该库位只能存在一个')
      } else {
        this.myProductInspectionLocation = value
      }
    },
    handleChangeHandyman(value, direction, movedKeys) {
      this.myHandyman = value
    },
    getFactory() {
      loadFactoryList().then((res) => {
        this.factoryOptions = res.data
      })
    },
    getType() {
      remote('workstation_type').then((response) => {
        if (response.data.code === 0) {
          this.typeOptions = response.data.data
        }
      })
    },
    getWorkCenter() {
      remote('work_center_type').then((response) => {
        if (response.data.code === 0) {
          this.workCenterOptions = response.data.data
          this.workCenterOptions.forEach((item) => {
            item.label = '(' + item.value + ') ' + item.label
          })
        }
      })
    },
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.addVisible = true
      // 清空数据源
      this.allEquipList = []
      this.allFeedLocation = []
      this.allLocation = []
      this.allHandyman = []
      this.myEquipList = []
      this.myFeedLocation = []
      this.myFedLocation = []
      this.myInspectionLocation = []
      this.myQualifiedLocation = []
      this.myDisqualifiedLocation = []
      this.myPendingLocation = []
      this.myProductInspectionLocation = []
      this.myHandyman = []
      this.clickDateArr = []
      this.$nextTick(() => {
        // 清空穿梭框
        this.$refs.dataForm.resetFields()
        getObj(this.dataForm.id).then((response) => {
          if (this.dataForm) {
            this.dataForm = response.data.data
            console.log(this.dataForm)
            this.allEquipList = this.dataForm.equipments
            this.allFeedLocation = this.dataForm.locations
            this.allLocation = JSON.parse(
              JSON.stringify(this.dataForm.locations)
            )
            this.allLocation.forEach((e) => (e.disabled = false))
            getAllHandymanTemplate().then((res) => {
              this.allHandyman = res.data.data
            })
            this.ids = this.dataForm.equipmentIds
              ? this.dataForm.equipmentIds
              : []
            this.feedLocationIds = this.dataForm.feedLocationIds
              ? this.dataForm.feedLocationIds
              : []
            this.fedLocationIds = this.dataForm.fedLocationIds
              ? this.dataForm.fedLocationIds
              : []
 
            this.inspectionLocationIds = this.dataForm.inspectionLocationIds
              ? this.dataForm.inspectionLocationIds
              : []
            this.qualifiedLocationIds = this.dataForm.qualifiedLocationIds
              ? this.dataForm.qualifiedLocationIds
              : []
            this.disqualifiedLocationIds = this.dataForm.disqualifiedLocationIds
              ? this.dataForm.disqualifiedLocationIds
              : []
            this.pendingLocationIds = this.dataForm.inspToDealLocationIds
              ? this.dataForm.inspToDealLocationIds
              : []
            this.handymanTypeIds = this.dataForm.handymanTypeIds
              ? this.dataForm.handymanTypeIds
              : []
            this.productInspectionLocationIds = this.dataForm
              .productInspectionLocationIds
              ? this.dataForm.productInspectionLocationIds
              : []
            this.myEquipList = this.ids
            this.myFeedLocation = this.feedLocationIds
            this.myFedLocation = this.fedLocationIds
            this.myInspectionLocation = this.inspectionLocationIds
            this.myQualifiedLocation = this.qualifiedLocationIds
            this.myDisqualifiedLocation = this.disqualifiedLocationIds
            this.myPendingLocation = this.pendingLocationIds
            this.myHandyman = this.handymanTypeIds
            this.myProductInspectionLocation = this.productInspectionLocationIds
          }
        })
      })
    },
    // 表单提交
    dataFormSubmit() {
      var canClickFlag = true
      this.clickDateArr.push(new Date().getTime())
      if (this.clickDateArr.length > 1) {
        if (
          this.clickDateArr[this.clickDateArr.length - 1] -
            this.clickDateArr[this.clickDateArr.length - 2] <
          2000
        ) {
          // 小于2秒则认为重复提交
          canClickFlag = false
        }
      }
      if (canClickFlag) {
        this.$refs.dataForm.validate((valid) => {
          if (valid) {
            const upEquipmentList = new Array()
            for (let i = 0; i < this.myEquipList.length; i++) {
              upEquipmentList.push(
                Object.assign({
                  equipmentId: this.myEquipList[i],
                  workstationId: this.dataForm.id
                })
              )
            }
            this.dataForm.workstationEquipment = upEquipmentList
            const workstationLocationList = []
            for (let i = 0; i < this.myFeedLocation.length; i++) {
              workstationLocationList.push(
                Object.assign({
                  locationId: this.myFeedLocation[i],
                  workstationId: this.dataForm.id,
                  locationType: 1
                })
              )
            }
            this.myInspectionLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 2
                })
              )
            })
            this.myQualifiedLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 4
                })
              )
            })
            this.myDisqualifiedLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 3
                })
              )
            })
            this.myFedLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 5
                })
              )
            })
            this.myPendingLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 6
                })
              )
            })
            this.myProductInspectionLocation.forEach((id) => {
              workstationLocationList.push(
                Object.assign({
                  locationId: id,
                  workstationId: this.dataForm.id,
                  locationType: 9
                })
              )
            })
 
            this.dataForm.workstationLocation = workstationLocationList
 
            const workstationTemplateList = []
            for (let i = 0; i < this.myHandyman.length; i++) {
              workstationTemplateList.push(
                Object.assign({
                  handymanTemplateId: this.myHandyman[i],
                  workstationId: this.dataForm.id
                })
              )
            }
            this.dataForm.workstationTemplate = workstationTemplateList
            if (this.dataForm.id) {
              putObj(this.dataForm).then((data) => {
                this.$message.success('修改成功')
                this.visible = false
                this.$emit('refreshDataList')
              })
            } else {
              addObj(this.dataForm).then((data) => {
                this.$message.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList')
              })
            }
          }
        })
      }
    }
  }
}
</script>
<style scoped>
  
</style>