wu
5 天以前 66a610d07c3c021cad0a6798cc7ccd32c5d34844
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
<script setup>
import {onBeforeUnmount, onMounted, onUnmounted, reactive, ref} from "vue";
import {useRouter} from "vue-router"
import request from "@/utils/request"
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {ElMessage, ElMessageBox} from 'element-plus'
import {useI18n} from 'vue-i18n'
const router = useRouter()
const adda = ref(false)
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const tableData = ref([])
const blindb = ref(false)
const slot = ref('')
const requestData = {
  line: 2001
};
const timeRange = ref([])
const selectValuesa = reactive([]);
// 磨边任务查询
const setEdgGlassInfoRequest = async () => {
  let celllist=[]
  let stateList=[]
  if(selectValuesa[0]!=null&&selectValuesa[0]!='undefined'){
    if(selectValuesa[0]!=""){
      celllist=[selectValuesa[0]];
    }
  }
  if(selectValuesa[1]!=null&&selectValuesa[1]!='undefined'){
    if(selectValuesa[1]!=""){
      stateList=[selectValuesa[1]];
    }
  }
  const response = await request.post("/cacheGlass/edgGlassTaskInfo/setEdgGlassInfoRequest", {
    cellList: celllist,
    stateList: stateList,
    beginDate: timeRange.value[0],
    endDate: timeRange.value[1],
  })
  if (response.code === 200) {
    ElMessage.success(response.message);
  } else {
    ElMessage.error(response.message);
  }
}
// 破损
 const open = async(row) => { 
  try {
    const confirmResult = await ElMessageBox.confirm(  
      t('workOrder.messagedamaged'), 
      t('workOrder.prompt'),  
      {  
        confirmButtonText: t('workOrder.yes'), 
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',  
      } 
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.glassId,
        state: 8,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
      ElMessage.error(response.msg);
      }  
    }  
  } catch (error) {
  }  
};  
// 拿走 
 const opena = async(row) => {  
  try {
    const confirmResult = await ElMessageBox.confirm(  
      t('workOrder.takemessage'), 
      t('workOrder.prompt'),  
      {  
        confirmButtonText: t('workOrder.yes'), 
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',  
      } 
    );
    if (confirmResult === 'confirm') {
      const response = await request.post("/cacheGlass/edgStorageCage/edgReportStatus", {
        glassId: row.glassId,
        state: 9,
        line: row.line,
        workingProcedure: '磨边',
    })
    if (response.code === 200) {
      ElMessage.success(response.message);
      } else {
      ElMessage.error(response.msg);
      }  
    }  
  } catch (error) {
  }  
};   
let socket = null;
const socketUrl = `ws://${window.ipConfig.serverUrl}/api/cacheGlass/api/talk/edgTasks`;
const handleMessage = (data) => {
  const formattedTasks = data.edgTasks[0].map(cageInfo => {
    if (cageInfo && cageInfo.createTime) {
      cageInfo.formattedCreateTime = formatTimestamp(cageInfo.createTime);
    }
    return cageInfo;
  });
  tableData.value = formattedTasks
};
//  模拟数据
// const generateMockData = () => {
//   const mockList = [
//     {
//       glassId: 'GL251209001',
//       width: 520,
//       height: 310,
//       thickness: 10,
//       filmsid: '钢化玻璃',
//       line: 1,
//       state: 2, // 未磨边
//       createTime: Date.now() - 3600 * 1000 * 2, // 2小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 2)
//     },
//     {
//       glassId: 'GL251209002',
//       width: 600,
//       height: 380,
//       thickness: 12,
//       filmsid: '浮法玻璃',
//       line: 2,
//       state: 1, // 磨边中
//       createTime: Date.now() - 3600 * 1000 * 1, // 1小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 1)
//     },
//     {
//       glassId: 'GL251209003',
//       width: 480,
//       height: 290,
//       thickness: 8,
//       filmsid: '夹胶玻璃',
//       line: 1,
//       state: 1, // 已磨边
//       createTime: Date.now() - 3600 * 1000 * 6, // 6小时前的时间戳
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 6)
//     },
//     {
//       glassId: 'GL251209004',
//       width: 550,
//       height: 330,
//       thickness: 9,
//       filmsid: '中空玻璃',
//       line: 2,
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 3,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 3)
//     },
//     {
//       glassId: 'GL251209005',
//       width: 580,
//       height: 350,
//       thickness: 11,
//       filmsid: '防弹玻璃',
//       line: '1',
//       state: 0,
//       createTime: Date.now() - 3600 * 1000 * 4,
//       formattedCreateTime: formatTimestamp(Date.now() - 3600 * 1000 * 4)
//     }
   
