From 60977504246152d12e2b08640fb63545090d2054 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 12 二月 2026 13:28:55 +0800
Subject: [PATCH] 进销存升级 1.选择台账时,若未来票金额为0时,来票登记按钮置灰,来票结束的采购限制不能继续来票操作)还有台账存在多个产品,若其中一个产品不能继续来票操作,这种情况也需要让有关来票的输入框置灰

---
 src/views/procurementManagement/invoiceEntry/index.vue            |   16 ++++
 src/views/procurementManagement/invoiceEntry/components/Modal.vue |  138 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 118 insertions(+), 36 deletions(-)

diff --git a/src/views/procurementManagement/invoiceEntry/components/Modal.vue b/src/views/procurementManagement/invoiceEntry/components/Modal.vue
index b723175..33d5144 100644
--- a/src/views/procurementManagement/invoiceEntry/components/Modal.vue
+++ b/src/views/procurementManagement/invoiceEntry/components/Modal.vue
@@ -133,10 +133,15 @@
 				/>
 				<el-table-column label="鏈寮�绁ㄦ暟" prop="ticketsNum" width="180">
 					<template #default="scope">
-						<el-input-number :step="0.1" :min="0" :max="scope.row.tempFutureTickets || 0" style="width: 100%"
-														 :precision="2"
-														 v-model="scope.row.ticketsNum"
-														 @change="invoiceNumBlur(scope.row)"
+						<el-input-number 
+							:step="0.1" 
+							:min="0" 
+							:max="scope.row.tempFutureTickets || 0" 
+							style="width: 100%"
+							:precision="2"
+							v-model="scope.row.ticketsNum"
+							:disabled="isProductDisabled(scope.row)"
+							@change="invoiceNumBlur(scope.row)"
 						/>
 					</template>
 				</el-table-column>
@@ -146,10 +151,14 @@
 					width="180"
 				>
 					<template #default="scope">
-						<el-input-number :step="0.01" :min="0" style="width: 100%"
-														 :precision="2"
-														 v-model="scope.row.ticketsAmount"
-														 @change="invoiceAmountBlur(scope.row)"
+						<el-input-number 
+							:step="0.01" 
+							:min="0" 
+							style="width: 100%"
+							:precision="2"
+							v-model="scope.row.ticketsAmount"
+							:disabled="isProductDisabled(scope.row)"
+							@change="invoiceAmountBlur(scope.row)"
 						/>
 					</template>
 				</el-table-column>
@@ -402,7 +411,7 @@
 			
 			// 璁剧疆浜у搧鏁版嵁锛屽苟鍒濆鍖栧紑绁ㄦ暟閲忓拰閲戦
 			allProductData.forEach(item => {
-				// 淇濆瓨鈥滃師濮嬫湭鏉ョエ鏁�/閲戦鈥濓紙鐢ㄤ簬鏍¢獙涓庤绠楋級
+				// 淇濆瓨"鍘熷鏈潵绁ㄦ暟/閲戦"锛堢敤浜庢牎楠屼笌璁$畻锛�
 				// 浼樺厛浣跨敤鍚庣杩斿洖鐨� futureTickets/futureTicketsAmount锛涙病鏈夊垯鍥為��鍒� quantity/taxInclusiveTotalPrice
 				item.tempFutureTickets = Number(
 					item.futureTickets !== undefined ? item.futureTickets : (item.quantity || 0)
@@ -411,15 +420,23 @@
 					item.futureTicketsAmount !== undefined ? item.futureTicketsAmount : (item.taxInclusiveTotalPrice || 0)
 				);
 
-				// 鏂板鏃讹細鏈寮�绁ㄦ暟榛樿 = 鏈潵绁ㄦ暟锛堜笖涓嶈兘澶т簬鏈潵绁ㄦ暟锛�
-				item.ticketsNum = Number(item.tempFutureTickets || 0);
-				// 鑱斿姩璁$畻鏈寮�绁ㄩ噾棰濄�佹湭鏉ョエ鏁般�佹湭鏉ョエ閲戦
-				const unitPrice = Number(item.taxInclusiveUnitPrice || 0);
-				item.ticketsAmount = Number((item.ticketsNum * unitPrice).toFixed(2));
-				item.futureTickets = Number((item.tempFutureTickets - item.ticketsNum).toFixed(2));
-				item.futureTicketsAmount = Number(
-					(item.tempFutureTicketsAmount - item.ticketsAmount).toFixed(2)
-				);
+				// 濡傛灉鏈潵绁ㄩ噾棰濅负0锛屽垯鏈寮�绁ㄦ暟鍜岄噾棰濋兘璁剧疆涓�0
+				if (item.tempFutureTicketsAmount <= 0) {
+					item.ticketsNum = 0;
+					item.ticketsAmount = 0;
+					item.futureTickets = Number(item.tempFutureTickets || 0);
+					item.futureTicketsAmount = 0;
+				} else {
+					// 鏂板鏃讹細鏈寮�绁ㄦ暟榛樿 = 鏈潵绁ㄦ暟锛堜笖涓嶈兘澶т簬鏈潵绁ㄦ暟锛�
+					item.ticketsNum = Number(item.tempFutureTickets || 0);
+					// 鑱斿姩璁$畻鏈寮�绁ㄩ噾棰濄�佹湭鏉ョエ鏁般�佹湭鏉ョエ閲戦
+					const unitPrice = Number(item.taxInclusiveUnitPrice || 0);
+					item.ticketsAmount = Number((item.ticketsNum * unitPrice).toFixed(2));
+					item.futureTickets = Number((item.tempFutureTickets - item.ticketsNum).toFixed(2));
+					item.futureTicketsAmount = Number(
+						(item.tempFutureTicketsAmount - item.ticketsAmount).toFixed(2)
+					);
+				}
 			});
 			
 			form.productData = allProductData;
