From ac00bb7b8eae1bf6aabb7f1ae67c2e5aa5b8ae90 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 12 六月 2026 10:21:12 +0800
Subject: [PATCH] 宝东 1.样式问题

---
 src/views/salesManagement/salesLedger/index.vue |  265 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 250 insertions(+), 15 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 8d25f53..37eb815 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -48,6 +48,9 @@
                      @click="openForm('add')">
             鏂板鍙拌处
           </el-button>
+					<el-button type="primary" plain :disabled="selectedRows.length === 0" @click="handleBatchExportContract">
+						瀵煎嚭鍚堝悓
+					</el-button>
           <el-button type="primary"
                      plain
                      @click="handleImport">瀵煎叆
@@ -155,6 +158,10 @@
               </el-table-column>
               <el-table-column label="鏁伴噺"
                                prop="quantity" />
+              <el-table-column label="姣忎欢鏁伴噺"
+                               prop="singleQuantity" />
+              <el-table-column label="鎬绘暟"
+                               prop="totalQuantity" />
               <el-table-column label="寰呭彂璐ф暟閲�"
                                prop="noQuantity" />
               <el-table-column label="绋庣巼(%)"
@@ -240,7 +247,7 @@
             <el-button link
                        type="primary"
                        @click="openForm('edit', scope.row)"
-                       :disabled="!scope.row.isEdit || scope.row.hasProductionRecord || !canEditLedger(scope.row)">缂栬緫
+                       :disabled="!canEditLedger(scope.row)">缂栬緫
             </el-button>
             <el-button link
                        type="primary"
@@ -284,10 +291,15 @@
           <el-col :span="12">
             <el-form-item label="閿�鍞悎鍚屽彿锛�"
                           prop="salesContractNo">
-              <el-input v-model="form.salesContractNo"
-                        placeholder="鑷姩鐢熸垚"
-                        clearable
-                        disabled />
+              <div style="display: flex; align-items: center; gap: 12px;width: 100%;">
+                <el-checkbox v-model="form.autoGenerateContractNo" v-if="operationType === 'add'">鑷姩鐢熸垚
+                </el-checkbox>
+                <el-input v-model="form.salesContractNo"
+                          :placeholder="form.autoGenerateContractNo ? '鑷姩鐢熸垚' : '璇疯緭鍏�'"
+                          clearable
+                          :disabled="form.autoGenerateContractNo" />
+
+              </div>
             </el-form-item>
           </el-col>
           <el-col :span="12">
@@ -440,6 +452,10 @@
                            prop="unit" />
           <el-table-column label="鏁伴噺"
                            prop="quantity" />
+          <el-table-column label="姣忎欢鏁伴噺"
+                           prop="singleQuantity" />
+          <el-table-column label="鎬绘暟"
+                           prop="totalQuantity" />
           <el-table-column label="绋庣巼(%)"
                            prop="taxRate" />
           <el-table-column label="鍚◣鍗曚环(鍏�)"
@@ -676,6 +692,30 @@
         </el-row>
         <el-row :gutter="30">
           <el-col :span="12">
+            <el-form-item label="姣忎欢鏁伴噺锛�"
+                          prop="singleQuantity">
+              <el-input-number :step="1"
+                               :min="1"
+                               v-model="productForm.singleQuantity"
+                               placeholder="璇疯緭鍏�"
+                               clearable
+                               :precision="0"
+                               @change="calculateFromSingleQuantity"
+                               style="width: 100%" />
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="鎬绘暟锛�"
+                          prop="totalQuantity">
+              <el-input v-model="productForm.totalQuantity"
+                        placeholder="鑷姩璁$畻"
+                        disabled
+                        style="width: 100%" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
             <el-form-item label="鍚◣鎬讳环(鍏�)锛�"
                           prop="taxInclusiveTotalPrice">
               <el-input v-model="productForm.taxInclusiveTotalPrice"
@@ -885,7 +925,7 @@
     <!-- 鍙戣揣寮规 -->
     <el-dialog v-model="deliveryFormVisible"
                title="鍙戣揣淇℃伅"
-               width="40%"
+               width="70%"
                @close="closeDeliveryDia">
       <el-form :model="deliveryForm"
                label-width="120px"