//   ];
//   return mockList;
// };
//   tableData.value = generateMockData();
//   ElMessage.success('模拟数据加载成功!');
// 历史任务
const iframeUrl = ref('');
const handlehistorical = (row) => {
  blindb.value = true;
  iframeUrl.value = `${window.location.origin}/#/StockBasicData/stockhistory`;
};
onMounted(() => {
  socket = initializeWebSocket(socketUrl, handleMessage);
});
  onUnmounted(() => {
    if (socket) {
      closeWebSocket(socket);
    }
  });
//   function getStatusTypeb(state) {
//   switch (state) {
//     case 0:
//       return 'info';
//     case 1:
//       return 'success';
//     case 1:
//       return 'danger';
//   }
// }
// 1. 辅助:获取行真实索引
function getRowRealIndex(row) {
  return tableData.value.findIndex(item => item.glassId === row.glassId);
}
 
// 2. 辅助:获取指定线路最新行状态
function getLineLatestState(line) {
  const targetLine = String(line || '').trim();
  if (!targetLine) return -1;
  for (const row of tableData.value) {
    const rowLine = String(row.line || '').trim();
    if (rowLine === targetLine) {
      return Number(row.state);
    }
  }
  return -1;
}
 
// 3. 核心判断:是否需要高亮/标红
function isNeedHighlight(row) {
  const currentState = Number(row.state);
  const currentLine = String(row.line || '').trim();
  if (!currentLine) return false;
 
  // 原有逻辑:未磨边 + 前序有磨边中/已磨边
  if (currentState === 0) {
    const currentIndex = getRowRealIndex(row);
    if (currentIndex === -1) return false;
    for (let i = 0; i < currentIndex; i++) {
      const compareRow = tableData.value[i];
      const compareLine = String(compareRow?.line || '').trim();
      const compareState = Number(compareRow?.state);
      if (compareLine === currentLine && [1, 2].includes(compareState)) {
        return true;
      }
    }
  }
 
  // 新增逻辑:磨边中 + 同线路最新是已磨边
  if (currentState === 1) {
    const latestState = getLineLatestState(currentLine);
    if (latestState === 2) {
      return true;
    }
  }
 
  return false;
}
 
// 4. 原始颜色映射
function getOriginalColor(state) {
  const stateNum = Number(state);
  switch (stateNum) {
    case 0: return 'info';
    case 1: return 'success';
    case 2: return 'primary';
    default: return 'info';
  }
}
 
// 5. 标签类型函数(调用isNeedHighlight)
function getStatusTypeb(row) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'danger';
  }
  return getOriginalColor(row.state);
}
 
// 6. 行样式函数(调用isNeedHighlight)
function getTableRowClass({ row }) {
  const currentState = Number(row.state);
  if ([0, 1].includes(currentState) && isNeedHighlight(row)) {
    return 'leak-edge-highlight';
  }
  return '';
}
 
