From ccd67e291e00a2ad9c29ad8df43de6fab5a4afed Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期四, 09 四月 2026 09:30:08 +0800
Subject: [PATCH] feat(协同审批/报价单): 添加附件上传、预览和下载功能

---
 src/views/salesManagement/salesLedger/index.vue |  225 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 202 insertions(+), 23 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index d9a180f..a3b8304 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -37,7 +37,7 @@
         </div>
       </div>
       <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
-        :expand-row-keys="expandedRowKeys" :row-key="(row) => row.id" show-summary style="width: 100%"
+        :expand-row-keys="expandedRowKeys" :row-key="(row) => row.id" :row-class-name="tableRowClassName" show-summary style="width: 100%"
         :summary-method="summarizeMainTable" @expand-change="expandChange" height="calc(100vh - 18.5em)">
         <el-table-column align="center" type="selection" width="55" fixed="left"/>
         <el-table-column type="expand" width="60" fixed="left">
@@ -51,7 +51,9 @@
 															 width="100px"
 															 align="center">
                 <template #default="scope">
-									<el-tag v-if="scope.row.approveStatus === 1"
+					<el-tag v-if="getShippingStatusText(scope.row) === '宸插彂璐�'"
+													type="success">宸插嚭搴�</el-tag>
+									<el-tag v-else-if="scope.row.hasSufficientStock"
 													type="success">鍏呰冻</el-tag>
 									<el-tag v-else
 													type="danger">涓嶈冻</el-tag>
@@ -117,9 +119,12 @@
         <el-table-column label="褰曞叆浜�" prop="entryPersonName" width="100" show-overflow-tooltip />
         <el-table-column label="褰曞叆鏃ユ湡" prop="entryDate" width="120" show-overflow-tooltip />
         <el-table-column label="绛捐鏃ユ湡" prop="executionDate" width="120" show-overflow-tooltip />
-        <el-table-column fixed="right" label="鎿嶄綔" min-width="100" align="center">
+        <el-table-column label="浜や粯鏃ユ湡" prop="deliveryDate" width="120" show-overflow-tooltip />
+        <el-table-column label="鍏跺畠璇存槑浜嬮」" prop="remarks" width="200" show-overflow-tooltip />
+        <el-table-column fixed="right" label="鎿嶄綔" min-width="200" align="center">
           <template #default="scope">
-            <el-button link type="primary" size="small" @click="openForm('edit', scope.row)">缂栬緫</el-button>
+            <el-button link type="primary" size="small" @click="openForm('edit', scope.row)" :disabled="!scope.row.isEdit">缂栬緫</el-button>
+			<el-button link type="primary" size="small" @click="exportSalesContracts(scope.row)">瀵煎嚭閿�鍞悎鍚�</el-button>
 <!--            <el-button link type="primary" size="small" @click="openForm('view', scope.row)">璇︽儏</el-button>-->
             <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">闄勪欢</el-button>
 <!--            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">鍙戣揣</el-button>-->
@@ -132,6 +137,14 @@
     <FormDialog v-model="dialogFormVisible" :title="operationType === 'add' ? '鏂板閿�鍞彴璐﹂〉闈�' : '缂栬緫閿�鍞彴璐﹂〉闈�'" :width="'70%'"
       :operation-type="operationType" @close="closeDia" @confirm="submitForm" @cancel="closeDia">
       <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
+				<!-- 鎶ヤ环鍗曞鍏ュ叆鍙o細鏀惧湪琛ㄥ崟椤堕儴锛岄�夋嫨鍚庡弽鏄惧鎴�/涓氬姟鍛樼瓑 -->
+				<el-row v-if="operationType === 'add'" style="margin-bottom: 10px;">
+					<el-col :span="24" style="text-align: right;">
+						<el-button type="primary" plain @click="openQuotationDialog">
+							浠庨攢鍞姤浠峰鍏�
+						</el-button>
+					</el-col>
+				</el-row>
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="閿�鍞悎鍚屽彿锛�" prop="salesContractNo">
@@ -196,6 +209,19 @@
 						</el-form-item>
 					</el-col>
 				</el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <el-form-item label="浜よ揣鏃ユ湡锛�" prop="entryDate">