@@ -898,7 +938,8 @@
                           prop="type">
               <el-select v-model="deliveryForm.type"
                          placeholder="璇烽�夋嫨鍙戣揣绫诲瀷"
-                         style="width: 100%">
+                         style="width: 100%"
+                         @change="handleDeliveryTypeChange">
                 <el-option label="璐ц溅"
                            value="璐ц溅" />
                 <el-option label="蹇��"
@@ -914,8 +955,43 @@
           </el-col>
         </el-row>
         <el-row :gutter="30">
+          <el-col :span="24" v-if="deliveryForm.type === '璐ц溅'">
+            <el-form-item label="鍙戣揣杞︾墝鍙凤細"
+                          prop="shippingCarNumber">
+              <el-input v-model="deliveryForm.shippingCarNumber"
+                        placeholder="璇疯緭鍏ュ彂璐ц溅鐗屽彿"
+                        clearable />
+            </el-form-item>
+          </el-col>
+          <el-col :span="24" v-else>
+            <el-form-item label="蹇�掑叕鍙革細"
+                          prop="expressCompany">
+              <el-input v-model="deliveryForm.expressCompany"
+                        placeholder="璇疯緭鍏ュ揩閫掑叕鍙�"
+                        clearable />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30" v-if="deliveryForm.type === '蹇��'">
           <el-col :span="24">
-            <el-form-item label="鎵瑰彿锛�"
+            <el-form-item label="蹇�掑崟鍙凤細"
+                          prop="expressNumber">
+              <el-input v-model="deliveryForm.expressNumber"
+                        placeholder="璇疯緭鍏ュ揩閫掑崟鍙�"
+                        clearable />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="24">
+            <el-form-item label="鍙戣揣鍥剧墖锛�">
+              <ImageUpload v-model:file-list="deliveryFileList" :limit="9" />
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="24">
+            <el-form-item label="搴撳瓨锛�"
                           prop="batchNo">
               <el-table :data="deliveryForm.batchNoList"
                         border
@@ -925,6 +1001,15 @@
                 <el-table-column label="鎵瑰彿"
                                  prop="batchNo"
                                  min-width="180" />
+                <el-table-column label="浜у搧澶х被"
+                                 prop="productName"
+                                 min-width="100" />
+                <el-table-column label="瑙勬牸鍨嬪彿"
+                                 prop="model"
+                                 min-width="100" />
+                <el-table-column label="鍗曚綅"
+                                 prop="unit"
+                                 min-width="100" />
                 <el-table-column label="搴撳瓨鏁伴噺"
                                  min-width="120"
                                  align="center">
@@ -990,6 +1075,7 @@
   import useFormData from "@/hooks/useFormData.js";
   import dayjs from "dayjs";
   import FileUpload from "@/components/AttachmentUpload/file/index.vue";
+  import ImageUpload from "@/components/AttachmentUpload/image/index.vue";
   import { getCurrentDate } from "@/utils/index.js";
   import { listCustomer } from "@/api/basicData/customer.js";
 
@@ -1017,6 +1103,7 @@
   });
   const total = ref(0);
   const fileList = ref([]);
+  const deliveryFileList = ref([]);
 
   // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁
   const operationType = ref("");
@@ -1031,6 +1118,7 @@
     },
     form: {
       salesContractNo: "",
+      autoGenerateContractNo: true,
       salesman: "",
       customerId: "",
       entryPerson: "",
@@ -1039,7 +1127,6 @@
       maintenanceTime: "",
       productData: [],
       executionDate: "",
-      hasProductionRecord: false,
     },
     rules: {
       salesman: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
@@ -1062,6 +1149,8 @@
       specificationModel: "",
       unit: "",
       quantity: "",
+      singleQuantity: 1,
+      totalQuantity: "",
       taxInclusiveUnitPrice: "",
       taxRate: "",
       taxInclusiveTotalPrice: "",
@@ -1195,11 +1284,30 @@
         deliveryQuantity: 0,
       }));
   };
