| | |
| | | import ComputeCard from "@/views/pp/glassOptimize/page/ComputeCard.vue"; |
| | | import ComputeDetail from "@/views/pp/glassOptimize/page/ComputeDetail.vue"; |
| | | import Compute from "@/views/pp/glassOptimize/page/Compute.vue"; |
| | | import {ref, watch} from 'vue'; |
| | | import {ElMessage} from "element-plus"; |
| | | 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) => { |
| | | |
| | | computedCard.value = data; |
| | | // 将 computed.value 合并到 computedCard.value 的最外层 |
| | | computedCard.value = { |
| | | ...computed.value, |
| | | ...computedCard.value |
| | | }; |
| | | }; |
| | | |
| | | // 监听子组件ComputeDetail的数据 |
| | | const handleData = (data) => { |
| | | computed.value = data; |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | if (props.project) { |
| | | console.log('ceshiyixia',props.project) |
| | | handleFetchData(props.project.projectNumber); |
| | | //handleTableData(data); |
| | | //handleDataReceive(data); |
| | | } |
| | | }); |
| | | |
| | | // 在父组件中定义处理接收数据的函数 |
| | | const handleDataReceive= async (data) => { |
| | | console.log('接收到子组件的数据2:', data); |
| | | // 处理数据,例如更新父组件的状态或调用后端API |
| | | |
| | | } |
| | | |
| | | |
| | | // 用于存储从后端获取到的数据,初始化为空数组 |
| | | 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('获取项目信息失败'); |
| | | } |
| | | }; |
| | | |
| | | |
| | | 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) { |
| | |
| | | } |
| | | }; |
| | | |
| | | // 用于从获取到的数据中提取流程卡号(processId) |
| | | const extractProcessCardNumbers = (data) => { |
| | | if (typeof data === 'string') { |
| | | console.log('流程卡号为字符串类型,直接返回该字符串:', data); |
| | | return data; |
| | | const handleTableData= async (data) => { |
| | | // 处理接收到的表格数据 |
| | | console.log('父组件接收到的数据1:', data); |
| | | } |
| | | |
| | | // 发送数据到钢化计算接口 |
| | | 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('返回数据格式异常,使用原始数据'); |
| | | // 即使解析失败也继续使用原始数据 |
| | | } |
| | | } |
| | | |
| | | // 更新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(); |
| | | } |
| | | }finally { |
| | | loading.close(); |
| | | } |
| | | if (Array.isArray(data)) { |
| | | const processCardNumbers = data.map(item => item.process_id); |
| | | console.log('提取到的流程卡号数组:', processCardNumbers); |
| | | return processCardNumbers; |
| | | } |
| | | console.log('传入的数据类型不符合要求,无法提取流程卡号'); |
| | | return []; |
| | | }; |
| | | |
| | | const handleSimulation = async () => { |
| | | let arry = computeCardRef.value.selectFullData(); |
| | | let data = arry; |
| | | data = data.reduce((acc, item) => { |
| | | if (item.tempering) { |
| | | acc.push(item); |
| | | } |
| | | return acc; |
| | | }, []); |
| | | |
| | | 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 (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 = (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> |
| | | |
| | | <template> |
| | | <div style="width: 100%; height: 100%;"> |
| | | |
| | | |
| | | <div id="compute"> |
| | | <compute @fetch-data="handleFetchData" /> |
| | | <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" |
| | | :technology-number="projectRow.technologyNumber===null?null:projectRow.technologyNumber" |
| | | @upProcessId="handleUpdateProcessId" @updateTechnologyNumber="handleTechnologyNumberUpdate" @sendData="handleCardData" |
| | | /> |
| | | </div> |
| | | |
| | | <div id="computeDetail"> |
| | | <compute-detail :process-card-numbers="extractProcessCardNumbers(receivedData)" /> |
| | | <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> |
| | | </template> |
| | | |
| | |
| | | margin-top: -30px; |
| | | margin-bottom: 2%; |
| | | width: 100%; |
| | | height: 40%; |
| | | height: 37%; |
| | | } |
| | | #computeCard{ |
| | | margin-top: 100px; |
| | | width: 64%; |
| | | height: 40%; |
| | | height: 55%; |
| | | float: left; |
| | | } |
| | | #computeDetail{ |
| | | margin-top: 90px; |
| | | margin-left: 1%; |
| | | float: left; |
| | | width: 35%; |
| | | height: 40%; |
| | | height: 55%; |
| | | } |
| | | </style> |