+              <el-date-picker style="width: 100%" v-model="form.deliveryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
+                              type="date" placeholder="璇烽�夋嫨" clearable />
+            </el-form-item>
+          </el-col>
+		  <el-col :span="12">
+            <el-form-item label="绛捐鍦扮偣锛�" prop="placeOfSinging">
+				<el-input v-model="form.placeOfSinging" placeholder="璇疯緭鍏�" clearable :disabled="operationType === 'view'" />
+            </el-form-item>
+          </el-col>
+        </el-row>
 				<el-row>
 					<el-form-item label="浜у搧淇℃伅锛�" prop="entryDate">
 						<el-button v-if="operationType !== 'view'" type="primary" @click="openProductForm('add')">娣诲姞</el-button>
@@ -204,7 +230,8 @@
 				</el-row>
 				<el-table :data="productData" border @selection-change="productSelected" show-summary
 									:summary-method="summarizeMainTable">
-					<el-table-column align="center" type="selection" width="55" v-if="operationType !== 'view'" />
+					<el-table-column align="center" type="selection" width="55" v-if="operationType !== 'view'"
+						:selectable="(row) => !isProductShipped(row)" />
 					<el-table-column align="center" label="搴忓彿" type="index" width="60" />
 					<el-table-column label="浜у搧澶х被" prop="productCategory" />
 					<el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" />
@@ -216,20 +243,22 @@
 					<el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
 					<el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center" v-if="operationType !== 'view'">
 						<template #default="scope">
-							<el-button link type="primary" size="small" @click="openProductForm('edit', scope.row,scope.$index)">缂栬緫</el-button>
+							<el-button link type="primary" size="small" 
+								:disabled="isProductShipped(scope.row)"
+								@click="openProductForm('edit', scope.row,scope.$index)">缂栬緫</el-button>
 						</template>
 					</el-table-column>
 				</el-table>
 				<el-row :gutter="30">
 					<el-col :span="24">
-						<el-form-item label="澶囨敞路锛�" prop="remark">
-							<el-input v-model="form.remark" placeholder="璇疯緭鍏�" clearable type="textarea" :rows="2" :disabled="operationType === 'view'" />
+						<el-form-item label="鍏跺畠璇存槑浜嬮」锛�" prop="remarks">
+							<el-input v-model="form.remarks" placeholder="璇疯緭鍏�" clearable type="textarea" :rows="2" :disabled="operationType === 'view'" />
 						</el-form-item>
 					</el-col>
 				</el-row>
 				<el-row :gutter="30">
 					<el-col :span="24">
-						<el-form-item label="闄勪欢鏉愭枡锛�" prop="remark">
+						<el-form-item label="闄勪欢鏉愭枡锛�" prop="salesLedgerFiles">
 							<el-upload v-model:file-list="fileList" :action="upload.url" multiple ref="fileUpload" auto-upload
 												 :headers="upload.headers" :before-upload="handleBeforeUpload" :on-error="handleUploadError"
 												 :on-success="handleUploadSuccess" :on-remove="handleRemove">
@@ -297,6 +326,15 @@
 					</template>
 				</el-table-column>
 			</el-table>
+			
+			<pagination
+				v-show="quotationPage.total > 0"
+				:total="quotationPage.total"
+				layout="total, sizes, prev, pager, next, jumper"
+				:page="quotationPage.current"
+				:limit="quotationPage.size"
+				@pagination="quotationPaginationChange"
+			/>
 			
 			<template #footer>
 				<el-button @click="quotationDialogVisible = false">鍏抽棴</el-button>
@@ -451,7 +489,7 @@
 					<div v-for="(item, index) in printData" :key="index" class="print-page">
 						<div class="delivery-note">
 							<div class="header">
-								<div class="company-name">榧庤瘹鐟炲疄涓氭湁闄愯矗浠诲叕鍙�</div>
+								<div class="company-name">闃冲厜鍗板埛鏈夐檺璐d换鍏徃</div>
 								<div class="document-title">闆跺敭鍙戣揣鍗�</div>
 							</div>
 							
@@ -645,6 +683,7 @@
 	addOrUpdateSalesLedgerProduct,
 	delProduct,
 	delLedgerFile, getProductInventory,