+  const validateDeliveryShippingCarNumber = (_rule, value, callback) => {
+    if (deliveryForm.value.type === "璐ц溅" && !value) {
+      return callback(new Error("璇疯緭鍏ュ彂璐ц溅鐗屽彿"));
+    }
+    callback();
+  };
+  const validateDeliveryExpressCompany = (_rule, value, callback) => {
+    if (deliveryForm.value.type === "蹇��" && !value) {
+      return callback(new Error("璇疯緭鍏ュ揩閫掑叕鍙�"));
+    }
+    callback();
+  };
   const deliveryFormData = reactive({
     deliveryForm: {
+      shippingCarNumber: "",
+      expressCompany: "",
+      expressNumber: "",
       type: "璐ц溅", // 璐ц溅, 蹇��
     },
     deliveryRules: {
+      shippingCarNumber: [
+        { validator: validateDeliveryShippingCarNumber, trigger: "blur" },
+      ],
+      expressCompany: [{ validator: validateDeliveryExpressCompany, trigger: "blur" }],
       type: [{ required: true, message: "璇烽�夋嫨鍙戣揣绫诲瀷", trigger: "change" }],
     },
   });
@@ -1521,7 +1629,7 @@
     selectedQuotation.value = null;
     let userLists = await userListNoPage();
     userList.value = userLists.data;
-    listCustomer({ current: -1, size: -1 }).then(res => {
+    listCustomer({ current: -1, size: -1, type: 0 }).then(res => {
       customerOption.value = res.data.records;
     });
     form.value.entryPerson = userStore.id;
@@ -1530,6 +1638,8 @@
       form.value.entryDate = getCurrentDate();
       // 绛捐鏃ユ湡榛樿涓哄綋澶�
       form.value.executionDate = getCurrentDate();
+      // 榛樿鑷姩鐢熸垚閿�鍞悎鍚屽彿
+      form.value.autoGenerateContractNo = true;
     } else {
       currentId.value = row.id;
       getSalesLedgerWithProducts({ id: row.id, type: 1 }).then(res => {
@@ -1537,6 +1647,8 @@
         form.value.entryPerson = Number(res.entryPerson);
         productData.value = form.value.productData;
         fileList.value = form.value.storageBlobVOs;
+        // 缂栬緫鏃惰缃嚜鍔ㄧ敓鎴愪负false锛屽厑璁告墜鍔ㄤ慨鏀�
+        form.value.autoGenerateContractNo = false;
       });
     }
     // let userAll = await userStore.getInfo()
@@ -1630,6 +1742,7 @@
     productData.value = products.map(p => {
       const quantity = Number(p.quantity ?? 0) || 0;
       const unitPrice = Number(p.unitPrice ?? 0) || 0;
+      const singleQuantity = 1;
       const taxRate = "13"; // 榛樿 13%锛屼究浜庣洿鎺ユ彁浜わ紙濡傞渶鍙湪浜у搧涓嚜琛屼慨鏀癸級
       const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
       const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(
@@ -1642,12 +1755,16 @@
         specificationModel: p.specification || "",
         unit: p.unit || "",
         quantity: quantity,
+        singleQuantity: singleQuantity,
+        totalQuantity: String(quantity * singleQuantity),
         taxRate: taxRate,
         taxInclusiveUnitPrice: unitPrice.toFixed(2),
         taxInclusiveTotalPrice: taxInclusiveTotalPrice,
         taxExclusiveTotalPrice: taxExclusiveTotalPrice,
         invoiceType: "澧炴櫘绁�",
         isProduction: true,
+        productId: p.productId,
+        productModelId: p.productModelId
       };
     });
 
@@ -1671,6 +1788,9 @@
         }
         form.value.storageBlobDTOs = fileList;
         form.value.type = 1;
+        if (form.value.autoGenerateContractNo) {
+          form.value.salesContractNo = '';
+        }
         addOrUpdateSalesLedger(form.value).then(res => {
           proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
           closeDia();
@@ -1704,6 +1824,12 @@
     if (type === "edit") {
       productForm.value = { ...row };
       productIndex.value = index;
+      // 濡傛灉娌℃湁 totalQuantity锛岃嚜鍔ㄨ绠楋細鎬绘暟 = 姣忎欢鏁伴噺 * 鏁伴噺
+      if (!productForm.value.totalQuantity && productForm.value.quantity) {
+        const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
+        const quantity = parseFloat(productForm.value.quantity);
+        productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
+      }
       // 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� tree 鑺傜偣 id锛屽苟鍔犺浇瑙勬牸鍨嬪彿鍒楄〃
       try {
         const options =
@@ -2385,6 +2511,10 @@
         );
     }
 
+    // 璁$畻鎬绘暟 = 姣忎欢鏁伴噺 * 鏁伴噺
+    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
+    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
+
     isCalculating.value = false;
   };
 
@@ -2418,6 +2548,10 @@
       inclusiveTotalPrice / quantity
     ).toFixed(2);
 
