zhoushihao
2025-09-05 dd4778d2cc47467a39473f02513ec5438b5c9512
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
<template>
  <div style="height: 500px;">
    <el-card style="flex: 1;margin-left: 10px;margin-top: 10px;margin-right: 10px;height: 800px;">
     <div style="display: flex;margin-left: 40%;margin-bottom: 5px;">
    <div style="text-align: center;"> {{ $t('processCard.temperinglayout') }}:{{ ava }}-{{ avanum }} </div>
     <el-button @click="handleAllDamage" style="margin-left: 80%;margin-top: -5px;">{{$t('order.dilapidation')}}</el-button>
    </div>
    <el-scrollbar height="750px" width="1400px" style="background-color: #e9e9eb;">
        <div style="position: relative;">
          <div
              v-for="(rect, index) in adjustedRects"
              :key="rect.glassId"
              class="rect"
              @click="showDialog(rect.glassId)"
              :style="{ position: 'absolute',
              top: `${rect.yAxisa}px`, left: `${rect.xAxisa}px`, width: `${rect.width}px`, height: `${rect.height}px`,
              backgroundColor: rect.isActive ? '#ADFF2F' : getRectColor(rect.state)
               }">
            <div class="centered-text">
              <div style="font-size: 10px;font-weight: bold;">{{ rect.glassId }}</div>
              <div style="font-size: 10px;font-weight: bold;">{{ rect.flowCardId }}</div>
              <div style="font-size: 15px;font-weight: bold;">{{ rect.widtha }}*{{ rect.heighta }}</div>
            </div>
          </div>
        </div>
      </el-scrollbar>
      <el-dialog v-model="blind" top="30vh" width="15%" style="text-align: center;" @close="handleDialogClose">
        <el-button :disabled="currentGlassRect?.state === 8 || currentGlassRect?.state === 9" type="warning"
                   plain :icon="Delete" @click="handleDamage(currentGlassId)" style="width: 140px;margin-left: 10px;">
          {{ $t('order.dilapidation') }}
        </el-button>
        <el-button :disabled="currentGlassRect?.state === 9 || currentGlassRect?.state === 8" type="danger"
                   plain @click="handleManualTake(currentGlassId)" style="width: 140px;margin-top: 10px;">
          <el-icon class="el-icon--right">
            <Upload/>
          </el-icon>
          {{ $t('order.takeaway') }}
        </el-button>
      </el-dialog>
    </el-card>
  </div>
