From 842da1670c7b652ab131982c73f3eb78e82212e4 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 20 五月 2026 18:02:40 +0800
Subject: [PATCH] feat:1.销售产品从库存选择

---
 src/api/basicData/product.js                    |    9 ++++
 src/views/salesManagement/salesLedger/index.vue |  109 ++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 89 insertions(+), 29 deletions(-)

diff --git a/src/api/basicData/product.js b/src/api/basicData/product.js
index d29a064..0964afd 100644
--- a/src/api/basicData/product.js
+++ b/src/api/basicData/product.js
@@ -64,4 +64,13 @@
         method: 'get',
         responseType: 'blob'
     })
+}
+
+// 鎴愬搧搴撳瓨鍒楄〃锛堢敤浜庨攢鍞彴璐︿骇鍝侀�夋嫨锛�
+export function finishedProductList(query) {
+    return request({
+        url: '/stockInventory/finishedProductList',
+        method: 'get',
+        params: query
+    })
 }
\ No newline at end of file
diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index c2be59c..3e9c0b2 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -344,10 +344,10 @@
 				</el-row>
 				<el-row :gutter="30">
 					<el-col :span="24">
-						<el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
-							<el-select v-model="productForm.productModelId" placeholder="璇烽�夋嫨" clearable
+						<el-form-item label="鐢靛帇锛�" prop="stockId">
+							<el-select v-model="productForm.stockId" placeholder="璇烽�夋嫨" clearable
 								@change="getProductModel" filterable>
-								<el-option v-for="item in modelOptions" :key="item.id" :label="item.model"
+								<el-option v-for="item in modelOptions" :key="item.id" :label="item.label"
 									:value="item.id" />
 							</el-select>
 						</el-form-item>
@@ -672,7 +672,7 @@
   delProduct,
   delLedgerFile, getProductInventory,
 } from "@/api/salesManagement/salesLedger.js";
-import { modelList, productTreeList } from "@/api/basicData/product.js";
+import { finishedProductList } from "@/api/basicData/product.js";
 import useFormData from "@/hooks/useFormData.js";
 import dayjs from "dayjs";
 import { getCurrentDate } from "@/utils/index.js";
@@ -686,6 +686,7 @@
 const userList = ref([]);
 const customerOption = ref([]);
 const productOptions = ref([]);
