From fa4a8a332b2b60b7b94b1f763091c1daf8927710 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期三, 22 四月 2026 14:18:35 +0800
Subject: [PATCH] 优化选择数据逻辑,仅保留具有子项的行以便于删除操作

---
 src/views/salesManagement/invoiceRegistration/index.vue |  133 +++++++++++++++++++++++++++++++++----------
 1 files changed, 101 insertions(+), 32 deletions(-)

diff --git a/src/views/salesManagement/invoiceRegistration/index.vue b/src/views/salesManagement/invoiceRegistration/index.vue
index 2cf92a8..8990f31 100644
--- a/src/views/salesManagement/invoiceRegistration/index.vue
+++ b/src/views/salesManagement/invoiceRegistration/index.vue
@@ -30,7 +30,12 @@
 			<div class="flex justify-between">
 				<div></div>
 				<div>
-					<el-button type="primary" @click="openForm" style="margin-bottom: 8px">
+					<el-button 
+						type="primary" 
+						@click="openForm" 
+						style="margin-bottom: 8px"
+						:disabled="!canInvoice"
+					>
 						寮�绁ㄧ櫥璁�
 					</el-button>
 				</div>
@@ -296,10 +301,14 @@
 					/>
 					<el-table-column label="鏈寮�绁ㄦ暟" prop="currentInvoiceNum" width="180">
 						<template #default="scope">
-							<el-input-number :step="0.1" :min="0" style="width: 100%"
-															 :precision="2"
-															 v-model="scope.row.currentInvoiceNum"
-															 @change="invoiceNumBlur(scope.row)"
+							<el-input-number 
+								:step="0.1" 
+								:min="0" 
+								style="width: 100%"
+								:precision="2"
+								v-model="scope.row.currentInvoiceNum"
+								@change="invoiceNumBlur(scope.row)"
+								:disabled="isProductInvoiceDisabled(scope.row)"
 							></el-input-number>
 						</template>
 					</el-table-column>
@@ -309,10 +318,14 @@
 						width="180"
 					>
 						<template #default="scope">
-							<el-input-number :step="0.01" :min="0" style="width: 100%"
-															 :precision="2"
-															 v-model="scope.row.currentInvoiceAmount"
-															 @change="invoiceAmountBlur(scope.row)"
+							<el-input-number 
+								:step="0.01" 
+								:min="0" 
+								style="width: 100%"
+								:precision="2"
+								v-model="scope.row.currentInvoiceAmount"
+								@change="invoiceAmountBlur(scope.row)"
+								:disabled="isProductInvoiceDisabled(scope.row)"
 							></el-input-number>
 						</template>
 					</el-table-column>
@@ -375,7 +388,7 @@
 <script setup>
 import pagination from "@/components/PIMTable/Pagination.vue";
 import FormDialog from '@/components/Dialog/FormDialog.vue';
-import { onMounted, ref } from "vue";
+import { onMounted, ref, computed } from "vue";
 import { Search } from "@element-plus/icons-vue";
 import { ElMessageBox } from "element-plus";
 // import {userListNoPage} from "@/api/system/user.js";
@@ -450,6 +463,27 @@
 
 const formattedInputNumber = (value) => {
 	return value ? parseFloat(value).toFixed(2) : 0;
+};
+
+// 鍒ゆ柇鏄惁鍙互寮�绁紙鍩轰簬閫変腑鐨勫彴璐︽暟鎹級
+const canInvoice = computed(() => {
+	if (selectedRows.value.length === 0) {
+		return false;
+	}
+	// 妫�鏌ユ墍鏈夐�変腑鐨勫彴璐︼紝鍙鏈変竴涓湭寮�绁ㄩ噾棰濆ぇ浜�0锛屽氨鍙互寮�绁�
+	return selectedRows.value.some(row => {
+		const noInvoiceAmount = parseFloat(row.noInvoiceAmountTotal || 0);
+		return noInvoiceAmount > 0;
+	});
+});
+
+// 鍒ゆ柇鍗曚釜浜у搧鏄惁鍙互寮�绁�
+const isProductInvoiceDisabled = (row) => {
+	// 妫�鏌ユ湭寮�绁ㄩ噾棰濆拰鏈紑绁ㄦ暟锛屽鏋滈兘涓�0鎴栧皬浜庣瓑浜�0锛屽垯绂佺敤
+	// 浼樺厛浣跨敤 tempnoInvoiceAmount 鍜� tempNoInvoiceNum锛堝垵濮嬪�硷級锛屽鏋滄病鏈夊垯浣跨敤 noInvoiceAmount 鍜� originalNoInvoiceNum
+	const noInvoiceAmount = parseFloat(row.tempnoInvoiceAmount || row.noInvoiceAmount || 0);
+	const noInvoiceNum = parseFloat(row.tempNoInvoiceNum || row.originalNoInvoiceNum || row.noInvoiceNum || 0);
+	return noInvoiceAmount <= 0 || noInvoiceNum <= 0;
 };
 
 // 鏌ヨ鍒楄〃
