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
<template>
  <div style="height:100%;">
    <el-alert
      v-if="!operationTasks || operationTasks.length == 0"
      title="还没有工单下发到此机台!"
      type="warning"
      effect="dark"
    >
    </el-alert>
    <el-table
      v-show="operationTasks && operationTasks.length > 0"
      :data="operationTasks"
      border
      highlight-current-row
      @row-click="optaskRowManualClick"
      height="100%"
      ref="operationTaskTable"
    >
      <el-table-column align="center" width="55" label="单选">
        <template slot-scope="scope">
          <el-checkbox
            class="operation-task-table-single-checkbox"
            v-model="scope.row.commonChecked"
            disabled
          ></el-checkbox>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="status"
        label="状态变更"
        width="100"
      >
        <template slot-scope="scope">
          <el-select
            v-model="scope.row.statusAction"
            placeholder="更改状态"
            @change="
              changeTaskState(
                scope.row.statusAction,
                scope.row.status,
                scope.row.id
              )
            "
          >
            <el-option
              v-for="ele in statusActions"
              :key="ele.value"
              :label="ele.label"
              :value="ele.value"
              :disabled="ele.disabled"
            >
            </el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="customerOrderNo"
        label="订单号"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="mpsNo"
        label="主计划号"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="partName"
        label="零件名称"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="discNum"
        label="盘长"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span>
            {{
              scope.row.discNum == null
                ? 0
                : (scope.row.plannedQuantity / scope.row.discNum).toFixed(5)
            }}{{ scope.row.unit }}*{{
              scope.row.discNum == null ? 0 : scope.row.discNum
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="operationName"
        label="工序"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="plannedQuantity"
        label="计划数量"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="completedQuantity"
        label="完成数量"
        width="100"
        show-overflow-tooltip
      >
      </el-table-column>
    </el-table>
  </div>
</template>
<style lang="scss" scoped>
.operation-task-table-single-checkbox
  >>> .el-checkbox__input.is-disabled.is-checked
  .el-checkbox__inner {
  background-color: #006eff;
  border-color: #006eff;
}
.operation-task-table-single-checkbox
  >>> .el-checkbox__input.is-disabled
  .el-checkbox__inner {
  background-color: #ffffff;
  cursor: pointer;
}
.operation-task-table-single-checkbox >>> .el-checkbox__inner::after {
  border: 1px solid #fff !important;
  border-left: 0 !important;
  border-top: 0 !important;
  cursor: pointer !important;
}
</style>
<script>
import {
  getOperationTask,
  changeOperationTaskState
} from '@/api/product/personboard'
import { getOperationTaskById, checkIsStart } from '@/api/plan/operationtask'
const task_storage_key = 'OPERATION_TASK_ID'
export default {
  props: {
    workstationId: {
      type: Number
    },
    productSn: {
      type: String
    },
    orderNumber: {
      type: String
    },
    spec: {
      type: String
    },
    mpsNo: {
      type: String
    }
  },
  data() {
    return {
      operationTasks: [],
      currOperateTask: {
        id: null,
        taskNo: null,
        technologyName: null,
        technologyRequire: null,
        partName: null,
        manufacturingOrder: null,
        status: null,
        statusDesc: null,
        saleOrder: null,
        custom: null,
        remark: null,
        partId: null,
        partNo: null,
        unit: null,
        operationName: null,
        routingId: null,
        operationId: null,
        discNum: null,
        routingOperationRemark: null,
        mpsNo: null,
        customerName: null,
        productName: null,
        moNo: null,
        customerOrderNo: null,
        commonChecked: false,
        statusAction: null,
        reelSpec: null,
        sunit: null
      },
      statusActions: [
        { value: 'start', label: '开始', disabled: false },
        { value: 'over', label: '结束', disabled: false }
      ]
    }
  },
  created() {
    if (!this.defaultOperationId) {
      const opId = localStorage.getItem(task_storage_key)
      if (opId) {
        this.defaultOperationId = parseInt(opId)
        this.currOperateTask.id = this.defaultOperationId
      }
    }
    this.loadOperateTaskByWorkstation(this.currOperateTask.id)
  },
  methods: {
    optaskRowManualClick(row) {
      if (!row.commonChecked) {
        const checkOptask = {
          id: row.id,
          workstationId: this.workstationId
        }
        checkIsStart(checkOptask)
          .then((response) => {
            const resData = response.data.data
            const resCode = response.data.code
            if (resCode === 0) {
              if (resData) {
                this.optaskRowClick(row)
              } else {
                this.$message.warning('当前工单优先级较低,不可先进行生产')
              }
            } else {
              console.log('校验工单优先级时,code返回值为1')
            }
          })
          .catch(() => {})
      } else {
        // 取消工单选中
        this.optaskRowClick(row)
      }
    },
    optaskRowClick(row) {
      this.operationTasks.forEach((item) => {
        if (row.id !== item.id) {
          item.commonChecked = false
        }
      })
      if (row.commonChecked) {
        row.commonChecked = false
        this.currOptask = null
        this.$refs.operationTaskTable.setCurrentRow()
      } else {
        row.commonChecked = true
        this.currOptask = row
        this.$refs.operationTaskTable.setCurrentRow(row)
      }
      this.currentTaskChange(row)
      // 点击工单时,触发事件,当前选中工单信息
      this.$emit('changeCurrOperateTask', this.currOperateTask)
    },
    // 为当前工单赋值
    currentTaskChange(val) {
      if (val.commonChecked) {
        var operationTask = val
        this.currOperateTask.id = operationTask.id
        this.currOperateTask.taskNo = operationTask.taskNo
        this.currOperateTask.technologyName = operationTask.technologyName
        this.currOperateTask.technologyRequire = operationTask.technologyRequire
        this.currOperateTask.partName = operationTask.partName
        this.currOperateTask.manufacturingOrder =
          operationTask.manufacturingOrder
        this.currOperateTask.status = operationTask.status
        this.currOperateTask.statusDesc = operationTask.statusDesc
        this.currOperateTask.saleOrder = operationTask.saleOrder
        this.currOperateTask.custom = operationTask.custom
        this.currOperateTask.remark = operationTask.remark
        this.currOperateTask.partNo = operationTask.partNo
        this.currOperateTask.partId = operationTask.partId
        this.currOperateTask.unit = operationTask.unit
        this.currOperateTask.operationName = operationTask.operationName
        this.currOperateTask.routingId = operationTask.routingId
        this.currOperateTask.operationId = operationTask.operationId
        this.currOperateTask.partNo = operationTask.partNo
        this.currOperateTask.moNo = operationTask.moNo
        this.currOperateTask.optaskNo = operationTask.optaskNo
        this.currOperateTask.operationName = operationTask.operationName
        this.currOperateTask.plannedQuantity = operationTask.plannedQuantity
        this.currOperateTask.completedQuantity = operationTask.completedQuantity
        this.currOperateTask.priority = operationTask.priority
        this.currOperateTask.unit = operationTask.unit
        this.currOperateTask.plannedStartDate = operationTask.plannedStartDate
        this.currOperateTask.plannedFinishDate = operationTask.plannedFinishDate
        this.currOperateTask.actualStartDate = operationTask.actualStartDate
        this.currOperateTask.actualFinishDate = operationTask.actualFinishDate
        this.currOperateTask.createTime = operationTask.createTime
        this.currOperateTask.discNum = operationTask.discNum
        this.currOperateTask.routingOperationRemark =
          operationTask.routingOperationRemark
        this.currOperateTask.mpsNo = operationTask.mpsNo
        this.currOperateTask.customerName = operationTask.customerName
        this.currOperateTask.productName = operationTask.productName
        this.currOperateTask.customerOrderNo = operationTask.customerOrderNo
        this.currOperateTask.commonChecked = operationTask.commonChecked
        this.currOperateTask.statusAction = operationTask.statusAction
        this.currOperateTask.reelSpec = operationTask.reelSpec
        this.currOperateTask.sunit = operationTask.sunit
      } else {
        this.initOperateTask()
      }
    },
    // 更改工单状态
    changeTaskState(statusAction, taskStatus, taskId) {
      let changeFlag = false
      let changeEvent
      if (statusAction === 'start') {
        if (taskStatus === '01pending') {
          changeFlag = true
          changeEvent = 'START'
        } else {
          this.$message.error('工单不是【等待】状态,无法开始。')
        }
      }
      if (statusAction === 'over') {
        if (taskStatus === '02inProgress') {
          changeFlag = true
          changeEvent = 'COMPLETE'
        } else {
          this.$message.error('工单不是【进行中】状态,无法结束')
        }
      }
      if (changeFlag) {
        changeOperationTaskState([taskId], changeEvent).then((response) => {
          if (response.data.code === 0) {
            this.$message.success('工单状态变更成功')
            // 刷新工单列表
            this.loadOperateTaskByWorkstation(this.currOperateTask.id)
          } else {
            this.$message.success('工单状态变更失败')
          }
        })
      }
    },
    // 根据工作站,加载工单信息,选中当前工单
    loadOperateTaskByWorkstation(taskId) {
      return new Promise((resolve, reject) => {
        this.operationTasks = []
        if (this.workstationId && this.workstationId != null) {
          var query = { workstationId: this.workstationId }
          if (this.productSn && this.productSn != null) {
            query.productSn = this.productSn
          }
          if (this.orderNumber && this.orderNumber != null) {
            query.salesOrder = this.orderNumber
          }
          if (this.spec && this.spec != null) {
            query.productName = this.spec
          }
          if (this.mpsNo && this.mpsNo != null) {
            query.mpsNo = this.mpsNo
          }
          getOperationTask(query)
            .then((response) => {
              var data = response.data
              if (data.code === 0) {
                var tasks = data.data
                var operationTask
                for (var i = 0; i < tasks.length; i++) {
                  operationTask = {}
                  Object.assign(operationTask, tasks[i])
                  operationTask.taskNo = tasks[i].optaskNo
                  if (tasks[i].state == '01pending') {
                    operationTask.cssStyle = 'waitClass'
                  } else if (tasks[i].state == '02inProgress') {
                    operationTask.cssStyle = 'inprogressClass'
                  } else if (tasks[i].state == '03interrupted') {
                    operationTask.cssStyle = 'pauseClass'
                  } else if (tasks[i].state == '04completed') {
                    operationTask.cssStyle = 'completeClass'
                  }
                  operationTask.completedQuantity =
                    tasks[i].completedQuantity == null
                      ? 0
                      : tasks[i].completedQuantity
                  operationTask.technologyRequire =
                    tasks[i].technologyRequirement
                  operationTask.status = tasks[i].state
                  operationTask.statusDesc = this.formaterState(tasks[i].state)
                  operationTask.custom = tasks[i].customer
                  operationTask.saleOrder = tasks[i].salesOrder
                  operationTask.partNo = tasks[i].partNo
                  operationTask.moNo = tasks[i].moNo
                  operationTask.optaskNo = tasks[i].optaskNo
                  operationTask.operationName = tasks[i].operationName
                  operationTask.plannedQuantity = tasks[i].plannedQuantity
                  operationTask.completedQuantity = tasks[i].completedQuantity
                  operationTask.priority = tasks[i].priority
                  operationTask.unit = tasks[i].unit
                  operationTask.plannedStartDate = tasks[i].plannedStartDate
                  operationTask.plannedFinishDate = tasks[i].plannedFinishDate
                  operationTask.actualStartDate = tasks[i].actualStartDate
                  operationTask.actualFinishDate = tasks[i].actualFinishDate
                  operationTask.createTime = tasks[i].createTime
                  operationTask.statusAction = null
                  operationTask.discNum = tasks[i].discNum
                  operationTask.routingOperationRemark =
                    tasks[i].routingOperationRemark
                  operationTask.mpsNo = tasks[i].mpsNo
                  operationTask.customerName = tasks[i].customerName
                  operationTask.productName = tasks[i].productName
                  operationTask.customerOrderNo = tasks[i].customerOrderNo
                  operationTask.partName = tasks[i].partName
                  operationTask.reelSpec = tasks[i].reelSpec
                  operationTask.sunit = tasks[i].sunit
                  operationTask.commonChecked = false
                  this.operationTasks.push(operationTask)
                }
                // 选中当前工单
                if (
                  this.operationTasks.length > 0 &&
                  taskId != null &&
                  taskId
                ) {
                  let isResetCurrOpertionTaskFlag = true
                  let currTask
                  for (var k = 0; k < this.operationTasks.length; k++) {
                    if (this.operationTasks[k].id === taskId) {
                      isResetCurrOpertionTaskFlag = false
                      currTask = this.operationTasks[k]
                      break
                    }
                  }
                  if (!isResetCurrOpertionTaskFlag) {
                    const checkOptask = {
                      id: taskId,
                      workstationId: this.workstationId
                    }
                    checkIsStart(checkOptask)
                      .then((response) => {
                        const resData = response.data.data
                        const resCode = response.data.code
                        if (resCode === 0) {
                          if (resData) {
                            this.optaskRowClick(currTask)
                          } else {
                            this.$message.warning(
                              '当前工单优先级较低,不可先进行生产'
                            )
                            this.initOperateTask()
                            this.$emit(
                              'changeCurrOperateTask',
                              this.currOperateTask
                            )
                          }
                        } else {
                          this.initOperateTask()
                          this.$emit(
                            'changeCurrOperateTask',
                            this.currOperateTask
                          )
                        }
                      })
                      .catch(() => {
                        this.initOperateTask()
                        this.$emit(
                          'changeCurrOperateTask',
                          this.currOperateTask
                        )
                      })
                  } else {
                    // 若当前工单在工单列表未被找到且当前工单状态为已完成或已取消时,则将当前工单重置为空并抛出事件,否则不管
                    getOperationTaskById(taskId).then((res) => {
                      const resData = res.data
                      if (resData.code === 0) {
                        // 当前工单状态为已完成或已取消或不存在
                        if (resData.data.status === '1') {
                          this.initOperateTask()
                          this.$emit(
                            'changeCurrOperateTask',
                            this.currOperateTask
                          )
                        }
                      }
                    })
                  }
                } else if (
                  this.operationTasks.length <= 0 &&
                  taskId != null &&
                  taskId
                ) {
                  // 工单列表为空,且taskId有值,则找到且当前工单状态为已完成或已取消时,将当前工单重置为空并抛出事件,否则不管
                  getOperationTaskById(taskId).then((res) => {
                    var resData = res.data
                    if (resData.code === 0) {
                      // 当前工单状态为已完成或已取消或不存在
                      if (resData.data.status === '1') {
                        this.initOperateTask()
                        this.$emit(
                          'changeCurrOperateTask',
                          this.currOperateTask
                        )
                      }
                    }
                  })
                }
 
                resolve()
              } else {
                this.$message.error('获取工单信息失败')
                reject()
              }
            })
            .catch((error) => {
              reject(error)
            })
        }
      })
    },
    // 刷新某个工单的信息
    updateSomeOpTask() {
      const opTask = this.operationTasks.find((item) => {
        return item.id == this.currOperateTask.id
      })
      if (opTask) {
        opTask.statusAction = 'start'
      }
    },
    // 工单状态格式化
    formaterState(val) {
      var statusDesc = ''
      if (val == '01pending') {
        statusDesc = '等待'
      } else if (val == '02inProgress') {
        statusDesc = '进行中'
      } else if (val == '03interrupted') {
        statusDesc = '已暂停'
      } else if (val == '04completed') {
        statusDesc = '已完成'
      }
      return statusDesc
    },
    // 初始化页面变量
    initOperateTask() {
      this.currOperateTask.id = null
      this.currOperateTask.taskNo = null
      this.currOperateTask.technologyName = null
      this.currOperateTask.technologyRequire = null
      this.currOperateTask.partName = null
      this.currOperateTask.manufacturingOrder = null
      this.currOperateTask.status = null
      this.currOperateTask.statusDesc = null
      this.currOperateTask.saleOrder = null
      this.currOperateTask.custom = null
      this.currOperateTask.remark = null
      this.currOperateTask.partNo = null
      this.currOperateTask.partId = null
      this.currOperateTask.unit = null
      this.currOperateTask.operationName = null
      this.currOperateTask.routingId = null
      this.currOperateTask.operationId = null
      this.currOperateTask.partNo = null
      this.currOperateTask.partId = null
      this.currOperateTask.unit = null
      this.currOperateTask.operationName = null
      this.currOperateTask.routingId = null
      this.currOperateTask.operationId = null
      this.currOperateTask.partNo = null
      this.currOperateTask.moNo = null
      this.currOperateTask.optaskNo = null
      this.currOperateTask.operationName = null
      this.currOperateTask.plannedQuantity = null
      this.currOperateTask.completedQuantity = null
      this.currOperateTask.priority = null
      this.currOperateTask.unit = null
      this.currOperateTask.plannedStartDate = null
      this.currOperateTask.plannedFinishDate = null
      this.currOperateTask.actualStartDate = null
      this.currOperateTask.actualFinishDate = null
      this.currOperateTask.createTime = null
      this.currOperateTask.discNum = null
      this.currOperateTask.routingOperationRemark = null
      this.currOperateTask.mpsNo = null
      this.currOperateTask.customerName = null
      this.currOperateTask.productName = null
      this.currOperateTask.customerOrderNo = null
      this.currOperateTask.commonChecked = false
      this.currOperateTask.statusAction = null
      this.currOperateTask.reelSpec = null
      this.currOperateTask.sunit = null
    }
  },
  watch: {
    workstationId() {
      if (this.workstationId) {
        this.loadOperateTaskByWorkstation(this.currOperateTask.id)
      }
    },
    currOperateTask: {
      handler(newValue, oldValue) {
        if (newValue.id) {
          localStorage.setItem(task_storage_key, newValue.id)
        } else {
          localStorage.setItem(task_storage_key, null)
        }
      },
      deep: true
    }
  }
}
</script>