@@ -435,15 +452,45 @@
 		});
 	} else if (type == "edit") {
 		const id = Array.isArray(selectedRows) ? selectedRows[0].id : selectedRows;
-		const data = await getPurchaseById({ id, type: 2 });
-		form.purchaseLedgerNo = data.purchaseContractNumber;
+		const response = await getPurchaseById({ id, type: 2 });
+		// 鍏煎涓嶅悓鐨勮繑鍥炴牸寮忥細鍙兘鏄� { code, data } 鎴栫洿鎺ヨ繑鍥炴暟鎹�
+		const data = response.data || response;
+		
+		// 鍏煎涓嶅悓鐨勫瓧娈靛悕锛歱urchaseContractNumber 鎴� purchaseLedgerNo
+		form.purchaseLedgerNo = data.purchaseContractNumber || data.purchaseLedgerNo || "";
 		form.invoiceAmount = data.invoiceAmount;
 		form.invoiceNumber = data.invoiceNumber;
 		form.salesContractNo = data.salesContractNo;
 		form.projectName = data.projectName;
 		form.supplierName = data.supplierName;
 		form.entryDate = data.entryDate;
-		form.productData = data.productData;
+		form.enterDate = data.enterDate || dayjs().format("YYYY-MM-DD");
+		
+		// 缂栬緫鏃朵篃闇�瑕佸垵濮嬪寲浜у搧鏁版嵁鐨� tempFutureTickets 鍜� tempFutureTicketsAmount
+		// 鍚屾椂涓烘瘡涓骇鍝佹坊鍔犲悎鍚屽彿绛変俊鎭�
+		const contractNumber = data.purchaseContractNumber || data.purchaseLedgerNo || "";
+		if (data.productData && Array.isArray(data.productData)) {
+			data.productData.forEach(item => {
+				// 淇濆瓨"鍘熷鏈潵绁ㄦ暟/閲戦"锛堢敤浜庢牎楠屼笌璁$畻锛�
+				// 浼樺厛浣跨敤鍚庣杩斿洖鐨� futureTickets/futureTicketsAmount锛涙病鏈夊垯鍥為��鍒� quantity/taxInclusiveTotalPrice
+				item.tempFutureTickets = Number(
+					item.futureTickets !== undefined ? item.futureTickets : (item.quantity || 0)
+				);
+				item.tempFutureTicketsAmount = Number(
+					item.futureTicketsAmount !== undefined ? item.futureTicketsAmount : (item.taxInclusiveTotalPrice || 0)
+				);
+				
+				// 纭繚姣忎釜浜у搧閮芥湁鍚堝悓鍙凤紝鐢ㄤ簬鏄剧ず鍦�"鎵�灞炲悎鍚�"鍒�
+				if (!item.purchaseLedgerNo) {
+					item.purchaseLedgerNo = contractNumber;
+				}
+			});
+		}
+		
+		form.productData = data.productData || [];
+		
+		// 缂栬緫妯″紡涓嬶紝鏍规嵁浜у搧鏁版嵁涓殑鏈寮�绁ㄩ噾棰濊嚜鍔ㄨ绠楀彂绁ㄩ噾棰�
+		calculateinvoiceAmount();
 	}
 };
 // 瀛愯〃鍚堣鏂规硶
@@ -515,22 +562,45 @@
 	form.invoiceAmount = Number(invoiceAmountTotal.toFixed(2));
 };
 