+	exportSalesContract
 } from "@/api/salesManagement/salesLedger.js";
 import { modelList, productTreeList } from "@/api/basicData/product.js";
 import useFormData from "@/hooks/useFormData.js";
@@ -686,6 +725,7 @@
 		customerId: "",
 		entryPerson: "",
 		entryDate: "",
+    deliveryDate: "",
 		maintenanceTime: "",
 		productData: [],
 		executionDate: "",
@@ -695,7 +735,9 @@
 		customerId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
 		entryPerson: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
 		entryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+    deliveryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
 		executionDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+		placeOfSinging: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
 	},
 });
 const { form, rules } = toRefs(data);
@@ -757,6 +799,12 @@
 const quotationSearchForm = reactive({
 	quotationNo: "",
 	customer: "",
+});
+// 鎶ヤ环鍗曞脊妗嗗垎椤�
+const quotationPage = reactive({
+	current: 1,
+	size: 10,
+	total: 0,
 });
 const selectedQuotation = ref(null);
 
@@ -979,6 +1027,23 @@
 		expandedRowKeys.value = [];
 	}
 };
+
+// 娣诲姞琛ㄨ绫诲悕鏂规硶
+const tableRowClassName = ({ row }) => {
+  if (!row.deliveryDate) return '';
+  if (row.isFh) return '';
+
+  const diff = row.deliveryDaysDiff;
+  if (diff === 15) {
+    return 'yellow';
+  } else if (diff === 10) {
+    return 'pink';
+  } else if (diff === 2) {
+    return 'purple';
+  } else if (diff < 2) {
+    return 'red';
+  }
+};
 // 涓昏〃鍚堣鏂规硶
 const summarizeMainTable = (param) => {
 	return proxy.summarizeTable(param, [
@@ -1035,6 +1100,8 @@
 const openQuotationDialog = async () => {
 	if (operationType.value === "view") return;
 	quotationDialogVisible.value = true;
+	// 鎵撳紑寮圭獥鏃堕噸缃垎椤靛埌绗竴椤�
+	quotationPage.current = 1;
 	// 鍏堢‘淇濆鎴峰垪琛ㄥ凡鍔犺浇锛屼究浜庡悗缁洖濉� customerId
 	if (!customerOption.value || customerOption.value.length === 0) {
 		try {
@@ -1051,14 +1118,15 @@
 	quotationLoading.value = true;
 	try {
 		const params = {
-			// 鍏煎鍚庣鍒嗛〉瀛楁锛氳繖閲屾部鐢ㄦ姤浠烽〉闈㈠凡鏈夊彲鐢ㄧ殑瀛楁鍛藉悕
-			currentPage: 1,
-			pageSize: 100,
+			// 鍚庣鍒嗛〉瀛楁锛歝urrent / size
+			current: quotationPage.current,
+			size: quotationPage.size,
 			...quotationSearchForm,
 			status: "閫氳繃",
 		};
 		const res = await getQuotationList(params);
 		quotationList.value = res?.data?.records || [];
+		quotationPage.total = res?.data?.total || 0;
 	} finally {
 		quotationLoading.value = false;
 	}
@@ -1067,7 +1135,15 @@
 const resetQuotationSearch = async () => {
 	quotationSearchForm.quotationNo = "";
 	quotationSearchForm.customer = "";
+	quotationPage.current = 1;
 	await fetchQuotationList();
+};
+
+// 鎶ヤ环鍗曞脊妗嗗垎椤靛垏鎹�
+const quotationPaginationChange = (obj) => {
+	quotationPage.current = obj.page;
+	quotationPage.size = obj.limit;
+	fetchQuotationList();
 };
 
 // 閫変腑鎶ヤ环鍗曞悗鍥炲~鍒板彴璐﹁〃鍗�
@@ -1076,10 +1152,14 @@
 	selectedQuotation.value = row;
 	
 	// 涓氬姟鍛�
-	form.value.salesman = row.salesperson || "";
+	form.value.salesman = (row.salesperson || "").trim();
 	
 	// 瀹㈡埛鍚嶇О -> customerId
-	const customer = (customerOption.value || []).find((c) => c.customerName === row.customer);
+	const qCustomerName = String(row.customer || "").trim();
+	const customer = (customerOption.value || []).find((c) => {
+		const name = String(c.customerName || "").trim();
+		return name === qCustomerName || name.includes(qCustomerName) || qCustomerName.includes(name);
+	});
 	if (customer?.id) {
 		form.value.customerId = customer.id;
 	} else {
@@ -1184,6 +1264,12 @@
 const productIndex = ref(0);
 // 鎵撳紑浜у搧寮规
 const openProductForm = async (type, row, index) => {
+	// 缂栬緫鏃舵鏌ヤ骇鍝佹槸鍚﹀凡鍙戣揣鎴栧鏍搁�氳繃
+	if (type === "edit" && isProductShipped(row)) {
+		proxy.$modal.msgWarning("宸插彂璐ф垨瀹℃牳閫氳繃鐨勪骇鍝佷笉鑳界紪杈�");
+		return;
+	}
+	
 	productOperationType.value = type;
 	productForm.value = {};
 	proxy.resetForm("productFormRef");
@@ -1250,6 +1336,14 @@
 		proxy.$modal.msgWarning("璇烽�夋嫨鏁版嵁");
 		return;
 	}
+	
+	// 妫�鏌ユ槸鍚︽湁宸插彂璐ф垨瀹℃牳閫氳繃鐨勪骇鍝�
+	const shippedProducts = productSelectedRows.value.filter(row => isProductShipped(row));
+	if (shippedProducts.length > 0) {
+		proxy.$modal.msgWarning("宸插彂璐ф垨瀹℃牳閫氳繃鐨勪骇鍝佷笉鑳藉垹闄�");
+		return;
+	}
+	
 	if (operationType.value === "add") {
 		productSelectedRows.value.forEach((selectedRow) => {
 			const index = productData.value.findIndex(
@@ -1324,15 +1418,56 @@
 			proxy.$modal.msg("宸插彇娑�");
 		});
 };
+/** 鍒ゆ柇鍗曚釜浜у搧鏄惁宸插彂璐э紙鏍规嵁shippingStatus鍒ゆ柇锛屽凡鍙戣揣鎴栧鏍搁�氳繃涓嶅彲缂栬緫鍜屽垹闄わ級 */
+const isProductShipped = (product) => {
+	if (!product) return false;
+	
+	const status = String(product.shippingStatus || "").trim();
+	// 濡傛灉鍙戣揣鐘舵�佹槸"宸插彂璐�"鎴�"瀹℃牳閫氳繃"锛屽垯涓嶅彲缂栬緫鍜屽垹闄�
+	return status === "宸插彂璐�" || status === "瀹℃牳閫氳繃";
+};
+
+/** 鍒ゆ柇閿�鍞鍗曚笅鏄惁瀛樺湪宸插彂璐�/鍙戣揣瀹屾垚鐨勪骇鍝侊紙涓嶅彲鍒犻櫎锛� */
+const hasShippedProducts = (products) => {
+	if (!products || !products.length) return false;
+	return products.some((p) => {
+		const status = String(p.shippingStatus || "").trim();
+		// 鏈夊彂璐ф棩鏈熸垨杞︾墝鍙疯涓哄凡鍙戣揣
+		if (p.shippingDate || p.shippingCarNumber) return true;
+		// 宸茶繘琛屽彂璐с�佸彂璐у畬鎴愩�佸凡鍙戣揣 鍧囦笉鍙垹闄�
+		return status === "宸茶繘琛屽彂璐�" || status === "鍙戣揣瀹屾垚" || status === "宸插彂璐�";
+	});
+};
+
 // 鍒犻櫎
-const handleDelete = () => {
-	let ids = [];
-	if (selectedRows.value.length > 0) {
-		ids = selectedRows.value.map((item) => item.id);
-	} else {
+const handleDelete = async () => {
+	if (selectedRows.value.length === 0) {
 		proxy.$modal.msgWarning("璇烽�夋嫨鏁版嵁");
 		return;
 	}
+	const ids = selectedRows.value.map((item) => item.id);
+
+	// 妫�鏌ユ槸鍚︽湁宸茶繘琛屽彂璐ф垨鍙戣揣瀹屾垚鐨勯攢鍞鍗曪紝鑻ユ湁鍒欎笉鍏佽鍒犻櫎
+	const cannotDeleteNames = [];
+	for (const row of selectedRows.value) {
+		let products = row.children && row.children.length > 0 ? row.children : null;
+		if (!products) {
+			try {
+				const res = await productList({ salesLedgerId: row.id, type: 1 });
+				products = res.data || [];
+			} catch {
+				products = [];
+			}
+		}
+		if (hasShippedProducts(products)) {
+			cannotDeleteNames.push(row.salesContractNo || `ID:${row.id}`);
+		}
+	}
+	if (cannotDeleteNames.length > 0) {
+		proxy.$modal.msgWarning("宸茶繘琛屽彂璐ф垨鍙戣揣瀹屾垚鐨勯攢鍞鍗曚笉鑳藉垹闄わ細" + cannotDeleteNames.join("銆�"));
+		return;
+	}
+
 	ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚垹闄わ紝鏄惁纭鍒犻櫎锛�", "瀵煎嚭", {
 		confirmButtonText: "纭",
 		cancelButtonText: "鍙栨秷",
@@ -1546,7 +1681,7 @@
       <div class="print-page">
         <div class="delivery-note">
           <div class="header">
-            <div class="company-name">榧庤瘹鐟炲疄涓氭湁闄愯矗浠诲叕鍙�</div>
+            <div class="company-name">闃冲厜褰╁嵃鏈夐檺璐d换鍏徃</div>
             <div class="document-title">闆跺敭鍙戣揣鍗�</div>
           </div>
           
@@ -1949,8 +2084,8 @@
  * @param row 琛屾暟鎹�
  */
 const canShip = (row) => {
-	// 浜у搧鐘舵�佸繀椤绘槸鍏呰冻锛坅pproveStatus === 1锛�
-	if (row.approveStatus !== 1) {
+	// 浜у搧鐘舵�佸繀椤绘槸鍏呰冻锛堝熀浜� hasSufficientStock 鍒ゆ柇锛�
+	if (!row || !row.hasSufficientStock) {
 		return false;
 	}
 	
@@ -1966,6 +2101,34 @@
 	const statusStr = shippingStatus ? String(shippingStatus).trim() : '';
 	return statusStr === '寰呭彂璐�' || statusStr === '瀹℃牳鎷掔粷';
 };
+
+/**
+ * 瀵煎嚭閿�鍞悎鍚�
+ *
+ * @param row 瀵煎嚭閿�鍞悎鍚岀殑鐩稿叧淇℃伅瀵硅薄
+ */
+const exportSalesContracts = (row) => {
+	exportSalesContract({ id: row.id }).then((res) => {
+		if (res) {
+			const downloadUrl = window.URL.createObjectURL(res);
+      const link = document.createElement('a');
+      link.href = downloadUrl;
+	  console.log(row.executionDate)
+      link.download = row.projectName+row.executionDate + "閿�鍞悎鍚�.docx"; // 璁剧疆涓嬭浇鏂囦欢鍚�
+      link.style.display = 'none'; // 闅愯棌a鏍囩
+      document.body.appendChild(link);
+      link.click(); // 瑙﹀彂鐐瑰嚮涓嬭浇
+      // 4. 娓呯悊璧勬簮锛堥伩鍏嶅唴瀛樻硠婕忥級
+      document.body.removeChild(link);
+      window.URL.revokeObjectURL(downloadUrl);
+
+      // 5. 鎻愮ず瀵煎嚭鎴愬姛
+      proxy.$modal.msgSuccess("瀵煎嚭閿�鍞悎鍚屾垚鍔�");
+		} else {
+			proxy.$modal.msgError(res.msg || "瀵煎嚭閿�鍞悎鍚屽け璐�");
+		}
+	});
+}
 
 /**
  * 涓嬭浇鏂囦欢
@@ -2072,6 +2235,22 @@
 	margin-left: 10px;
 }
 
+::v-deep .yellow {
+  background-color: #FAF0DE;
+}
+
+::v-deep .pink {
+  background-color: #FAE1DE;
+}
+
+::v-deep .red {
+  background-color: #FAE1DE;
+}
+
+::v-deep .purple{
+  background-color: #F4DEFA;
+}
+
 .table_list {
 	margin-top: unset;
 }

--
Gitblit v1.9.3