wuyouming666
2024-05-24 03f241781205b4aaafa6cee66e7402a41ef97fc1
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
<script setup>
import {Search} from "@element-plus/icons-vue";
import {reactive, onMounted, onBeforeUnmount} from "vue";
 
import {useRouter} from "vue-router"
const router = useRouter()
 
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import Landingindication from "./Landingindication.vue";
import Landingindicationtwo from "./Landingindicationtwo.vue";
import request from "@/utils/request";
import { initializeWebSocket, closeWebSocket } from '@/utils/WebSocketService';
 import { WebSocketHost } from '@/utils/constants';
 
 
const dialogFormVisiblea = ref(false)
 
const dialogFormVisiblea2 = ref(false)
 
// 数据
const loading = ref(false);
 
// 弹框显示控制
const dialogFormVisible = ref(false);
// 表单数据
const workstationId = ref('');
const flowCardId = ref('');
const flowCardOptions = ref([]);
const tableData = reactive([]);
// 方法
const handleSelectionChange = () => {
  // 处理表格行选择事件
};
 
const handleBindRack = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  // 发起接口请求获取流程卡号
    fetchFlowCardId(); 
  dialogFormVisiblea.value = true; // 打开绑定架子对话框
};
 
//获取流程卡号
const fetchFlowCardId = async () => {
  try {
    const response = await request.get('unLoadGlass/downWorkStation/getflowCardId');
    console.log(response)
    if (response.code === 200) {
  flowCardOptions.value = response.data
    .filter(item => item !== null)
    .map(item => ({ flowcard_id: item.flow_card_Id }));
  console.log(flowCardOptions.value);
}
 else {
      ElMessage.error(response.msg);
    }
  } catch (error) {
    console.error(error);
  }
};
//确认
const handleConfirm = async () => {
  try {
    const response = await request.post('unLoadGlass/downWorkStation/updateFlowCardId', {
      workstationId: workstationId.value,
      flowCardId: flowCardId.value
    }); 
 
    console.log(response)
    if (response.code == 200) {
      // 绑定成功,处理逻辑
      console.log('绑定成功');
   
      ElMessage.success(response.message);
      updatePageData();
      dialogFormVisiblea.value = false;
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理错误
    console.error(error);
  }
};
 
 
const updatePageData = () => {
  // 假设你的页面上有一个名为 tableData 的 Vue 组件
  // 你可以直接更新 tableData 的数据
  fetchTableData()
  // 使用 $forceUpdate() 强制更新组件
 
};
 
const handleBindRack2 = (row) => {
  workstationId.value = row.workstationId; // 假设rackNumber是架号字段的属性名
  dialogFormVisiblea2.value = true; // 打开绑定架子对话框
};
//清除内容
const handleclear = async () => {
    try {
        const response = await request.post('unLoadGlass/downWorkStation/clear', {
            workstationId: workstationId.value,
        });
 
        console.log(response);
 
        if (response.code === 200) {
            // 清除成功的逻辑
            console.log('清除成功');
            ElMessage.success(response.message);
            dialogFormVisiblea2.value = false;
        } else if (response.code === 400) {
            // 清除失败的逻辑
            console.log('清除失败');
            console.log(response.message); // 打印服务器返回的错误信息
            ElMessage.error(response.message);
            dialogFormVisiblea2.value = false;
        }
    } catch (error) {
        // console.log(error);
         ElMessage.error("清除失败");
            dialogFormVisiblea2.value = false;
    }
};
 
 
// 发送获取表格数据的请求
const fetchTableData = async () => {
  try {
    // 发送获取表格数据的请求,并等待响应
    const response = await request.get('unLoadGlass/downWorkStation/getone');
 
    // 检查响应状态
    if (response.code === 200) {
      // 更新表格数据
      console.log('成功获取表格数据:', response.data);
      tableData.splice(0, tableData.length, ...response.data);
    } else {
      // 请求失败,显示错误消息
      ElMessage.error(response.msg);
    }
  } catch (error) {
    // 处理请求失败的情况
    ElMessage.error('获取表格数据失败,请重试');
  }
};
 
 
const socketUrl = `ws://${WebSocketHost}:8085/api/talk/unloadglass`;
// 定义消息处理函数,更新 receivedData 变量
const handleMessage = (data) => {
 
  // 更新 tableData 的数据
 
  tableData.splice(0, tableData.length, ...data.params[0]);
 // console.log("更新后数据", tableData);
 
};
 
// 初始化 WebSocket,并传递消息处理函数
 
onMounted(() => {
  fetchFlowCardId();
  fetchTableData(); // 获取数据
  initializeWebSocket(socketUrl, handleMessage);
});
 
onBeforeUnmount(() => {
  console.log("关闭了")
  closeWebSocket();
});
 
// beforeUnmount(() => {
//   closeWebSocket();
// });
 
 
// setInterval(fetchTableData, 2000)
 
 
</script>
 
<template>
  <div>
    <el-card style="flex: 1;margin-left: 10px;margin-top: 5px;" v-loading="loading">
      <div style="width: 98%; height: calc(100% - 35px); overflow-y: auto;max-height: 200px;">
        <el-table height="100%" ref="table" 
        @selection-change="handleSelectionChange"
        :data="tableData" :header-cell-style="{background:'#F2F3F5 ',color:'#1D2129'}">
          <el-table-column prop="workstationId" align="center" label="下片位" min-width="80" />
          <el-table-column prop="workstationId" align="center" label="架号" min-width="120" />
          <el-table-column prop="flowCardId" align="center" label="流程卡号" min-width="120" />
          <el-table-column prop="totalquantity" align="center" label="总数量" min-width="120" />
          <el-table-column prop="racksnumber" align="center" label="已落架数量" min-width="120" />
          <el-table-column prop="work_state" align="center" label="状态" min-width="120" />
          <el-table-column prop="deviceId" align="center" label="设备号" min-width="120" />
         
 
 
          <el-table-column
            align="center"
            label="启用状态"
            min-width="80"
            prop="enableState"
          >
          <template #default="scope">
            <el-tag type="success" >{{ scope.row.enableState==1?"启用":"未启用"  }}</el-tag>
          </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="center" width="200">
            <template #default="scope">
            <el-button size="mini" type="text" plain v-show="scope.row.enableState !== '已启用' " @click="handleBindRack(scope.row)">绑定架子</el-button>
            <el-button size="mini" type="text" plain  @click="handleBindRack2(scope.row)">清空</el-button>
          </template>
        </el-table-column>
        </el-table>
      </div>
    </el-card>
 
 
    <el-dialog v-model="dialogFormVisiblea" top="21vh" width="30%" title="绑定架子" >
    <div style="margin-left: 50px;margin-top: 10px;margin-bottom: 10px;">
      <el-form  size="mini" label-width="150px">
        <el-form  label-width="100px" label-position="right">
          <el-form-item label="架号:" :required="true" style="width: 18vw">
            <el-input v-model="workstationId" autocomplete="off"/>
          </el-form-item>
          <el-form-item label="流程卡号:" :required="true" style="width: 18vw;">
          <el-select v-model="flowCardId" placeholder="请选择流程卡号">
            <el-option v-for="item in flowCardOptions" :key="item.flowcard_id" :label="item.flowcard_id" :value="item.flowcard_id" />
          </el-select>
        </el-form-item>
      </el-form>
      </el-form>
    </div>
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
        <el-button @click="dialogFormVisiblea = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
 
 
 
 
  <el-dialog v-model="dialogFormVisiblea2" top="21vh" width="30%" title="清除架子玻璃" >
 
    <template #footer>
      <div id="dialog-footer">
        <el-button type="primary" @click="handleclear">
          确认
        </el-button>
        <el-button @click="dialogFormVisiblea2 = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
 
 
    <!-- workstationId: '1',
    workstationId: '1005',
    flowCardId: '183.6',
    totalquantity: '1991',
    racksnumber:"1",
    work_state: '待识别', -->
  </div>
  <div style="display: flex;">
  <div id="main-body">
      <Landingindication></Landingindication>
    </div>
  <div id="main-bodya">
    <Landingindicationtwo></Landingindicationtwo>
    </div></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: 450px;
}
#main-body{
  margin-top: -20px;
  margin-left: 200px;
}
#main-bodya{
  margin-top: -10px;
  margin-left: 100px;
}
</style>