-const open = async (type, selectedRows) => {
-	visible.value = true;
+// 鍒ゆ柇浜у搧鏄惁鍙互缁х画鏉ョエ鎿嶄綔锛氬鏋滄湭鏉ョエ鏁板拰鏈潵绁ㄩ噾棰濋兘涓�0鎴栧皬浜庣瓑浜�0锛屽垯绂佺敤
+const isProductDisabled = (row) => {
+	// 浼樺厛浣跨敤 tempFutureTickets锛堝師濮嬫湭鏉ョエ鏁帮級锛屽鏋滄病鏈夊垯浣跨敤 futureTickets
+	const futureTickets = Number(row.tempFutureTickets !== undefined 
+		? row.tempFutureTickets 
+		: (row.futureTickets !== undefined ? row.futureTickets : 0));
 	
-	// 濡傛灉鏄壒閲忔搷浣滐紝璁剧疆鏍囬
-	if (Array.isArray(selectedRows) && selectedRows.length > 1) {
-		modalOptions.value = {
-			...(modalOptions.value || {}),
-			title: `鎵归噺鏂板 (${selectedRows.length}鏉�)`,
-		};
-	} else {
-		modalOptions.value = {
-			...(modalOptions.value || {}),
-			title: type === "add" ? "鏂板" : "缂栬緫",
-		};
+	// 浼樺厛浣跨敤 tempFutureTicketsAmount锛堝師濮嬫湭鏉ョエ閲戦锛夛紝濡傛灉娌℃湁鍒欎娇鐢� futureTicketsAmount
+	const futureAmount = Number(row.tempFutureTicketsAmount !== undefined 
+		? row.tempFutureTicketsAmount 
+		: (row.futureTicketsAmount !== undefined ? row.futureTicketsAmount : 0));
+	
+	// 鍙湁褰撴湭鏉ョエ鏁板拰鏈潵绁ㄩ噾棰濋兘涓�0鎴栧皬浜庣瓑浜�0鏃讹紝鎵嶇鐢�
+	return futureTickets <= 0 && futureAmount <= 0;
+};
+
+const open = async (type, selectedRows) => {
+	// 纭繚 modalOptions.value 鏄璞�
+	if (!modalOptions.value || typeof modalOptions.value !== 'object') {
+		modalOptions.value = {};
 	}
 	
+	// 鏍规嵁鎿嶄綔绫诲瀷鍜岄�変腑鏁版嵁璁剧疆鏍囬
+	if (Array.isArray(selectedRows) && selectedRows.length > 1) {
+		// 鎵归噺鎿嶄綔
+		modalOptions.value.title = type === "add" ? `鎵归噺鏂板 (${selectedRows.length}鏉�)` : `鎵归噺缂栬緫 (${selectedRows.length}鏉�)`;
+	} else {
+		// 鍗曚釜鎿嶄綔 - 鏄庣‘鍒ゆ柇 type 鐨勫��
+		if (type === "add" || type === "鏂板") {
+			modalOptions.value.title = "鏂板";
+		} else if (type === "edit" || type === "缂栬緫") {
+			modalOptions.value.title = "缂栬緫";
+		} else {
+			modalOptions.value.title = "鏉ョエ鐧昏"; // 榛樿鏍囬
+		}
+	}
+	
+	visible.value = true;
+	
 	// 濡傛灉鏄崟涓搷浣滐紝鑾峰彇id
 	if (!Array.isArray(selectedRows) || selectedRows.length === 1) {
 		const idValue = Array.isArray(selectedRows) ? selectedRows[0].id : selectedRows;
diff --git a/src/views/procurementManagement/invoiceEntry/index.vue b/src/views/procurementManagement/invoiceEntry/index.vue
index 00a6881..8c435e0 100644
--- a/src/views/procurementManagement/invoiceEntry/index.vue
+++ b/src/views/procurementManagement/invoiceEntry/index.vue
@@ -39,7 +39,7 @@
         <div></div>
         <div>
           <el-button @click="handleExport" style="margin-right: 10px">瀵煎嚭</el-button>
-          <el-button type="primary" @click="handleAdd('add')">
+          <el-button type="primary" @click="handleAdd('add')" :disabled="isInvoiceDisabled">
             鏉ョエ鐧昏
           </el-button>
 <!--          <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>-->
@@ -84,7 +84,7 @@
 <script setup>
 import { usePaginationApi } from "@/hooks/usePaginationApi";
 import {delRegistration, gePurchaseListPage} from "@/api/procurementManagement/invoiceEntry.js";
-import { nextTick, onMounted, getCurrentInstance, ref } from "vue";
+import { nextTick, onMounted, getCurrentInstance, ref, computed } from "vue";
 import ExpandTable from "./components/ExpandTable.vue";
 import Modal from "./components/Modal.vue";
 import {ElMessageBox} from "element-plus";
@@ -186,6 +186,18 @@
   );
 };
 
+// 璁$畻鏄惁鍙互鏉ョエ鐧昏锛氬鏋滄墍鏈夐�変腑琛岀殑寰呮潵绁ㄩ噾棰濋兘涓�0锛屽垯绂佺敤鎸夐挳
+const isInvoiceDisabled = computed(() => {
+  if (selectedRows.value.length === 0) {
+    return true;
+  }
+  // 濡傛灉鎵�鏈夐�変腑琛岀殑寰呮潵绁ㄩ噾棰濋兘涓�0鎴栧皬浜庣瓑浜�0锛屽垯绂佺敤
+  return selectedRows.value.every(row => {
+    const amount = parseFloat(row.unReceiptPaymentAmount || 0);
+    return amount <= 0;
+  });
+});
+
 const handleAdd = (type) => {
 	if (selectedRows.value.length < 1) {
 		proxy.$modal.msgWarning("璇疯嚦灏戦�変腑涓�鏉℃暟鎹�");

--
Gitblit v1.9.3