+const productOptionsRaw = ref([]); // 淇濆瓨鍘熷鏁版嵁锛堝寘鍚� children锛�
 const modelOptions = ref([]);
 const tableLoading = ref(false);
 const page = reactive({
@@ -920,35 +921,71 @@
 // 鑾峰彇浜у搧澶х被tree鏁版嵁
 const getProductOptions = () => {
 	// 杩斿洖 Promise锛屼究浜庡湪缂栬緫浜у搧鏃剁瓑寰呭姞杞藉畬鎴�
-	return productTreeList({productName: '鎴愬搧'}).then((res) => {
-		const tree = convertIdToValue(res);
-		const finishedNode = tree.find(
-			(item) => item?.label === '鎴愬搧' || item?.productName === '鎴愬搧'
-		);
-		productOptions.value = finishedNode?.children || tree;
+	return finishedProductList({}).then((res) => {
+		// 淇濆瓨鍘熷鏁版嵁锛堝寘鍚� children锛夌敤浜庡悗缁彁鍙栫數鍘嬪垪琛�
+		productOptionsRaw.value = res || [];
+		// 浜у搧澶х被涓嬫媺閫夐」
+		productOptions.value = (res || []).map(item => ({
+			...item,
+			value: item.productId,  // 鐢� productId 浣滀负 value
+			children: undefined     // 鍘绘帀涓嬫媺绠ご
+		}));
 		return productOptions.value;
 	});
 };
 const formattedNumber = (row, column, cellValue) => {
 	return parseFloat(cellValue).toFixed(2);
 };
-// 鑾峰彇tree瀛愭暟鎹�
+// 鑾峰彇tree瀛愭暟鎹紙浠� children 涓彁鍙栫數鍘嬪垪琛級
 const getModels = (value) => {
 	productForm.value.productCategory = findNodeById(productOptions.value, value);
-	modelList({ id: value }).then((res) => {
-		modelOptions.value = res;
-	});
+	// 浠庡師濮嬫暟鎹腑鎵惧埌閫変腑鐨勮妭鐐癸紙鍖呭惈 children锛�
+	const selectedNode = productOptionsRaw.value.find(item => item.productId === value);
+	if (selectedNode && selectedNode.children && selectedNode.children.length > 0) {
+		// 鎻愬彇 children 涓殑鍨嬪彿鏁版嵁锛屾嫾鎺ユ樉绀烘枃鏈�
+		modelOptions.value = selectedNode.children
+			.map(item => {
+				// 鎷兼帴鏄剧ず鏂囨湰锛歮odel - processCategory - voltage锛堣繃婊ょ┖瀛楃涓诧級
+				const parts = [];
+				if (item.model && item.model.trim()) parts.push(item.model);
+				if (item.processCategory && item.processCategory.trim()) parts.push(item.processCategory);
+				if (item.voltage && item.voltage.trim()) parts.push(item.voltage);
+				return {
+					...item,
+					id: item.stockId,  // 鐢� stockId 浣滀负鍞竴鏍囪瘑
+					productModelId: item.productModelId,  // 淇濆瓨 productModelId 鐢ㄤ簬鎻愪氦
+					label: parts.join('-')
+				};
+			})
+			.filter(item => item.label);  // 杩囨护鎺� label 涓虹┖鐨勯�夐」
+	} else {
+		modelOptions.value = [];
+	}
 };
 const getProductModel = (value) => {
 	const index = modelOptions.value.findIndex((item) => item.id === value);
 	if (index !== -1) {
-		productForm.value.specificationModel = modelOptions.value[index].model;
-		productForm.value.unit = modelOptions.value[index].unit;
-		productForm.value.materialCode = modelOptions.value[index].materialCode;
+		const selectedItem = modelOptions.value[index];
+		// 瑙勬牸鍨嬪彿瀛樺偍鎷兼帴鍊硷紝鐢ㄤ簬琛ㄦ牸鏄剧ず
+		productForm.value.specificationModel = selectedItem.label;
+		productForm.value.unit = selectedItem.unit;
+		productForm.value.materialCode = selectedItem.materialCode;
+		// 淇濆瓨鐢靛帇淇℃伅
+		productForm.value.voltage = selectedItem.voltage;
+		// 淇濆瓨宸ュ簭绫诲埆
+		productForm.value.processCategory = selectedItem.processCategory;
+		// 淇濆瓨 productModelId 鐢ㄤ簬鎻愪氦
+		productForm.value.productModelId = selectedItem.productModelId;
+		// 淇濆瓨 stockId 鐢ㄤ簬鎻愪氦
+		productForm.value.stockId = selectedItem.stockId;
 	} else {
 		productForm.value.specificationModel = null;
 		productForm.value.unit = null;
 		productForm.value.materialCode = null;
+		productForm.value.voltage = null;
+		productForm.value.processCategory = null;
+		productForm.value.productModelId = null;
+		productForm.value.stockId = null;
 	}
 };
 const findNodeById = (nodes, productId) => {
@@ -967,13 +1004,13 @@
 };
 function convertIdToValue(data) {
 	return data.map((item) => {
-		const { id, children, ...rest } = item;
+		const { productId, children, ...rest } = item;
 		const newItem = {
 			...rest,
-			value: id, // 灏� id 鏀逛负 value
+			value: productId, // 浜у搧澶х被鐢� productId 浣滀负 value
 		};
 		if (children && children.length > 0) {
-			newItem.children = convertIdToValue(children);
+			newItem.children = children;  // children 淇濇寔鍘熸牱
 		}
 
 		return newItem;
@@ -1272,22 +1309,36 @@
 	if (type === "edit") {
 		productForm.value = { ...row };
 		productIndex.value = index;
-		// 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� tree 鑺傜偣 id锛屽苟鍔犺浇瑙勬牸鍨嬪彿鍒楄〃
+		// 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� tree 鑺傜偣 id锛屽苟鍔犺浇鐢靛帇鍒楄〃
 		try {
 			const options = productOptions.value && productOptions.value.length > 0
 				? productOptions.value
 				: await getProductOptions();
 			const categoryId = findNodeIdByLabel(options, productForm.value.productCategory);
 			if (categoryId) {
-				const models = await modelList({ id: categoryId });
-				modelOptions.value = models || [];
-				// 鏍规嵁褰撳墠瑙勬牸鍨嬪彿鍚嶇О鍙嶆煡骞惰缃� productModelId锛屼究浜庝笅鎷夋鏄剧ず宸查�夊��
-				const currentModel = (modelOptions.value || []).find(
-					(m) => m.model === productForm.value.specificationModel
-				);
-				if (currentModel) {
-					productForm.value.productModelId = currentModel.id;
+				// 浠庡師濮嬫暟鎹腑鎵惧埌閫変腑鐨勮妭鐐癸紝鎻愬彇 children
+				const selectedNode = productOptionsRaw.value.find(item => item.productId === categoryId);
+				if (selectedNode && selectedNode.children && selectedNode.children.length > 0) {
+					modelOptions.value = selectedNode.children
+						.map(item => {
+							// 鎷兼帴鏄剧ず鏂囨湰锛歮odel - processCategory - voltage锛堣繃婊ょ┖瀛楃涓诧級
+							const parts = [];
+							if (item.model && item.model.trim()) parts.push(item.model);
+							if (item.processCategory && item.processCategory.trim()) parts.push(item.processCategory);
+							if (item.voltage && item.voltage.trim()) parts.push(item.voltage);
+							return {
+								...item,
+								id: item.stockId,  // 鐢� stockId 浣滀负鍞竴鏍囪瘑
+								productModelId: item.productModelId,
+								label: parts.join('-')
+							};
+						})
+						.filter(item => item.label);  // 杩囨护鎺� label 涓虹┖鐨勯�夐」
 				}
+				// 鏍规嵁褰撳墠 stockId 璁剧疆閫変腑鍊硷紙鐢ㄤ簬涓嬫媺妗嗗洖鏄撅級
+				productForm.value.stockId = row.stockId;
+				// 鍚屾椂淇濆瓨 productModelId
+				productForm.value.productModelId = row.productModelId;
 			}
 		} catch (e) {
 			// 鍔犺浇澶辫触鏃朵繚鎸佸彲缂栬緫锛屼笉涓柇寮圭獥

--
Gitblit v1.9.3