</template>
<script setup lang="ts">
import {avatarEmits,  ElMessage, ElMessageBox } from 'element-plus'
import {onBeforeUnmount, computed, onMounted, onUnmounted, ref} from 'vue';
import request from "@/utils/request"
import {host, WebSocketHost} from '@/utils/constants'
import {closeWebSocket, initializeWebSocket} from '@/utils/WebSocketService';
import {useI18n} from 'vue-i18n'
const {t} = useI18n()
let language = ref(localStorage.getItem('lang') || 'zh')
const blind = ref(false)
const currentGlassId = ref(null);
const adjustedRects = ref([]);
const ava = ref('');
const avanum = ref('');
const realwidth = ref('');
const realheight = ref('');
let socket = null;
const socketUrl = `ws://${WebSocketHost}:${host}/api/cacheGlass/api/talk/currentCutDrawingTwo`;
const handleMessage = (data: any) => {
  if (data.engineer != null) {
  ava.value = data.engineer[0]
  }else{
    ava.value = ''
  }
  if (data.engineer != null) {
    avanum.value = data.sequence[0]
  }else{
    avanum.value = ''
  }
      if (data.upPattenUsage && data.upPattenUsage.length > 0) {
        realwidth.value = data.upPattenUsage[0].width;
        realheight.value = data.upPattenUsage[0].height;
        const realx = realwidth.value;
        const realy = realheight.value;
        const scaleFactora = 1621.78 / realx;
        const scaleFactorya = 750 / realy;
      window.localStorage.setItem('widthreturna', realy)
      window.localStorage.setItem('scaleFactorb', scaleFactora)
      window.localStorage.setItem('scaleFactoryb', scaleFactorya)
      }
      if (data.currentCutTerritory && data.currentCutTerritory.length > 0) {
        let scaleFactor = window.localStorage.getItem('scaleFactorb')
        let scaleFactory = window.localStorage.getItem('scaleFactoryb')
        let widthreturn = window.localStorage.getItem('widthreturna')
        const newRects = data.currentCutTerritory[0].map(rect => {
          const existingRect = adjustedRects.value.find(r => r.glassId === rect.glassId);
          if (existingRect) {
            return {
              ...existingRect,
               xAxisa: rect.xAxis * scaleFactor,
               yAxisa: (widthreturn - (rect.yAxis + rect.edgHeight )) * scaleFactory,
              width: rect.edgWidth * scaleFactor,
              height: rect.edgHeight * scaleFactory,
              widtha: rect.edgWidth,
              heighta: rect.edgHeight,
              state: rect.state,
            };
          } else {
            // 如果不存在,则添加新矩形,默认 isActive 为 false
            return {
              ...rect,
              xAxisa: rect.xAxis * scaleFactor,
              yAxisa: (widthreturn - (rect.yAxis + rect.edgHeight)) * scaleFactory,
              width: rect.edgWidth * scaleFactor,
              height: rect.edgHeight * scaleFactory,
              widtha: rect.edgWidth,
              heighta: rect.edgHeight,
              state: rect.state,
              isActive: false,
              glassId: rect.glassId,
            };
          }
        });
        adjustedRects.value = newRects;
      } else if (data.currentCutTerritory == '') {
        adjustedRects.value = [];
      }
}
const currentGlassRect = computed(() => {
  return adjustedRects.value.find(rect => rect.glassId === currentGlassId.value);
});
function showDialog(glassId: number) {
  currentGlassId.value = glassId;
  blind.value = true;
  adjustedRects.value = adjustedRects.value.map(rect =>
      rect.glassId === glassId ? {...rect, isActive: true} : rect
  );
}
const handleDialogClose = () => {
  adjustedRects.value = adjustedRects.value.map(rect => ({
    ...rect,
    isActive: false
  }));
}
// 一键破损所有玻璃
const handleAllDamage = async () => {
  try {
      const confirmResult = await ElMessageBox.confirm(
      t('order.dilapidationWhether'),
      t('workOrder.prompt'),
      {
        confirmButtonText: t('workOrder.yes'),
        cancelButtonText: t('workOrder.cancel'),
        type: 'warning',
      }
    );
    // 筛选出state不是8和9的玻璃ID
    const glassIdList = adjustedRects.value
      .filter(rect => rect.state !== 8 && rect.state !== 9)
      .map(rect => rect.glassId);
    if (glassIdList.length === 0) {
      ElMessage.warning(t('order.noGlassToDamage')); // 没有可破损的玻璃
      return;
    }
    const response = await request.post('/cacheGlass/taskCache/identControlsByPatternSequence', {
      glassIdList: glassIdList,
      state: 8,
      line: 2,
      workingProcedure: '切割',
      remark: '掰片'
    });
    if (response.code === 200) {
      ElMessage.success(response.message);
      // 更新所有玻璃状态
      glassIdList.forEach(glassId => {
        updateRectStatus(glassId, 8);
      });
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
    ElMessage.error(t(''));
  }
};
// 破损
const handleDamage = async () => {
  try {
    const response = await request.post('/cacheGlass/taskCache/identControls', {
      glassId: currentGlassId.value,
      state: 8,
      line: 2,
      remark: '掰片',
      workingProcedure: '切割',
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blind.value = false;
      updateRectStatus(currentGlassId.value, 8);
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
}
// 人工拿走
const handleManualTake = async () => {
  try {
    const response = await request.post('/cacheGlass/taskCache/identControls', {
      glassId: currentGlassId.value,
      state: 9,
      line: 2,
      workingProcedure: '切割',
      remark: '掰片',
    })
    if (response.code == 200) {
      ElMessage.success(response.message);
      blind.value = false;
      updateRectStatus(currentGlassId.value, 9);
    } else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
}
function getRectColor(state: number): string {
  switch (state) {
    case 0:  
      return '#7AC5CD';//未进笼
    case 1:
      return '#95d475';
    case -1:
      return '#99BBFF';
    case 2:  
      return 'lightblue';
    case 3:  
      return '#eebe77';  
    case 4:  
      return '#CD6090';
    case 8:
      return '#911005';//破损
    case 9:
      return '#4682B4';//拿走
    default:
      return '#CDAF95'; 
  }
}
// 更新矩形状态
function updateRectStatus(glassId: string, status: number) {
  adjustedRects.value.forEach(rect => {
    if (rect.glassId === glassId) {
      rect.state = status; // 更新矩形的状态  
    }
  });
}
onMounted(() => {
  socket = initializeWebSocket(socketUrl, handleMessage);
});
onBeforeUnmount(() => {
  closeWebSocket();
});
</script>
<style scoped>
.rect {
  border: 1px solid black; /* 设置矩形的边框 */
  /* background-color: lightblue; 设置矩形的背景色   */
}
.centered-text {
  /* 设置文字居中样式 */
  /* display: flex; */
  justify-content: center;
  align-items: center;
  height: 100%; /* 确保div占据整个矩形的高度 */
  /* font-size: large; */
}
#line {
  position: absolute;
  top: 70%; /* 直线位于矩形中间 */
  left: 210px; /* 直线在箭头右侧一些距离 */
  transform: translateY(-50%); /* 垂直居中 */
  height: 2px; /* 直线的高度 */
  width: 240px; /* 直线的长度,根据需要调整 */
  background-color: #911005; /* 直线的颜色 */
}
</style>