From 7efe917a161f7c6965cfa75ac5ad7e664dcc1eb4 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 14 十一月 2025 09:59:03 +0800
Subject: [PATCH] 1.生产派工-加一个损耗率新增修改

---
 src/views/productionManagement/productionDispatching/index.vue |   96 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/src/views/productionManagement/productionDispatching/index.vue b/src/views/productionManagement/productionDispatching/index.vue
index 6a61e6e..e976013 100644
--- a/src/views/productionManagement/productionDispatching/index.vue
+++ b/src/views/productionManagement/productionDispatching/index.vue
@@ -9,11 +9,21 @@
 					<span>鎬婚噺(kg)锛�</span>
 					<el-input-number v-model="machineData[machine.name].workLoad" :min="0" :step="1" size="small" />
 				</div>
-				<div><span>姝e湪宸ヤ綔閲�(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>
@@ -71,7 +81,7 @@
 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({
@@ -175,19 +185,23 @@
 
 // 淇濆瓨鐐掓満鎬婚噺璁剧疆
 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, // 姝e湪宸ヤ綔閲�
+			currentWorkLoad: machineData[machine.name].currentWorkLoad, //  棰勮鎶曞叆閲�
 			vacant: machineData[machine.name].vacant   // 绌轰綑閲�
 		};
 		
 		// 濡傛灉鏄慨鏀规搷浣滐紝闇�瑕佷紶閫抜d瀛楁
 		if (hasQueryData.value) {
-			// 杩欓噷闇�瑕佷粠鏌ヨ鏁版嵁涓幏鍙栧搴旂殑id
-			// 鍋囪鏌ヨ鏁版嵁涓瘡涓倰鏈烘暟鎹兘鏈塱d瀛楁
 			const queryData = getMachineQueryData(machine.id);
 			if (queryData && queryData.id) {
 				saveItem.id = queryData.id;
@@ -197,23 +211,44 @@
 		return saveItem;
 	});
 	
-	console.log('淇濆瓨鐐掓満璁剧疆鏁版嵁:', saveData);
+	// 鏋勯�犳崯鑰楃巼鏁版嵁
+	const rateData = {
+		rate: rate.value
+	};
+	
+	// 濡傛灉鏈塈D锛岃鏄庢槸淇敼鎿嶄綔
+	if (rateId.value) {
+		rateData.id = rateId.value;
+	}
 	
 	// 鏍规嵁鏄惁鏈夋煡璇㈡暟鎹喅瀹氳皟鐢ㄦ柊澧炴帴鍙h繕鏄慨鏀规帴鍙�
 	const saveApi = hasQueryData.value ? updateSpeculatTrading : addSpeculatTrading;
 	const successMessage = hasQueryData.value ? '鐐掓満璁剧疆淇敼鎴愬姛' : '鐐掓満璁剧疆鏂板鎴愬姛';
 	
-	console.log(`璋冪敤鎺ュ彛: ${hasQueryData.value ? '淇敼' : '鏂板'}`);
+	// 鏍规嵁鏄惁鏈塈D鍐冲畾璋冪敤鏂板鎺ュ彛杩樻槸淇敼鎺ュ彛
+	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涓簍rue锛屼笅娆′繚瀛樺皢璋冪敤淇敼鎺ュ彛
 		if (!hasQueryData.value) {
 			hasQueryData.value = true;
 		}
+		
+		// 濡傛灉杩斿洖浜咺D锛屼繚瀛樿捣鏉�
+		if (rateRes && rateRes.data && rateRes.data.id) {
+			rateId.value = rateRes.data.id;
+		}
+		
+		// 淇濆瓨鎴愬姛鍚庨噸鏂拌皟鐢ㄦ煡璇㈤〉闈�
+		getList();
 	}).catch(err => {
 		proxy.$message.error('淇濆瓨澶辫触');
 		console.error('淇濆瓨澶辫触:', err);
@@ -273,6 +308,10 @@
 
 // 鏄惁鏈夋煡璇㈡暟鎹�
 const hasQueryData = ref(false)
+// 鎹熻�楃巼
+const rate = ref(6)
+// 鎹熻�楃巼ID
+const rateId = ref(null)
 
 // 鑾峰彇鐐掓満姝e湪宸ヤ綔閲忔暟鎹�
 const getMachineProductionData = () => {
@@ -310,9 +349,6 @@
 					machineData[machineName].vacant = machineData[machineName].workLoad - machineData[machineName].currentWorkLoad;
 				}
 			});
-			
-			console.log('鐐掓満鏁版嵁鍒濆鍖栧畬鎴�:', machineData);
-			console.log('鐐掓満鏌ヨ鏁版嵁:', machineQueryData.value);
 		}
 	}).catch(err => {
 		console.error('鑾峰彇鐐掓満姝e湪宸ヤ綔閲忔暟鎹け璐�:', err);
@@ -351,9 +387,29 @@
 		
 		// 鍚屾椂鑾峰彇鐐掓満姝e湪宸ヤ綔閲忔暟鎹�
 		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) => {
@@ -412,6 +468,7 @@
 
 onMounted(() => {
 	getList();
+	getLossRateData();
 });
 </script>
 
@@ -512,8 +569,21 @@
 	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>

--
Gitblit v1.9.3