@@ -555,12 +589,12 @@
 		const allProductData = [];
 		results.forEach((result, index) => {
 			const contract = selectedRows.value[index];
-			const contractId = contract.id;
+			// const contractId = contract.id;
 			if (result.productData) {
 				result.productData.forEach(item => {
 					allProductData.push({
 						...item,
-						id: contractId, // 鏄庣‘璁剧疆鍚堝悓ID
+						// id: contractId, // 鏄庣‘璁剧疆鍚堝悓ID
 						salesContractNo: contract.salesContractNo, // 娣诲姞閿�鍞悎鍚屽彿
 						customerName: contract.customerName, // 娣诲姞瀹㈡埛鍚嶇О
 						customerContractNo: contract.customerContractNo // 娣诲姞瀹㈡埛鍚堝悓鍙�
@@ -578,6 +612,14 @@
 		form.value.salesContractNo = ""; // 閿�鍞悎鍚屽彿鐣欑┖锛屽洜涓轰細鍦ㄤ骇鍝佽〃鏍间腑鍒嗗埆鏄剧ず
 		
 		productData.value = allProductData;
+		
+		// 瀵逛簬涓嶈兘寮�绁ㄧ殑浜у搧锛屽皢寮�绁ㄦ暟鍜屽紑绁ㄩ噾棰濊缃负0
+		productData.value.forEach(item => {
+			if (isProductInvoiceDisabled(item)) {
+				item.currentInvoiceNum = 0;
+				item.currentInvoiceAmount = 0;
+			}
+		});
 		
 		dialogFormVisible.value = true;
 		console.log("productData.value ", productData.value);
@@ -699,51 +741,78 @@
 };
 
 //鏈寮�绁ㄥけ鐒︽搷浣�
+const getInvoiceCalcUnitPrice = (row) => {
+	const baseNoInvoiceNum = parseFloat(
+		row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
+	);
+	const baseNoInvoiceAmount = parseFloat(
+		row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
+	);
+	if (!baseNoInvoiceNum) {
+		return 0;
+	}
+	return baseNoInvoiceAmount / baseNoInvoiceNum;
+};
+
 const invoiceNumBlur = (row) => {
 	if (!row.currentInvoiceNum) {
 		row.currentInvoiceNum = 0;
 	}
-	if (row.currentInvoiceNum > row.tempNoInvoiceNum) {
+	const baseNoInvoiceNum = parseFloat(
+		row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
+	);
+	const baseNoInvoiceAmount = parseFloat(
+		row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
+	);
+	const unitPrice = getInvoiceCalcUnitPrice(row);
+	if (!unitPrice) {
+		row.currentInvoiceAmount = 0;
+		row.noInvoiceNum = Number(baseNoInvoiceNum).toFixed(2);
+		row.noInvoiceAmount = Number(baseNoInvoiceAmount).toFixed(2);
+		return;
+	}
+	if (row.currentInvoiceNum > baseNoInvoiceNum) {
 		proxy.$modal.msgWarning("鏈寮�绁ㄦ暟涓嶅緱澶т簬鏈紑绁ㄦ暟");
 		row.currentInvoiceNum = 0;
 	}
 	// 璁$畻鏈寮�绁ㄩ噾棰�
-	row.currentInvoiceAmount = (
-		row.currentInvoiceNum * row.taxInclusiveUnitPrice
-	).toFixed(2);
+	row.currentInvoiceAmount = (row.currentInvoiceNum * unitPrice).toFixed(2);
 	// 璁$畻鏈紑绁ㄦ暟
-	row.noInvoiceNum = (row.originalNoInvoiceNum - row.currentInvoiceNum).toFixed(
-		2
-	);
+	row.noInvoiceNum = (baseNoInvoiceNum - row.currentInvoiceNum).toFixed(2);
 	// 璁$畻鏈紑绁ㄩ噾棰�
-	row.noInvoiceAmount = (
-		row.tempnoInvoiceAmount - row.currentInvoiceAmount
-	).toFixed(2);
+	row.noInvoiceAmount = (row.noInvoiceNum * unitPrice).toFixed(2);
 };
 // 鏈寮�绁ㄩ噾棰濆け鐒︽搷浣�
 const invoiceAmountBlur = (row) => {
 	if (!row.currentInvoiceAmount) {
 		row.currentInvoiceAmount = 0;
 	}
+	const baseNoInvoiceNum = parseFloat(
+		row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
+	);
+	const baseNoInvoiceAmount = parseFloat(
+		row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
+	);
+	const unitPrice = getInvoiceCalcUnitPrice(row);
+	if (!unitPrice) {
+		row.currentInvoiceNum = 0;
+		row.noInvoiceNum = Number(baseNoInvoiceNum).toFixed(2);
+		row.noInvoiceAmount = Number(baseNoInvoiceAmount).toFixed(2);
+		return;
+	}
 	// 璁$畻鏄惁瓒呰繃寮�绁ㄦ�婚噾棰�
-	if (row.currentInvoiceAmount > row.tempnoInvoiceAmount) {
+	if (row.currentInvoiceAmount > baseNoInvoiceAmount) {
 		proxy.$modal.msgWarning("鏈寮�绁ㄩ噾棰濅笉寰楀ぇ浜庢湭寮�绁ㄩ噾棰�");
 		row.currentInvoiceAmount = 0;
 	}
 	// 璁$畻鏈寮�绁ㄦ暟
-	row.currentInvoiceNum = (
-		row.currentInvoiceAmount / row.taxInclusiveUnitPrice
-	).toFixed(2);
+	row.currentInvoiceNum = (row.currentInvoiceAmount / unitPrice).toFixed(2);
 	console.log("row.currentInvoiceNum ", row.currentInvoiceNum);
 	console.log(" row.originalNoInvoiceNum  ", row.originalNoInvoiceNum);
 	// 璁$畻鏈紑绁ㄦ暟
-	row.noInvoiceNum = (row.originalNoInvoiceNum - row.currentInvoiceNum).toFixed(
-		2
-	);
+	row.noInvoiceNum = (baseNoInvoiceNum - row.currentInvoiceNum).toFixed(2);
 	// 璁$畻鏈紑绁ㄩ噾棰�
-	row.noInvoiceAmount = (
-		row.tempnoInvoiceAmount - row.currentInvoiceAmount
-	).toFixed(2);
+	row.noInvoiceAmount = (row.noInvoiceNum * unitPrice).toFixed(2);
 };
 
 onMounted(() => {

--
Gitblit v1.9.3