From 50b6007b336a65b7deb6c77c9fdc608865067608 Mon Sep 17 00:00:00 2001 From: 张诺 <2864490065@qq.com> Date: 星期五, 25 七月 2025 16:31:57 +0800 Subject: [PATCH] 昭德改善销售数量 --- src/views/equipment/management/mould/equipmentRequisitionDialog.vue | 169 ++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 110 insertions(+), 59 deletions(-) diff --git a/src/views/equipment/management/mould/equipmentRequisitionDialog.vue b/src/views/equipment/management/mould/equipmentRequisitionDialog.vue index b0086e4..9abe870 100644 --- a/src/views/equipment/management/mould/equipmentRequisitionDialog.vue +++ b/src/views/equipment/management/mould/equipmentRequisitionDialog.vue @@ -1,7 +1,9 @@ <template> <el-dialog v-model="visible" - :title="isReturnMode ? '璁惧褰掕繕' : (isEdit ? '缂栬緫璁惧棰嗙敤' : '鏂板璁惧棰嗙敤')" + :title=" + isReturnMode ? '璁惧褰掕繕' : isEdit ? '缂栬緫璁惧棰嗙敤' : '鏂板璁惧棰嗙敤' + " width="600px" @close="handleClose" > @@ -35,7 +37,21 @@ /> </el-select> </el-form-item> - <el-form-item label="璁惧搴撳瓨" prop="equipmentStock" v-if="!isReturnMode && formData.status !== 2"> + <el-form-item label="鏄惁涓烘秷鑰楀搧" prop="isConsumables"> + <el-select + :model-value="currentConsumables" + placeholder="璇烽�夋嫨鏄惁涓鸿�楁潗绫诲瀷" + :disabled="true" + > + <el-option label="鏄�" :value="true" /> + <el-option label="鍚�" :value="false" /> + </el-select> + </el-form-item> + <el-form-item + label="璁惧搴撳瓨" + prop="equipmentStock" + v-if="!isReturnMode && formData.status !== 2" + > <el-input :value=" equipmentList.find((item) => item.id == form.equipmentId) @@ -52,14 +68,22 @@ style="width: 100%" /> </el-form-item> - <el-form-item label="宸插綊杩樻暟閲�" prop="returnedQuantity" v-if="isReturnMode"> + <el-form-item + label="宸插綊杩樻暟閲�" + prop="returnedQuantity" + v-if="isReturnMode" + > <el-input :value="formData.totalReturnNo || 0" disabled style="width: 100%" /> </el-form-item> - <el-form-item label="棰嗙敤鏁伴噺" prop="usageQuantity" v-if="!isReturnMode && formData.status !== 2"> + <el-form-item + label="棰嗙敤鏁伴噺" + prop="usageQuantity" + v-if="!isReturnMode && formData.status !== 2" + > <el-input-number v-model="form.usageQuantity" :min="1" @@ -73,7 +97,11 @@ >(鏈�澶歿{ maxQuantity }}鍙�)</span > </el-form-item> - <el-form-item label="鏈褰掕繕鏁伴噺" prop="returnQuantity" v-if="isReturnMode"> + <el-form-item + label="鏈褰掕繕鏁伴噺" + prop="returnQuantity" + v-if="isReturnMode" + > <el-input-number v-model="form.returnQuantity" :min="1" @@ -86,21 +114,26 @@ v-if="remainingReturnQuantity > 0" >(鏈�澶歿{ remainingReturnQuantity }}鍙�)</span > - <span - style="color: #67c23a; font-size: 12px; margin-left: 8px" - v-else + <span style="color: #67c23a; font-size: 12px; margin-left: 8px" v-else >(宸插叏閮ㄥ綊杩�)</span > <!-- 褰掕繕瀹屾垚鎻愮ず --> - <div - v-if="remainingReturnQuantity > 0 && form.returnQuantity === remainingReturnQuantity" + <div + v-if=" + remainingReturnQuantity > 0 && + form.returnQuantity === remainingReturnQuantity + " style="color: #67c23a; font-size: 12px; margin-top: 4px" > 馃挕 鎻愮ず锛氭湰娆″綊杩樺悗灏嗗畬鎴愬叏閮ㄥ綊杩� </div> </el-form-item> <!-- 浣跨敤寮�濮嬫椂闂� - 鍙湪闈炲綊杩樻ā寮忔樉绀� --> - <el-form-item label="浣跨敤寮�濮嬫椂闂�" prop="usageStartTime" v-if="!isReturnMode"> + <el-form-item + label="浣跨敤寮�濮嬫椂闂�" + prop="usageStartTime" + v-if="!isReturnMode" + > <el-date-picker v-model="form.usageStartTime" type="datetime" @@ -111,7 +144,7 @@ :disabled="isViewMode" /> </el-form-item> - + <!-- 褰掕繕缁撴潫鏃堕棿 - 鍙湪褰掕繕妯″紡鏄剧ず --> <el-form-item label="褰掕繕鏃堕棿" prop="returnTime" v-if="isReturnMode"> <el-date-picker @@ -166,7 +199,6 @@ ElMessage.error("鑾峰彇璁惧鍒楄〃澶辫触"); } }; - const props = defineProps({ modelValue: Boolean, formData: { @@ -177,6 +209,23 @@ type: String, default: "add", }, +}); + +// 榛樿琛ㄥ崟鍒濆鍊� +const defaultForm = { + userId: "", + equipmentId: "", + usageQuantity: 1, + usageStartTime: "", + returnQuantity: 1, + returnTime: "", + remarks: "", +}; +const form = ref({ ...defaultForm }); + +const currentConsumables = computed(() => { + const eq = equipmentList.value.find(item => item.id == form.value.equipmentId); + return eq ? !!eq.isConsumables : false; }); const maxQuantity = computed(() => { if (!form.value.equipmentId) return 0; @@ -192,10 +241,18 @@ get: () => props.modelValue, set: (v) => emit("update:modelValue", v), }); + +// 鐩戝惉璁惧閫夋嫨鍙樺寲 +watch( + () => form.value.equipmentId, + (newId) => { + if (newId) { + const eq = equipmentList.value.find(item => item.id == newId); + } + } +); const isViewMode = computed( - () => - props.addOrEdit === "view" || - props.addOrEdit === "viewRow" + () => props.addOrEdit === "view" || props.addOrEdit === "viewRow" ); // 鍒ゆ柇鏄惁涓哄綊杩樻ā寮� @@ -204,35 +261,23 @@ // 璁$畻鍓╀綑鍙綊杩樻暟閲� const remainingReturnQuantity = computed(() => { if (!isReturnMode.value || !props.formData.usageQuantity) return 0; - + const totalUsageQuantity = props.formData.usageQuantity || 0; // 鎬讳娇鐢ㄦ暟閲� const alreadyReturnedQuantity = props.formData.totalReturnNo || 0; // 宸插綊杩樻暟閲� const remaining = totalUsageQuantity - alreadyReturnedQuantity; // 鍓╀綑鍙綊杩樻暟閲� - + return Math.max(0, remaining); // 纭繚涓嶄负璐熸暟 }); const isEdit = computed(() => !!props.formData?.id); const formRef = ref(); -// 榛樿琛ㄥ崟鍒濆鍊� -const defaultForm = { - userId: "", - equipmentId: "", - usageQuantity: 1, - usageStartTime: "", - returnQuantity: 1, - returnTime: "", - remarks: "", -}; -const form = ref({ ...defaultForm }); - // 鑾峰彇褰撳墠鏃ユ湡锛圷YYY-MM-DD鏍煎紡锛� const getCurrentDate = () => { const now = new Date(); const year = now.getFullYear(); - const month = String(now.getMonth() + 1).padStart(2, '0'); - const day = String(now.getDate()).padStart(2, '0'); + const month = String(now.getMonth() + 1).padStart(2, "0"); + const day = String(now.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; }; @@ -246,12 +291,13 @@ (val) => { if (val && Object.keys(val).length > 0) { form.value = { ...val }; - + // 褰掕繕妯″紡鍒濆鍖� if (isReturnMode.value) { form.value.returnTime = getCurrentDate(); const maxReturnQuantity = remainingReturnQuantity.value; - form.value.returnQuantity = maxReturnQuantity > 0 ? Math.min(1, maxReturnQuantity) : 0; + form.value.returnQuantity = + maxReturnQuantity > 0 ? Math.min(1, maxReturnQuantity) : 0; } } else { form.value = { ...defaultForm }; @@ -279,7 +325,9 @@ if (remaining <= 0) { callback(new Error("宸插叏閮ㄥ綊杩橈紝鏃犳硶缁х画褰掕繕")); } else if (value > remaining) { - callback(new Error(`褰掕繕鏁伴噺涓嶈兘澶т簬鍓╀綑鍙綊杩樻暟閲�(${remaining}鍙�)`)); + callback( + new Error(`褰掕繕鏁伴噺涓嶈兘澶т簬鍓╀綑鍙綊杩樻暟閲�(${remaining}鍙�)`) + ); } else { callback(); } @@ -335,60 +383,63 @@ // 闃叉姈鍚庣殑鎻愪氦鏂规硶 const debouncedSubmit = debounce(handleSubmit, 800); -function handleSubmit () { +function handleSubmit() { formRef.value.validate(async (valid) => { if (!valid) return; - + let submitData = { ...form.value }; - + // 褰掕繕妯″紡澶勭悊 if (isReturnMode.value) { const currentReturnQuantity = form.value.returnQuantity; const totalUsageQuantity = props.formData.usageQuantity; const alreadyReturnedQuantity = props.formData.totalReturnNo || 0; - const newTotalReturnedQuantity = alreadyReturnedQuantity + currentReturnQuantity; - + const newTotalReturnedQuantity = + alreadyReturnedQuantity + currentReturnQuantity; + // 鍒ゆ柇鏄惁鍏ㄩ儴褰掕繕瀹屾垚 let equipmentStatus = 2; // 榛樿涓洪儴鍒嗗綊杩� let isFullyReturned = newTotalReturnedQuantity >= totalUsageQuantity; - + if (isFullyReturned) { equipmentStatus = 3; // 鍏ㄩ儴褰掕繕瀹屾垚 - + // 鍏ㄩ儴褰掕繕鏃剁殑纭鎻愮ず try { await ElMessageBox.confirm( - `纭灏嗚澶�"${props.formData.equipmentName || '鏈煡璁惧'}"鍏ㄩ儴褰掕繕鍚楋紵褰掕繕鍚庤澶囩姸鎬佸皢鍙樹负"宸插綊杩�"銆俙, - '纭鍏ㄩ儴褰掕繕', + `纭灏嗚澶�"${ + props.formData.equipmentName || "鏈煡璁惧" + }"鍏ㄩ儴褰掕繕鍚楋紵褰掕繕鍚庤澶囩姸鎬佸皢鍙樹负"宸插綊杩�"銆俙, + "纭鍏ㄩ儴褰掕繕", { - confirmButtonText: '纭褰掕繕', - cancelButtonText: '鍙栨秷', - type: 'success', + confirmButtonText: "纭褰掕繕", + cancelButtonText: "鍙栨秷", + type: "success", } ); } catch (error) { - if (error === 'cancel') { - ElMessage.info('宸插彇娑堝綊杩樻搷浣�'); + if (error === "cancel") { + ElMessage.info("宸插彇娑堝綊杩樻搷浣�"); return; } } - - console.log('璁惧褰掕繕瀹屾垚:', { + + console.log("璁惧褰掕繕瀹屾垚:", { 璁惧鍚嶇О: props.formData.equipmentName, 鎬讳娇鐢ㄦ暟閲�: totalUsageQuantity, 鏂扮殑褰掕繕鎬绘暟: newTotalReturnedQuantity, - 鐘舵��: '宸插叏閮ㄥ綊杩�' + 鐘舵��: "宸插叏閮ㄥ綊杩�", }); } else { - console.log('璁惧閮ㄥ垎褰掕繕:', { + console.log("璁惧閮ㄥ垎褰掕繕:", { 璁惧鍚嶇О: props.formData.equipmentName, 鎬讳娇鐢ㄦ暟閲�: totalUsageQuantity, 宸插綊杩樻暟閲�: newTotalReturnedQuantity, 鍓╀綑鏈綊杩�: totalUsageQuantity - newTotalReturnedQuantity, - 鐘舵��: '閮ㄥ垎褰掕繕' + 鐘舵��: "閮ㄥ垎褰掕繕", }); } - + submitData = { ...props.formData, totalReturnNo: newTotalReturnedQuantity, @@ -396,22 +447,22 @@ returnTime: form.value.returnTime, equipmentStatus: equipmentStatus, remarks: form.value.remarks, - usageQuantity: totalUsageQuantity + usageQuantity: totalUsageQuantity, }; } try { - let {code,data} = await addOrEditUsageRecord(submitData); + let { code, data } = await addOrEditUsageRecord(submitData); if (code !== 200) { ElMessage.error(data.msg || "鎿嶄綔澶辫触"); return; } - if(code == 200 && data == 1){ + if (code == 200 && data == 1) { emit("submit", submitData); } handleClose(); } catch (error) { - console.error('鎻愪氦澶辫触:', error); + console.error("鎻愪氦澶辫触:", error); ElMessage.error("鎿嶄綔澶辫触锛岃绋嶅悗鍐嶈瘯"); } }); -- Gitblit v1.9.3