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
<template>
  <div>
    <el-alert
      v-if="!operationTasks || operationTasks.length == 0"
      title="还没有工单下发到此机台!"
      type="warning"
      effect="dark"
    >
    </el-alert>
    <el-card
      v-for="(item, index) in operationTasks"
      @click.native="setCheckFlag(item)"
      shadow="hover"
      :class="[
        'task-item',
        item.checkFlag ? 'card-checked-bgcolor' : 'card-bgcolor'
      ]"
    >
      <div class="title">
        <div class="part-info">
          <label class="name">{{ item.partName }}</label>
          <label class="no">{{ item.partNo }}</label>
        </div>
        <div class="priority" title="优先级" v-if="item.priority">
          {{ item.priority }}
        </div>
      </div>
 
      <el-progress
        class="task-progress"
        :text-inside="true"
        :stroke-width="15"
        :format="formatProgress(item)"
        :percentage="
          Number((item.completedQuantity / item.plannedQuantity).toFixed(2)) *
            100
        "
      ></el-progress>
 
      <div class="task-bottom">
        <div title="编号">
          <el-image
            src="/img/icon/barcode.png"
            class="task-bottom-image"
          ></el-image>
          <label>{{ item.taskNo }}</label>
        </div>
        <div title="计划完成时间">
          <el-image
            src="/img/icon/clock.png"
            class="task-bottom-image"
          ></el-image>
          <label>{{ item.planFinishDay }}</label>
        </div>
      </div>
    </el-card>
  </div>
</template>
<style lang="scss" scoped>
.task-item {
  cursor: pointer;
  margin-bottom: 15px;
  min-height: 150px;
  border: 1px solid rgba(0, 0, 0, 0.125);
 
  .el-card__body {
    min-height: 140px;
    position: relative;
  }
 
  .title {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
 
  .priority {
    font-weight: 700;
    font-size: 25px;
    color: #e74c3c;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }
 
  .part-info {
    display: flex;
    flex-direction: column;
    margin: 6px 0;
 
    .name {
      color: #333;
      font-size: 15px;
      font-weight: 700;
      line-height: 20px;
    }
 
    .no {
      font-size: 12px;
      color: #999;
      line-height: 20px;
    }
  }
}
 
.card-checked-bgcolor {
  background-color: #bae7ff;
}
 
.task-progress {
  width: 90%;
  margin: 0 auto;
  padding-top: 20px;
  padding-bottom: 30px;
}
 
.task-progress >>> .el-progress-bar__outer {
  background-color: #bcbec3;
}
 
.task-bottom {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  font-size: 12px;
  padding: 10px 0;
  margin-top: 4px;
  color: #666;
 
  div {
    display: flex;
    align-items: center;
  }
 
  label {
    margin-left: 6px;
  }
}
 
.task-bottom-image {
  width: 16px;
  height: 16px;
}
</style>
<script>
import { getOperationTask } from '@/api/product/personboard'
import { getOperationTaskById } from '@/api/plan/operationtask'
const task_storage_key = 'OPERATION_TASK_ID'
export default {
  props: {
    workstationId: {
      type: Number
    }
  },
  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
      },
      defaultOperationId: null
    }
  },
  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: {
    // 点击工单,选中工单
    setCheckFlag(item) {
      if (item.checkFlag) {
        item.checkFlag = false
      } else {
        item.checkFlag = true
      }
      this.changeTask(item)
      this.currentTaskChange(item)
      // 点击工单时,触发事件,当前选中工单信息
      this.$emit('changeCurrOperateTask', this.currOperateTask)
    },
    // 修改各工单选中情况
    changeTask(item) {
      this.operationTasks.forEach(function(el) {
        if (item.id != el.id) {
          el.checkFlag = false
        }
      })
    },
    // 为当前工单赋值
    currentTaskChange(val) {
      if (val.checkFlag) {
        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
      } else {
        this.initOperateTask()
      }
    },
    // 格式化工单进度内容
    formatProgress(item) {
      return () => {
        return item.completedQuantity + ' / ' + item.plannedQuantity
      }
    },
    // 根据工作站,加载工单信息,选中当前工单
    loadOperateTaskByWorkstation(taskId) {
      return new Promise((resolve, reject) => {
        this.operationTasks = []
        if (this.workstationId && this.workstationId != null) {
          var query = { workstationId: this.workstationId }
          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.checkFlag = false
                  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
 
                  this.operationTasks.push(operationTask)
                }
                // 选中当前工单
                if (
                  this.operationTasks.length > 0 &&
                  taskId != null &&
                  taskId
                ) {
                  var isResetCurrOpertionTaskFlag = true
                  for (var k = 0; k < this.operationTasks.length; k++) {
                    if (this.operationTasks[k].id === taskId) {
                      this.setCheckFlag(this.operationTasks[k])
                      isResetCurrOpertionTaskFlag = false
                      break
                    }
                  }
                  // 若当前工单在工单列表未被找到且当前工单状态为已完成时,则将当前工单重置为空并抛出事件,否则不管
                  if (isResetCurrOpertionTaskFlag) {
                    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)
            })
        }
      })
    },
    // 工单状态格式化
    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
    }
  },
  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>