function getStatusTextb(state) {
  switch (state) {
    case 0:
      return t('workOrder.nedging');
    case 1:
      return t('workOrder.edging');
    case 2:
      return t('workOrder.finedging');
  }
}
function formatTimestamp(timestamp) {
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要加1,并补零
  const day = String(date.getDate()).padStart(2, '0'); // 补零
  const hours = String(date.getHours()).padStart(2, '0'); // 补零(如果需要显示时间)
  const minutes = String(date.getMinutes()).padStart(2, '0'); // 补零(如果需要显示时间)
  const seconds = String(date.getSeconds()).padStart(2, '0'); // 补零(如果需要显示时间)
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
onBeforeUnmount(() => {
  closeWebSocket();
});
</script>
<template>
  <div style="height: 500px;">
    <div>
      <el-card style="flex: 1;margin-left: 10px;margin-top: 20px;" >
        <div style="display: flex;">
        <!-- <el-button style="margin-left: 20px;" id="searchButton" type="success" @click="handlehistorical">{{
          $t('searchOrder.historicaltasks')
        }}
      </el-button> -->
        <el-select v-model="selectValuesa[0]" filterable :placeholder="$t('workOrder.cway')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.edgingone')" value="930"></el-option>
          <el-option :label="$t('workOrder.edgingtwo')" value="931"></el-option>
        </el-select>
        <el-select v-model="selectValuesa[1]" filterable :placeholder="$t('workOrder.cstate')" clearable
                   style="margin-left: 20px;margin-bottom: 10px;">
          <el-option :label="$t('workOrder.nedging')" value="0"></el-option>
          <el-option :label="$t('workOrder.edging')" value="1"></el-option>
          <el-option :label="$t('workOrder.finedging')" value="2"></el-option>
          </el-select>
          <span class="demonstration" style="margin-left: 20px;margin-top: 3px;">{{ $t('workOrder.time') }}</span>
            <el-date-picker v-model="timeRange" type="datetimerange" range-separator="至" :start-placeholder="$t('reportmanage.starttime')"  style="margin-left: 15px;" value-format = "YYYY-MM-DD hh:mm:ss"
              :end-placeholder="$t('reportmanage.endtime')">
            </el-date-picker>
          <el-button type="primary" style="margin-left: 10px;margin-bottom: 10px;" @click="setEdgGlassInfoRequest()">{{
        $t('reportmanage.inquire')
      }}</el-button>
      </div>
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;">
        <el-table height="750" ref="table" 
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}"
        :row-class-name="getTableRowClass"
        >
        <el-table-column prop="glassId" align="center" :label="$t('workOrder.glassID')" min-width="180" />
          <el-table-column prop="width" align="center" :label="$t('workOrder.width')" min-width="120" />
          <el-table-column prop="height" align="center" :label="$t('workOrder.height')" min-width="80" />
          <el-table-column prop="thickness" align="center" :label="$t('workOrder.thickness')" min-width="120" />
          <el-table-column prop="filmsid" align="center" :label="$t('workOrder.glasstype')" min-width="120" />
          <el-table-column prop="line" align="center" :label="$t('workOrder.line')" min-width="120" />
          <el-table-column prop="formattedCreateTime" align="center" :label="$t('workOrder.time')" min-width="120" />
          <el-table-column prop="state" :label="$t('workOrder.status')" align="center" width="200">
            <!-- <template #default="scope">
              {{ scope.row.status==0?"未磨边":scope.row.status==1?"磨边中":"已磨边" }}
            </template> -->
            <template #default="scope"> 
          <el-tag :type="getStatusTypeb(scope.row || {}, scope.index)">  
          {{ getStatusTextb(scope.row.state) }}  
        </el-tag>   
        <!-- <el-tag :type="getStatusTypeb(scope.row.state)">  
          {{ getStatusTextb(scope.row.state) }}  
        </el-tag>   -->
      </template> 
        </el-table-column>
          <el-table-column fixed="right" :label="$t('workOrder.operate')" align="center" width="200">
            <template #default="scope">
              <el-button type="text" plain @click="open(scope.row)">{{
                  $t('workOrder.breakage')
                }}
              </el-button>
              <el-button type="text" plain @click="opena(scope.row)">{{
                  $t('workOrder.takeout')
                }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      </el-card>
    </div>
  <!-- 历史任务 -->
<el-dialog v-model="blindb" top="10vh" width="95%" @close="iframeUrl=''">
     <iframe 
     :src="iframeUrl" 
     marginwidth="2000px"
     marginheight="2000px"
     width="100%" 
     height="700px" 
     frameborder="0"
     ></iframe>
  </el-dialog>
  </div>
</template>
<style scoped>
#dt { display:block; float:left;line-height: 20px;margin-left: 100px;}
#dta { display:block; float:left;line-height: 20px;margin-left: 80%;}
#dialog-footer{
  text-align: center;
  margin-top: -15px;
}
#message{
  text-align: center;
  align-items: center;
  color: black;
   width: 200px;
   height: 100px;
   background-color: #337ecc;
   margin-left: 28%;
}
#awatch{
  height: 460px;
  /* margin-top: -60px; */
}
/* 漏磨边行整行高亮样式(穿透scoped) */
:deep(.leak-edge-highlight) {
  background-color: #fff1f0 !important; /* 浅红背景(和danger标签呼应) */
}
/* 行内单元格文字标红 */
:deep(.leak-edge-highlight > td) {
  color: #f5222d !important; /* 红色文字 */
  font-weight: 500 !important; /* 可选:文字加粗,更醒目 */
}
/* 鼠标悬浮时保持高亮(可选) */
:deep(.el-table__row.leak-edge-highlight:hover > td) {
  background-color: #fee2e2 !important;
}
</style>