+    // 璁$畻鎬绘暟 = 姣忎欢鏁伴噺 * 鏁伴噺
+    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
+    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
+
     isCalculating.value = false;
   };
 
@@ -2438,7 +2572,7 @@
 
     isCalculating.value = true;
 
-    // 璁$畻鍚◣鎬讳环
+    // 璁$畻鍚◣鎬讳环 = 鍗曚环 * 鏁伴噺
     productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
 
     // 濡傛灉鏈夌◣鐜囷紝璁$畻涓嶅惈绋庢�讳环
@@ -2449,6 +2583,10 @@
           productForm.value.taxRate
         );
     }
+
+    // 璁$畻鎬绘暟 = 姣忎欢鏁伴噺 * 鏁伴噺
+    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
+    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
 
     isCalculating.value = false;
   };
@@ -2470,7 +2608,7 @@
 
     isCalculating.value = true;
 
-    // 璁$畻鍚◣鎬讳环
+    // 璁$畻鍚◣鎬讳环 = 鍗曚环 * 鏁伴噺
     productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
 
     // 濡傛灉鏈夌◣鐜囷紝璁$畻涓嶅惈绋庢�讳环
@@ -2481,6 +2619,25 @@
           productForm.value.taxRate
         );
     }
+
+    isCalculating.value = false;
+  };
+
+  // 鏍规嵁姣忎欢鏁伴噺鍙樺寲璁$畻鎬绘暟
+  const calculateFromSingleQuantity = () => {
+    if (isCalculating.value) return;
+
+    const quantity = parseFloat(productForm.value.quantity);
+
+    if (!quantity || quantity <= 0) {
+      return;
+    }
+
+    isCalculating.value = true;
+
+    // 璁$畻鎬绘暟 = 姣忎欢鏁伴噺 * 鏁伴噺
+    const singleQuantity = parseInt(productForm.value.singleQuantity) || 1;
+    productForm.value.totalQuantity = (quantity * singleQuantity).toFixed(0);
 
     isCalculating.value = false;
   };
@@ -2537,6 +2694,7 @@
       瀹℃牳鎷掔粷: "瀹℃牳鎷掔粷",
       瀹℃牳閫氳繃: "瀹℃牳閫氳繃",
       宸插彂璐�: "宸插彂璐�",
+      閮ㄥ垎鍙戣揣: "閮ㄥ垎鍙戣揣",
     };
     return statusTextMap[statusStr] || "寰呭彂璐�";
   };
@@ -2568,6 +2726,7 @@
       瀹℃牳鎷掔粷: "danger",
       瀹℃牳閫氳繃: "success",
       宸插彂璐�: "success",
+      閮ㄥ垎鍙戣揣: "warning",
     };
     return typeTextMap[statusStr] || "info";
   };
@@ -2593,7 +2752,7 @@
 
     // 鍙戣揣鐘舵�佸繀椤绘槸"寰呭彂璐�"鎴�"瀹℃牳鎷掔粷"
     const statusStr = shippingStatus ? String(shippingStatus).trim() : "";
-    return statusStr === "寰呭彂璐�" || statusStr === "瀹℃牳鎷掔粷";
+    return statusStr === "寰呭彂璐�" || statusStr === "瀹℃牳鎷掔粷" || statusStr === "閮ㄥ垎鍙戣揣";
   };
 
   // 鎵撳紑闄勪欢寮圭獥
@@ -2605,7 +2764,40 @@
     recordId.value = row.id;
     fileDialogVisible.value = true;
   };
