xby-y
6 天以前 b3ff80e45d24a821ca0731983b1546b48570cdf1
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
<template>
  <dv-scroll-board :config="config" style="width:100%;height:400px" />
</template>
 
<script>
import axios from 'axios';
 
export default {
  name: 'SC02TaskInfo',
  components: {
    // 如果组件已全局注册,则不需要在这里注册
  },
  data() {
    return {
      taskList: [],
      refreshInterval: null,
      config: null
    };
  },
  mounted() {
    this.getTaskData();
    this.startAutoRefresh();
  },
  beforeDestroy() {
    this.stopAutoRefresh();
  },
  methods: {
    // 获取任务数据
    getTaskData() {
      import('@/api/api').then(({ WCS_GET }) => {
        WCS_GET('/api/Task/GetRoadwayTaskProgress', { roadway: 'SC02' })
          .then((response) => {
            console.log("SC02任务数据响应:", response);
 
            if (response && response.data && response.data.tasks) {
              // 过滤掉异常状态的任务
              this.taskList = response.data.tasks.map(task => ({
                taskNum: task.taskNum,
                taskStatus: task.taskState,
                warehouseId: 1,
                palletType: task.taskType,
                targetAddress: task.targetAddress,
                createDate: task.createDate
              })).filter(task => 
                ![999, 298, 299, 198, 199].includes(task.taskStatus)
              );
              this.updateBoardData();
            } else {
              this.taskList = [];
              this.updateBoardData();
            }
          })
          .catch((error) => {
            console.error("获取SC02任务数据失败:", error);
            this.taskList = [];
            this.updateBoardData();
          });
      });
    },
 
    // 更新滚动表格数据
    updateBoardData() {
      let boardData = [];
      if (this.taskList.length === 0) {
        boardData = [['--', '--', '--', '--', '--', '暂无任务数据']];
        return;
      }
      boardData = this.taskList.map((task) => {
        // 设置任务类型颜色
        const taskType = this.getTaskType(task);
        const typeColor = this.getTaskTypeColor(taskType);
        const typeHtml = `<span style="color:${typeColor};font-weight:bold;font-size:18px">${taskType}</span>`;
 
        // 设置托盘类型
        const palletType = this.getPalletTypeText(task);
        const palletColor = this.getPalletTypeColor(task);
        const palletHtml = `<span style="color:${palletColor};font-weight:bold;font-size:18px;padding:2px 6px;border-radius:3px;background:rgba(255,255,255,0.1)">${palletType}</span>`;
 
        // 设置目的地(显示完整货位编码)
        let targetAddress = task.targetAddress || '--';
        const addressHtml = `<span style="color:#67e0e3;font-size:20px;font-weight:bold;font-family:monospace">${targetAddress}</span>`;
 
        // 设置状态
        const statusText = this.getStatusText(task);
        const statusClass = this.getStatusClass(task);
        const statusColor = this.getStatusColor(statusClass);
        const statusHtml = `<span style="color:${statusColor};font-weight:bold;font-size:18px;padding:4px 8px;border-radius:4px;background:${this.getStatusBgColor(statusClass)}">${statusText}</span>`;
 
        // 格式化时间
        const timeText = this.formatDate(task.createDate);
        
        return [
          `<span style="color:#37a2da;font-family:monospace;font-size:18px">${task.taskNum || '--'}</span>`,
          typeHtml,
          addressHtml,
          `<span style="color:#9fe6b8;font-size:18px">${timeText}</span>`,
          statusHtml
        ];
      });
      this.config = {
        header: ['任务号', '类型', '目的地', '创建时间', '状态'],
        data: boardData,
        index: false,
        columnWidth: [100, 80, 339, 140, 180], 
        align: ['center', 'center', 'center', 'center', 'center'],
        waitTime: 2000,
        rowNum: 8,
        headerBGC: 'rgba(0, 0, 0, 0.5)',
        headerHeight: 55,
        oddRowBGC: 'rgba(0, 0, 0, 0.3)',
        evenRowBGC: 'rgba(0, 0, 0, 0.5)',
        carousel: 'single',
        // 添加字体大小设置
        headerStyle: {
          fontSize: 22,
          fontWeight: 'bold'
        },
        rowStyle: {
          fontSize: 20,
          height: 50
        }
      };
    },
 
    // 获取任务类型颜色
    getTaskTypeColor(type) {
      const colorMap = {
        '入库': '#37a2da',
        '出库': '#32c5e9',
        '移库': '#67e0e3',
        '未知': '#ffdb5c'
      };
      return colorMap[type] || '#ffdb5c';
    },
 
    // 获取托盘类型文字
    getPalletTypeText(task) {
      // 根据 warehouseId 和 palletType 判断
      const warehouseId = task.warehouseId;
      const palletType = task.palletType;
      
      if (warehouseId === 2) {
        // warehouseId=2是成品
        return '成品';
      } else if (warehouseId === 1) {
        // warehouseId=1,根据palletType判断
        if (palletType === '1' || palletType === 1) {
          return '布卷';
        } else if (palletType === '2' || palletType === 2) {
          return '松布卷';
        }
      }
      
      return '未知';
    },
 
    // 获取托盘类型颜色
    getPalletTypeColor(task) {
      const warehouseId = task.warehouseId;
      const palletType = task.palletType;
      
      if (warehouseId === 2) {
        return '#ff9f7f'; // 成品 - 橙色
      } else if (warehouseId === 1) {
        if (palletType === '1' || palletType === 1) {
          return '#9fe6b8'; // 布卷 - 绿色
        } else if (palletType === '2' || palletType === 2) {
          return '#ffdb5c'; // 松布卷 - 黄色
        }
      }
      
      return '#95a5a6'; // 未知 - 灰色
    },
 
    // 获取状态颜色
    getStatusColor(statusClass) {
      const colorMap = {
        'status-completed': '#ffffff', // 完成 - 白色文字
        'status-processing': '#ffffff', // 执行中 - 白色文字
        'status-pending': '#ffffff',   // 待处理 - 白色文字
        'status-cancelled': '#ffffff', // 取消 - 白色文字
        'status-error': '#ffffff',     // 错误 - 白色文字
        'status-default': '#ffffff'    // 默认 - 白色文字
      };
      return colorMap[statusClass] || '#ffffff';
    },
 
    // 获取状态背景颜色
    getStatusBgColor(statusClass) {
      const colorMap = {
        'status-completed': 'rgba(46, 204, 113, 0.7)', // 完成 - 绿色
        'status-processing': 'rgba(52, 152, 219, 0.7)', // 执行中 - 蓝色
        'status-pending': 'rgba(243, 156, 18, 0.7)',   // 待处理 - 橙色
        'status-cancelled': 'rgba(149, 165, 166, 0.7)', // 取消 - 灰色
        'status-error': 'rgba(231, 76, 60, 0.7)',     // 错误 - 红色
        'status-default': 'rgba(127, 140, 141, 0.7)'    // 默认 - 深灰色
      };
      return colorMap[statusClass] || 'rgba(127, 140, 141, 0.7)';
    },
 
    // 启动自动刷新
    startAutoRefresh() {
      this.refreshInterval = setInterval(() => {
        this.getTaskData();
      }, 30000);
    },
 
    // 停止自动刷新
    stopAutoRefresh() {
      if (this.refreshInterval) {
        clearInterval(this.refreshInterval);
        this.refreshInterval = null;
      }
    },
 
    // 格式化日期(简化版)
    formatDate(dateString) {
      if (!dateString) return '--';
      try {
        const date = new Date(dateString);
        return date.toLocaleTimeString('zh-CN', {
          hour: '2-digit',
          minute: '2-digit',
          second: '2-digit',
          hour12: false
        });
      } catch (e) {
        return '--';
      }
    },
 
    // 获取任务类型文字
    getTaskType(task) {
      const status = parseInt(task.taskStatus) || 0;
      
      if (status >= 200 && status < 300) {
        return '入库';
      } else if (status >= 100 && status < 200) {
        return '出库';
      } else if (status >= 300 && status <= 410) {
        return '移库';
      }
      
      return '未知';
    },
 
    // 根据状态值获取状态文字描述
    getStatusText(task) {
      const status = parseInt(task.taskStatus) || 0;
      
      if (status >= 200 && status < 300) {
        const inStatusMap = {
          215: '输送线执行中',
          220: '输送完成',
          230: '堆垛机执行中',
          235: '堆垛完成',
          290: '完成',
          297: '挂起',
          298: '取消',
          299: '异常'
        };
        return inStatusMap[status] || '入库';
      } else if (status >= 100 && status < 200) {
        const outStatusMap = {
          100: '新建',
          110: '堆垛机执行中',
          115: '堆垛完成',
          120: '输送线执行中',
          125: '输送完成',
          190: '完成',
          197: '挂起',
          198: '取消',
          199: '异常'
        };
        return outStatusMap[status] || '出库';
      } else if (status >= 300 && status < 400) {
        const relocationStatusMap = {
          300: '新建',
          315: '移库执行中',
          310: '完成',
          330: '异常'
        };
        return relocationStatusMap[status] || '移库';
      }
      
      return '未知';
    },
 
    // 获取状态对应的CSS类
    getStatusClass(task) {
      const status = parseInt(task.taskStatus) || 0;
      
      if ([298, 299, 198, 199, 330].includes(status)) {
        return 'status-error';
      } else if ([290, 190, 310].includes(status)) {
        return 'status-completed';
      } else if ([297, 197].includes(status)) {
        return 'status-cancelled';
      } else if ([230, 235, 240, 245, 110, 115, 120, 125, 315].includes(status)) {
        return 'status-processing';
      } else if ([200, 100, 300].includes(status)) {
        return 'status-pending';
      }
      
      return 'status-default';
    }
  }
};
</script>
 
<style scoped>
/* 确保滚动表格正确显示 */
dv-scroll-board {
  font-family: 'Microsoft YaHei', Arial, sans-serif;
}
</style>