| | |
| | | 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 receivedData = ref([]); |
| | | |
| | | 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] |
| | | |
| | | console.log('获取到的glass_thickness:', projectData.glass_thickness); |
| | | console.log('获取到的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) => { |
| | |
| | | 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 sendToComputeTempering = async () => { |
| | | let loading; |
| | | try { |
| | | // 显示加载提示 |
| | | loading = ElLoading.service({ |
| | | lock: true, |
| | | text: '正在计算中,请稍候...', |
| | | background: 'rgba(0, 0, 0, 0.7)' |
| | | }); |
| | | |
| | | 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('返回数据格式异常,使用原始数据'); |
| | | // 即使解析失败也继续使用原始数据 |
| | | } |
| | | } |
| | | |
| | | // 更新computedData以显示返回的结果 |
| | | computedData.value = { |
| | | code: 200, |
| | | data: resultData |
| | | }; |
| | | |
| | | console.log('接收到的处理后数据:', computedData.value); |
| | | } else { |
| | | // 处理错误情况 |
| | | const errorMessage = response?.msg || response?.message || '模拟计算失败'; |
| | | ElMessage.error(errorMessage); |
| | | } |
| | | } catch (error) { |
| | | console.error('请求失败:', error); |
| | | |
| | | // 确保关闭加载提示 |
| | | if (loading) { |
| | | loading.close(); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | const handleSimulation = async () => { |
| | | let arry = computeCardRef.value.selectFullData(); |
| | | let data = arry; |
| | |
| | | return acc; |
| | | }, []); |
| | | |
| | | if(data.length===arry.length){ |
| | | state.value=1 |
| | | }else{ |
| | | state.value=2 |
| | | 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; |
| | | } |
| | | }); |
| | | |
| | | if(props.project!=null){ |
| | | computed.value.glass_thickness=props.project.glass_thickness |
| | | computed.value.glass_type=props.project.glass_type |
| | | } |
| | | if(data.length>0){ |
| | | 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: [] |
| | | }; |
| | | // 将计算出的钢化数量总和添加到 computed.value 中 |
| | | computed.value.max_qty = maxQty; |
| | | |
| | | 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:null, |
| | | technology_number:null, |
| | | order_number:null, |
| | | layers_number:null, |
| | | max_width:null, |
| | | max_height:null, |
| | | child_width:null, |
| | | child_height:null, |
| | | quantity:null, |
| | | patch_state:null |
| | | } |
| | | detail.process_id=items.process_id |
| | | detail.technology_number=items.technology_number |
| | | detail.order_number=items.order_number |
| | | detail.layers_number=item.total_layers |
| | | detail.max_width=items.maxwidth |
| | | detail.max_height=items.maxheight |
| | | detail.child_width=items.width |
| | | detail.child_height=items.height |
| | | detail.quantity=items.quantity |
| | | detail.patch_state=item.patch_state |
| | | 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: [] |
| | | }; |
| | | |
| | | processCard.glass_details.push(detail) |
| | | }) |
| | | // 创建异步请求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); |
| | | }); |
| | | |
| | | }else{ |
| | | ElMessage.warning(res.msg) |
| | | // 等待所有异步请求完成 |
| | | try { |
| | | const completedProcessCards = await Promise.all(detailPromises); |
| | | |
| | | // 将完成的流程卡添加到computed.value中 |
| | | if (!computed.value.process_cards) { |
| | | computed.value.process_cards = []; |
| | | } |
| | | }) |
| | | computed.value.process_cards.push(processCard) |
| | | }) |
| | | console.log(computed.value) |
| | | }else{ |
| | | ElMessage.warning("没有需要钢化工艺的数据请直接保存") |
| | | state.value=3 |
| | | return |
| | | } |
| | | 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(); |
| | | }; |
| | | |
| | | |
| | | /*request.post(`/glassOptimize/simulationCalculate`,computed.value).then((res) => { |
| | |
| | | text: '正在计算中,请稍候...', |
| | | background: 'rgba(0, 0, 0, 0.7)' |
| | | }); |
| | | console.log('发送到后端的数据',computedCard.value) |
| | | // console.log('发送到后端的数据',computedCard.value) |
| | | const mockData = { |
| | | code: 200, |
| | | data: [ |