| | |
| | | import {onMounted, ref} from 'vue'; |
| | | import {ElMessage, ElLoading} from "element-plus"; |
| | | import request from "@/utils/request"; |
| | | import requestTemp from "@/utils/requestTemp"; |
| | | |
| | | const props = defineProps({ |
| | | project : null |
| | | }); |
| | | |
| | | const state = ref() |
| | | const computed = ref(null); |
| | | const computedCard = ref(null); |
| | | const computedData = ref({ |
| | |
| | | // 监听子组件ComputeCard的数据 |
| | | |
| | | |
| | | |
| | | const computeCardRef=ref(null) |
| | | |
| | | |
| | | const handleCardData = (data) => { |
| | |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | if (props.project.projectNumber) { |
| | | if (props.project) { |
| | | console.log('ceshiyixia',props.project) |
| | | handleFetchData(props.project.projectNumber); |
| | | //handleTableData(data); |
| | | //handleDataReceive(data); |
| | |
| | | |
| | | // 用于存储从后端获取到的数据,初始化为空数组 |
| | | const receivedData = ref([]); |
| | | const emit = defineEmits(['update:project']); |
| | | const fetchProjectInfo = async (projectNumber) => { |
| | | try { |
| | | const res = await request.post(`/glassOptimize/getProjectByProjectNo/${projectNumber}`); |
| | | console.log('完整响应数据:', res); // 用于调试查看完整响应结构 |
| | | |
| | | if (Number(res.code) === 200 && res.data && res.data.data && res.data.data.length > 0) { |
| | | // 正确访问嵌套的数据结构 |
| | | const projectData = res.data.data[0]; // 注意这里是 res.data.data[0] |
| | | const updatedProject = { |
| | | ...props.project, |
| | | glass_thickness: projectData.glass_thickness || '', |
| | | glass_type: projectData.glass_type || '' |
| | | }; |
| | | console.log('获取到的glass_thickness:', projectData.glass_thickness); |
| | | console.log('获取到的glass_type:', projectData.glass_type); |
| | | // // 通过 emit 更新 project |
| | | emit('update:project', updatedProject); |
| | | // 更新 computed.value |
| | | computed.value = { |
| | | ...computed.value, |
| | | glass_thickness: projectData.glass_thickness, |
| | | glass_type: projectData.glass_type |
| | | }; |
| | | // 确保computed.value已初始化 |
| | | if (!computed.value) { |
| | | computed.value = {}; |
| | | } |
| | | |
| | | computed.value.glass_thickness = projectData.glass_thickness; |
| | | computed.value.glass_type = projectData.glass_type; |
| | | |
| | | console.log('设置后的computed.value:', computed.value); |
| | | } else { |
| | | console.warn('未找到项目信息或数据格式不正确'); |
| | | } |
| | | } catch (error) { |
| | | console.error('获取项目信息失败', error); |
| | | ElMessage.error('获取项目信息失败'); |
| | | } |
| | | }; |
| | | |
| | | |
| | | console.log(receivedData) |
| | | const handleFetchData = async (projectNumber) => { |
| | | try { |
| | | const res = await request.post(`/glassOptimize/selectProjectCompute/${projectNumber}`); |
| | | if (Number(res.code) === 200 && res.data && res.data.data) { |
| | | receivedData.value = res.data.data; |
| | | // 获取项目信息 |
| | | await fetchProjectInfo(projectNumber); |
| | | } else { |
| | | console.error('请求出现问题,状态码:', res.code, ',错误信息:', res.msg); |
| | | if (res.code === 404) { |
| | |
| | | console.log('父组件接收到的数据1:', data); |
| | | } |
| | | |
| | | const handleSimulation = async () => { |
| | | const loading = ElLoading.service({ |
| | | lock: true, |
| | | text: '正在计算中,请稍候...', |
| | | background: 'rgba(0, 0, 0, 0.7)' |
| | | }); |
| | | console.log('发送到后端的数据',computedCard.value) |
| | | const mockData = { |
| | | code: 200, |
| | | data: [ |
| | | { |
| | | "glass_details": [ |
| | | { |
| | | "angle": 0.0, |
| | | "glass_type": 3, |
| | | "height": 862, |
| | | "layers_number": 2, |
| | | "order_number": 33, |
| | | "process_id": "NG24120028A005", |
| | | "technology_number": 2, |
| | | "tempering_feed_sequence": 14, |
| | | "tempering_layout_id": 15, |
| | | "width": 814, |
| | | "x_coordinate": 1582.0, |
| | | "y_coordinate": 3768.0 |
| | | }, |
| | | { |
| | | "angle": 0.1, |
| | | "glass_type": 4, |
| | | "height": 862, |
| | | "layers_number": 2, |
| | | "order_number": 33, |
| | | "process_id": "NG24120028A005", |
| | | "technology_number": 2, |
| | | "tempering_feed_sequence": 14, |
| | | "tempering_layout_id": 15, |
| | | "width": 814, |
| | | "x_coordinate": 1582.0, |
| | | "y_coordinate": 3768.0 |
| | | } |
| | | ], |
| | | "guidance": 15, |
| | | "rackinfos": [ |
| | | "NG24120026A003-2", |
| | | "NG24120027A003-2", |
| | | "NG24120028A005-2" |
| | | ], |
| | | "ratioResult": [ |
| | | { |
| | | "area": 10.53, |
| | | "glass_total": 15, |
| | | "ratio": 0.74, |
| | | "tempering_layout_id": "13" |
| | | }, |
| | | { |
| | | "area": 10.53, |
| | | "glass_total": 15, |
| | | "ratio": 0.74, |
| | | "tempering_layout_id": "14" |
| | | }, |
| | | { |
| | | "area": 9.82, |
| | | "glass_total": 14, |
| | | "ratio": 0.69, |
| | | "tempering_layout_id": "15" |
| | | } |
| | | ], |
| | | "resultSum": [15.0, 0.74] |
| | | // 发送数据到钢化计算接口 |
| | | const sendToComputeTempering = async () => { |
| | | let loading=ElLoading.service({ |
| | | lock: true, |
| | | text: '正在计算中,请稍候...', |
| | | background: 'rgba(0, 0, 0, 0.7)' |
| | | }); |
| | | try { |
| | | console.log('发送到后端的数据', JSON.stringify(computedCard.value, null, 2)); |
| | | |
| | | // 发送数据到钢化计算接口 |
| | | const response = await requestTemp.post('/computeTempering/inputTemperingData', computedCard.value); |
| | | |
| | | console.log('后端原始响应:', response); |
| | | |
| | | // 检查响应结构并正确处理 |
| | | if (response && (response.code === 200 || response.status === 200)) { |
| | | ElMessage.success('模拟计算成功!'); |
| | | |
| | | // 处理返回的数据 |
| | | let resultData = response.data; |
| | | |
| | | // 如果data是字符串,需要解析JSON |
| | | if (typeof resultData === 'string') { |
| | | try { |
| | | resultData = JSON.parse(resultData); |
| | | } catch (parseError) { |
| | | console.error('解析返回数据失败:', parseError); |
| | | ElMessage.warning('返回数据格式异常,使用原始数据'); |
| | | // 即使解析失败也继续使用原始数据 |
| | | } |
| | | ] |
| | | }; |
| | | if (mockData.code === 200) { |
| | | loading.close(); |
| | | ElMessage.success('模拟计算成功!'); |
| | | } |
| | | |
| | | // 更新computedData以显示返回的结果 |
| | | computedData.value = { |
| | | code: 200, |
| | | data: resultData |
| | | }; |
| | | |
| | | console.log('接收到的处理后数据:', computedData.value); |
| | | } else { |
| | | // 处理错误情况 |
| | | const errorMessage = response?.msg || response?.message || '模拟计算失败'; |
| | | ElMessage.error(errorMessage); |
| | | } |
| | | // 更新computedData |
| | | computedData.value = mockData; |
| | | // try { |
| | | // if (!computed.value ) { |
| | | // ElMessage.warning('请先加载数据再进行模拟计算'); |
| | | // return; |
| | | // } |
| | | } catch (error) { |
| | | console.error('请求失败:', error); |
| | | // 确保关闭加载提示 |
| | | if (loading) { |
| | | loading.close(); |
| | | } |
| | | }finally { |
| | | loading.close(); |
| | | } |
| | | }; |
| | | |
| | | // // 显示加载提示 |
| | | // const loading = ElLoading.service({ |
| | | // lock: true, |
| | | // text: '正在计算中,请稍候...', |
| | | // background: 'rgba(0, 0, 0, 0.7)' |
| | | // }); |
| | | const handleSimulation = async () => { |
| | | let arry = computeCardRef.value.selectFullData(); |
| | | let data = arry; |
| | | data = data.reduce((acc, item) => { |
| | | if (item.tempering) { |
| | | acc.push(item); |
| | | } |
| | | return acc; |
| | | }, []); |
| | | |
| | | // try { |
| | | // // 将数据提交到后端 |
| | | // const response = await request.post('/glassOptimize/simulationCalculate', { |
| | | |
| | | // data: computedCard.value |
| | | if (data.length === arry.length) { |
| | | state.value = 1 |
| | | } else { |
| | | state.value = 2 |
| | | } |
| | | // 计算钢化流程卡的数量总和 |
| | | let maxQty = 0; |
| | | if (data.length > 0) { |
| | | // 遍历所有勾选了钢化的流程卡,累加它们的数量 |
| | | arry.forEach(item => { |
| | | if (item.tempering) { |
| | | maxQty += item.total_num || 0; |
| | | } |
| | | }); |
| | | |
| | | // }); |
| | | // 将计算出的钢化数量总和添加到 computed.value 中 |
| | | computed.value.max_qty = maxQty; |
| | | |
| | | // if (response.code === 200) { |
| | | // ElMessage.success('模拟计算成功!'); |
| | | // } else { |
| | | // ElMessage.error(response.msg || '模拟计算失败'); |
| | | // } |
| | | // } catch (error) { |
| | | // console.error('请求失败:', error); |
| | | // ElMessage.error('网络异常,请稍后再试'); |
| | | // } finally { |
| | | // // 关闭加载提示 |
| | | // loading.close(); |
| | | // } |
| | | // } catch (error) { |
| | | // console.error('请求失败:', error); |
| | | // ElMessage.error('网络异常,请稍后再试'); |
| | | // } |
| | | if (data.length > 0) { |
| | | // 创建所有异步请求的Promise数组 |
| | | const detailPromises = []; |
| | | data.forEach(item => { |
| | | const processCard = { |
| | | process_no: item.processId, |
| | | layers: item.technologyNumber, |
| | | total_layers: item.total_layers, |
| | | total_num: item.total_num, |
| | | total_area: item.total_area, |
| | | is_must: true, |
| | | allow_rotate: item.allow_rotate, |
| | | priority_level: 0, |
| | | tempering: item.tempering, |
| | | curtain_wall: item.curtain_wall, |
| | | patch_state: item.patch_state, |
| | | merge: item.merge, |
| | | glass_details: [] |
| | | }; |
| | | |
| | | // 创建异步请求Promise并保存 |
| | | const detailPromise = request.post(`/glassOptimize/selectComputeDetail/${item.processId}/${item.technologyNumber}/${item.patch_state}`).then((res) => { |
| | | if (Number(res.code) === 200) { |
| | | res.data.data.forEach(items => { |
| | | const detail = { |
| | | process_id: items.process_id, |
| | | technology_number: items.technology_number, |
| | | order_number: items.order_number, |
| | | layers_number: item.total_layers, |
| | | max_width: items.maxwidth, |
| | | max_height: items.maxheight, |
| | | child_width: items.width, |
| | | child_height: items.height, |
| | | quantity: items.quantity, |
| | | patch_state: item.patch_state |
| | | } |
| | | processCard.glass_details.push(detail) |
| | | }) |
| | | return processCard; |
| | | } else { |
| | | ElMessage.warning(res.msg) |
| | | return processCard; |
| | | } |
| | | }).catch(error => { |
| | | console.error('获取详情失败:', error); |
| | | return processCard; |
| | | }); |
| | | |
| | | detailPromises.push(detailPromise); |
| | | }); |
| | | |
| | | // 等待所有异步请求完成 |
| | | try { |
| | | const completedProcessCards = await Promise.all(detailPromises); |
| | | |
| | | // 将完成的流程卡添加到computed.value中 |
| | | if (!computed.value.process_cards) { |
| | | computed.value.process_cards = []; |
| | | } |
| | | computed.value.process_cards = completedProcessCards; |
| | | |
| | | console.log('完整的computed.value数据:', computed.value); |
| | | } catch (error) { |
| | | console.error('处理流程卡详情时出错:', error); |
| | | ElMessage.error('获取流程卡详情失败'); |
| | | } |
| | | } else { |
| | | ElMessage.warning("没有需要钢化工艺的数据请直接保存") |
| | | state.value = 3 |
| | | // 即使没有钢化数据,也要设置 max_qty 为 0 |
| | | computed.value.max_qty = 0; |
| | | return |
| | | } |
| | | |
| | | // 合并数据 |
| | | computedCard.value = { |
| | | ...computed.value, |
| | | ...computedCard.value |
| | | }; |
| | | |
| | | // console.log('最终发送到后端的数据:', computedCard.value); |
| | | |
| | | await sendToComputeTempering(); |
| | | }; |
| | | }; |
| | | |
| | | |
| | |
| | | //接受子组件ComputeCard的流程卡号 |
| | | let projectRow = ref({ |
| | | processId:null, |
| | | patchState:null, |
| | | technologyNumber:null |
| | | }) |
| | | const handleUpdateProcessId = newProcessId => { |
| | | projectRow.value.processId = newProcessId; |
| | | console.log('接收到子组件获取的流程卡号为',projectRow.value.processId) |
| | | const handleUpdateProcessId = (processId,patchState,technologyNumber) => { |
| | | projectRow.value.processId = processId; |
| | | projectRow.value.patchState = patchState; |
| | | }; |
| | | |
| | | const handleTechnologyNumberUpdate = (processId,patchState,technologyNumber) => { |
| | | projectRow.value.technologyNumber = technologyNumber; |
| | | projectRow.value.patchState = patchState; |
| | | }; |
| | | |
| | | |
| | | |
| | | </script> |
| | | |
| | |
| | | <div style="width: 100%; height: 100%;"> |
| | | |
| | | <div id="compute"> |
| | | <compute :data="computedData" @fetch-data="handleFetchData" :project="props.project" @sendData="handleData" @simulate-click="handleSimulation" /> |
| | | <compute :data="computedData" :state="state" |
| | | @fetch-data="handleFetchData" |
| | | :project="props.project" |
| | | @sendData="handleData" |
| | | @simulate-click="handleSimulation" /> |
| | | </div> |
| | | |
| | | <div id="computeCard"> |
| | | <compute-card :table-data="receivedData" |
| | | <compute-card ref="computeCardRef" :table-data="receivedData" |
| | | :process-id="projectRow.processId===null?null:projectRow.processId" |
| | | @upProcessId="handleUpdateProcessId" @sendData="handleCardData" |
| | | :technology-number="projectRow.technologyNumber===null?null:projectRow.technologyNumber" |
| | | @upProcessId="handleUpdateProcessId" @updateTechnologyNumber="handleTechnologyNumberUpdate" @sendData="handleCardData" |
| | | /> |
| | | </div> |
| | | |
| | | <div id="computeDetail"> |
| | | <compute-detail :process-id="projectRow.processId===null?null:projectRow.processId" /> |
| | | <compute-detail :process-id="projectRow.processId===null?null:projectRow.processId" |
| | | :technology-number="projectRow.technologyNumber===null?null:projectRow.technologyNumber" |
| | | :patch-state="projectRow.patchState===null?null:projectRow.patchState"/> |
| | | </div> |
| | | |
| | | </div> |