| | |
| | | <span>总量(kg):</span> |
| | | <el-input-number v-model="machineData[machine.name].workLoad" :min="0" :step="1" size="small" /> |
| | | </div> |
| | | <div><span>正在工作量(kg):</span><span>{{ machineData[machine.name].currentWorkLoad }}</span></div> |
| | | <div><span> 预计投入量(kg):</span><span>{{ machineData[machine.name].currentWorkLoad }}</span></div> |
| | | <div><span>空余工作量(kg):</span><span>{{ machineData[machine.name].vacant }}</span></div> |
| | | </div> |
| | | </div> |
| | | <div class="save-button-container"> |
| | | <div class="loss-rate-container"> |
| | | <span class="loss-rate-label">损耗率(%):</span> |
| | | <el-select v-model="rate" placeholder="请选择损耗率" style="width: 120px" size="small"> |
| | | <el-option label="6" :value="6" /> |
| | | <el-option label="7" :value="7" /> |
| | | <el-option label="8" :value="8" /> |
| | | <el-option label="9" :value="9" /> |
| | | <el-option label="10" :value="10" /> |
| | | </el-select> |
| | | </div> |
| | | <el-button type="primary" @click="saveMachineTotals" size="small">保存设置</el-button> |
| | | </div> |
| | | </div> |
| | |
| | | clearable |
| | | prefix-icon="Search" |
| | | /> |
| | | <span class="search_title ml10">项目名称:</span> |
| | | <el-input |
| | | v-model="searchForm.projectName" |
| | | style="width: 240px" |
| | | placeholder="请输入" |
| | | @change="handleQuery" |
| | | clearable |
| | | prefix-icon="Search" |
| | | /> |
| | | <!-- <span class="search_title ml10">项目名称:</span>--> |
| | | <!-- <el-input--> |
| | | <!-- v-model="searchForm.projectName"--> |
| | | <!-- style="width: 240px"--> |
| | | <!-- placeholder="请输入"--> |
| | | <!-- @change="handleQuery"--> |
| | | <!-- clearable--> |
| | | <!-- prefix-icon="Search"--> |
| | | <!-- />--> |
| | | <span class="search_title ml10">录入日期:</span> |
| | | <el-date-picker v-model="searchForm.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange" |
| | | placeholder="请选择" clearable @change="changeDaterange" /> |
| | | <el-checkbox |
| | | style="margin-left: 10px" |
| | | v-model="searchForm.status" |
| | | label="不显示待排数量为0" |
| | | @change="handleQuery" |
| | | /> |
| | | <el-button type="primary" @click="handleQuery" style="margin-left: 10px">搜索</el-button> |
| | | </div> |
| | | <div> |
| | |
| | | import FormDia from "@/views/productionManagement/productionDispatching/components/formDia.vue"; |
| | | import AutoDispatchDia from "@/views/productionManagement/productionDispatching/components/autoDispatchDia.vue"; |
| | | import dayjs from "dayjs"; |
| | | import {schedulingListPage, schedulingList, addSpeculatTrading, updateSpeculatTrading} from "@/api/productionManagement/productionOrder.js"; |
| | | import {schedulingListPage, schedulingList, addSpeculatTrading, updateSpeculatTrading, getLossRate, addLossRate, updateLossRate} from "@/api/productionManagement/productionOrder.js"; |
| | | import { ElMessageBox } from "element-plus"; |
| | | |
| | | const data = reactive({ |
| | | searchForm: { |
| | | customerName: "", |
| | | projectName: "", |
| | | entryDate: null, // 录入日期 |
| | | entryDateStart: undefined, |
| | | entryDateEnd: undefined, |
| | | status: true, |
| | | entryDate: [dayjs().format("YYYY-MM-DD"), dayjs().format("YYYY-MM-DD")], // 录入日期,默认当天 |
| | | entryDateStart: dayjs().format("YYYY-MM-DD"), |
| | | entryDateEnd: dayjs().format("YYYY-MM-DD"), |
| | | }, |
| | | }); |
| | | const { searchForm } = toRefs(data); |
| | |
| | | prop: "salesContractNo", |
| | | width: 220, |
| | | }, |
| | | { |
| | | label: "客户合同号", |
| | | prop: "customerContractNo", |
| | | width: 250, |
| | | }, |
| | | // { |
| | | // label: "客户合同号", |
| | | // prop: "customerContractNo", |
| | | // width: 250, |
| | | // }, |
| | | { |
| | | label: "客户名称", |
| | | prop: "customerName", |
| | | width: 250, |
| | | }, |
| | | { |
| | | label: "项目名称", |
| | | prop: "projectName", |
| | | width:300 |
| | | }, |
| | | // { |
| | | // label: "项目名称", |
| | | // prop: "projectName", |
| | | // width:300 |
| | | // }, |
| | | { |
| | | label: "产品大类", |
| | | prop: "productCategory", |
| | |
| | | label: "待排数量", |
| | | prop: "pendingQuantity", |
| | | width: 100, |
| | | fixed: 'right', |
| | | }, |
| | | ]); |
| | | const tableData = ref([]); |
| | |
| | | |
| | | // 保存炒机总量设置 |
| | | const saveMachineTotals = () => { |
| | | // 验证损耗率是否已选择 |
| | | if (rate.value === null || rate.value === undefined || isNaN(rate.value)) { |
| | | proxy.$message.warning('请选择损耗率'); |
| | | return; |
| | | } |
| | | |
| | | // 构造保存数据数组,使用machines数组循环构建 |
| | | const saveData = machines.map(machine => { |
| | | const saveItem = { |
| | | name: machine.name, // 炒机名称 |
| | | workLoad: machineData[machine.name].workLoad, // 总量 |
| | | currentWorkLoad: machineData[machine.name].currentWorkLoad, // 正在工作量 |
| | | currentWorkLoad: machineData[machine.name].currentWorkLoad, // 预计投入量 |
| | | vacant: machineData[machine.name].vacant // 空余量 |
| | | }; |
| | | |
| | | // 如果是修改操作,需要传递id字段 |
| | | if (hasQueryData.value) { |
| | | // 这里需要从查询数据中获取对应的id |
| | | // 假设查询数据中每个炒机数据都有id字段 |
| | | const queryData = getMachineQueryData(machine.id); |
| | | if (queryData && queryData.id) { |
| | | saveItem.id = queryData.id; |
| | |
| | | return saveItem; |
| | | }); |
| | | |
| | | console.log('保存炒机设置数据:', saveData); |
| | | // 构造损耗率数据 |
| | | const rateData = { |
| | | rate: rate.value |
| | | }; |
| | | |
| | | // 如果有ID,说明是修改操作 |
| | | if (rateId.value) { |
| | | rateData.id = rateId.value; |
| | | } |
| | | |
| | | // 根据是否有查询数据决定调用新增接口还是修改接口 |
| | | const saveApi = hasQueryData.value ? updateSpeculatTrading : addSpeculatTrading; |
| | | const successMessage = hasQueryData.value ? '炒机设置修改成功' : '炒机设置新增成功'; |
| | | |
| | | console.log(`调用接口: ${hasQueryData.value ? '修改' : '新增'}`); |
| | | // 根据是否有ID决定调用新增接口还是修改接口 |
| | | const rateApi = rateId.value ? updateLossRate : addLossRate; |
| | | const rateSuccessMessage = rateId.value ? '损耗率修改成功' : '损耗率新增成功'; |
| | | |
| | | // 调用后端API保存 |
| | | saveApi(saveData).then(res => { |
| | | // 并行调用两个接口 |
| | | Promise.all([ |
| | | saveApi(saveData), |
| | | rateApi(rateData) |
| | | ]).then(([saveRes, rateRes]) => { |
| | | proxy.$message.success(successMessage); |
| | | console.log('保存成功:', res); |
| | | proxy.$message.success(rateSuccessMessage); |
| | | |
| | | // 保存成功后,设置hasQueryData为true,下次保存将调用修改接口 |
| | | if (!hasQueryData.value) { |
| | | hasQueryData.value = true; |
| | | } |
| | | |
| | | // 如果返回了ID,保存起来 |
| | | if (rateRes && rateRes.data && rateRes.data.id) { |
| | | rateId.value = rateRes.data.id; |
| | | } |
| | | |
| | | // 保存成功后重新调用查询页面 |
| | | getList(); |
| | | }).catch(err => { |
| | | proxy.$message.error('保存失败'); |
| | | console.error('保存失败:', err); |
| | |
| | | |
| | | // 是否有查询数据 |
| | | const hasQueryData = ref(false) |
| | | // 损耗率 |
| | | const rate = ref(6) |
| | | // 损耗率ID |
| | | const rateId = ref(null) |
| | | |
| | | // 获取炒机正在工作量数据 |
| | | const getMachineProductionData = () => { |
| | |
| | | machineData[machineName].vacant = machineData[machineName].workLoad - machineData[machineName].currentWorkLoad; |
| | | } |
| | | }); |
| | | |
| | | console.log('炒机数据初始化完成:', machineData); |
| | | console.log('炒机查询数据:', machineQueryData.value); |
| | | } |
| | | }).catch(err => { |
| | | console.error('获取炒机正在工作量数据失败:', err); |
| | |
| | | |
| | | // 同时获取炒机正在工作量数据 |
| | | getMachineProductionData(); |
| | | // 获取损耗率数据 |
| | | getLossRateData(); |
| | | }).catch(() => { |
| | | tableLoading.value = false; |
| | | }) |
| | | }; |
| | | |
| | | // 获取损耗率数据 |
| | | const getLossRateData = () => { |
| | | getLossRate().then((res) => { |
| | | const data = res.data || res; |
| | | if (data && data.rate !== undefined && data.rate !== null) { |
| | | rate.value = Number(data.rate); // 确保转换为数字 |
| | | rateId.value = data.id || null; |
| | | } else { |
| | | rate.value = 6; |
| | | rateId.value = null; |
| | | } |
| | | }).catch(err => { |
| | | console.error('获取损耗率数据失败:', err); |
| | | rate.value = 6; |
| | | rateId.value = null; |
| | | }); |
| | | }; |
| | | // 表格选择数据 |
| | | const handleSelectionChange = (selection) => { |
| | |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | getLossRateData(); |
| | | }); |
| | | </script> |
| | | |
| | |
| | | grid-column: 1 / -1; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | gap: 16px; |
| | | margin-top: 16px; |
| | | padding-top: 16px; |
| | | border-top: 1px solid #e9ecef; |
| | | } |
| | | .loss-rate-container{ |
| | | display: flex; |
| | | align-items: center; |
| | | gap: 8px; |
| | | } |
| | | .loss-rate-label{ |
| | | font-size: 14px; |
| | | color: #6c757d; |
| | | font-weight: 500; |
| | | white-space: nowrap; |
| | | } |
| | | </style> |