-
+	const handleBatchExportContract = () => {
+		if (selectedRows.value.length === 0) {
+			proxy.$modal.msgWarning("璇烽�夋嫨瑕佸鍑虹殑鍙拌处");
+			return;
+		}
+		const firstCustomerKey =
+			selectedRows.value[0].customerId ?? selectedRows.value[0].customerName ?? "";
+		const hasDifferentCustomer = selectedRows.value.some((row) => {
+			const customerKey = row.customerId ?? row.customerName ?? "";
+			return String(customerKey) !== String(firstCustomerKey);
+		});
+		if (hasDifferentCustomer) {
+			proxy.$modal.msgWarning("浠呮敮鎸佸悓涓�瀹㈡埛鍚屾椂瀵煎嚭鍚堝悓");
+			return;
+		}
+		const ids = selectedRows.value
+			.map((row) => row.id)
+			.filter((id) => id !== null && id !== undefined);
+		if (ids.length === 0) {
+			proxy.$modal.msgWarning("鏈幏鍙栧埌鍚堝悓ID");
+			return;
+		}
+		proxy.download(
+			"/sales/ledger/exportContract",
+			ids,
+			`閿�鍞悎鍚宊鎵归噺_${dayjs().format("YYYYMMDDHHmmss")}.docx`,
+			{
+				method: "post",
+				filename: `閿�鍞悎鍚宊鎵归噺_${dayjs().format("YYYYMMDDHHmmss")}.docx`,
+				headers: { "Content-Type": "application/json;charset=utf-8" },
+				transformRequest: [(data) => JSON.stringify(data)],
+			}
+		);
+	}
   // 鎵撳紑鍙戣揣寮规
   const openDeliveryForm = async row => {
     // 妫�鏌ユ槸鍚﹀彲浠ュ彂璐�
@@ -2620,11 +2812,31 @@
     const batchNoList = await getDeliveryBatchNoList(
       row.productModelId || row.modelId
     );
+    
+    // 鑷姩鍒嗛厤鍙戣揣鏁伴噺锛氭寜鐓у緟鍙戣揣鏁伴噺锛屼粠涓婂埌涓嬩緷娆″垎閰�
+    const noQuantity = Number(row?.noQuantity || 0);
+    let remainingQuantity = noQuantity;
+    batchNoList.forEach(item => {
+      if (remainingQuantity <= 0) {
+        item.deliveryQuantity = 0;
+        return;
+      }
+      const batchStockQuantity = getDeliveryBatchQuantity(item);
+      // 褰撳墠鎵规鍙垎閰嶇殑鏁伴噺锛氬彇鍓╀綑寰呭彂璐ф暟閲忓拰搴撳瓨鏁伴噺鐨勮緝灏忓��
+      const assignQuantity = Math.min(remainingQuantity, batchStockQuantity);
+      item.deliveryQuantity = assignQuantity;
+      remainingQuantity -= assignQuantity;
+    });
+    
     deliveryForm.value = {
+      shippingCarNumber: "",
+      expressCompany: "",
+      expressNumber: "",
       type: "璐ц溅",
       batchNo: [],
       batchNoList,
     };
+    deliveryFileList.value = [];
     deliveryFormVisible.value = true;
   };
 
@@ -2662,6 +2874,19 @@
           salesLedgerId: salesLedgerId,
           salesLedgerProductId: currentDeliveryRow.value.id,
           type: deliveryForm.value.type,
+          shippingCarNumber:
+            deliveryForm.value.type === "璐ц溅"
+              ? deliveryForm.value.shippingCarNumber
+              : "",
+          expressCompany:
+            deliveryForm.value.type === "蹇��"
+              ? deliveryForm.value.expressCompany
+              : "",
+          expressNumber:
+            deliveryForm.value.type === "蹇��"
+              ? deliveryForm.value.expressNumber
+              : "",
+          storageBlobDTOs: deliveryFileList.value || [],
           batchNo: deliveryForm.value.batchNo,
           batchNoDetailList: selectedBatchRows.map(item => ({
             stockInventoryId: item.id,
@@ -2701,8 +2926,18 @@
   };
 
   // 鍏抽棴鍙戣揣寮规
+  const handleDeliveryTypeChange = val => {
+    if (val === "璐ц溅") {
+      deliveryForm.value.expressCompany = "";
+      deliveryForm.value.expressNumber = "";
+    } else {
+      deliveryForm.value.shippingCarNumber = "";
+    }
+  };
+
   const closeDeliveryDia = () => {
     proxy.resetForm("deliveryFormRef");
+    deliveryFileList.value = [];
     deliveryFormVisible.value = false;
     currentDeliveryRow.value = null;
   };
@@ -2919,4 +3154,4 @@
       page-break-after: avoid;
     }
   }
-</style>
+</style>
\ No newline at end of file

--
Gitblit v1.9.3