From 0f013881f8a5b78d2e2651d09d332ac01a759401 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期二, 20 一月 2026 14:42:50 +0800
Subject: [PATCH] 销售台账发货同步

---
 src/views/salesManagement/salesLedger/index.vue |  589 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 276 insertions(+), 313 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 2fbd217..54114f1 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -6,8 +6,16 @@
           <el-input v-model="searchForm.customerName" placeholder="璇疯緭鍏�" clearable prefix-icon="Search"
             @change="handleQuery" />
         </el-form-item>
+        <el-form-item label="瀹㈡埛鍚堝悓鍙凤細">
+          <el-input v-model="searchForm.customerContractNo" placeholder="璇疯緭鍏�" clearable prefix-icon="Search"
+            @change="handleQuery" />
+        </el-form-item>
         <el-form-item label="閿�鍞悎鍚屽彿锛�">
           <el-input v-model="searchForm.salesContractNo" placeholder="璇疯緭鍏�" clearable prefix-icon="Search"
+            @change="handleQuery" />
+        </el-form-item>
+        <el-form-item label="椤圭洰鍚嶇О锛�">
+          <el-input v-model="searchForm.projectName" placeholder="璇疯緭鍏�" clearable prefix-icon="Search"
             @change="handleQuery" />
         </el-form-item>
         <el-form-item label="褰曞叆鏃ユ湡锛�">
@@ -33,7 +41,7 @@
       </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%"
-        :summary-method="summarizeMainTable" @expand-change="expandChange" height="calc(100vh - 21em)">
+        :summary-method="summarizeMainTable" @expand-change="expandChange" height="calc(100vh - 18.5em)">
         <el-table-column align="center" type="selection" width="55" />
         <el-table-column type="expand">
           <template #default="props">
@@ -42,67 +50,72 @@
               <el-table-column label="浜у搧澶х被" prop="productCategory" />
               <el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" />
               <el-table-column label="鍗曚綅" prop="unit" />
+              <el-table-column label="浜у搧鐘舵��" width="100px" align="center">
+                <template #default="scope">
+                  <el-tag v-if="scope.row.approveStatus === 0" type="info">鏈嚭搴�</el-tag>
+                  <el-tag v-if="scope.row.approveStatus === 1" type="success">宸插嚭搴�</el-tag>
+                  <el-tag v-if="scope.row.approveStatus === 2" type="warning">瀹℃牳涓�</el-tag>
+                  <el-tag v-if="scope.row.approveStatus === 3" type="success">瀹℃牳鎴愬姛</el-tag>
+                  <el-tag v-if="scope.row.approveStatus === 4" type="danger">瀹℃牳澶辫触</el-tag>
+                </template>
+              </el-table-column>
+              <el-table-column label="鍙戣揣杞︾墝" minWidth="100px" align="center">
+                <template #default="scope">
+                  <div>
+                    <el-tag type="success" v-if="scope.row.shippingCarNumber">{{ scope.row.shippingCarNumber }}</el-tag>
+                    <el-tag v-else type="info">鏈彂璐�</el-tag>
+                  </div>
+                </template>
+              </el-table-column>
+              <el-table-column label="鍙戣揣鏃ユ湡" minWidth="100px" align="center">
+                <template #default="scope">
+                  <div>
+                    <div v-if="scope.row.shippingDate">{{ scope.row.shippingDate }}</div>
+                    <el-tag v-else type="info">鏈彂璐�</el-tag>
+                  </div>
+                </template>
+              </el-table-column>
               <el-table-column label="鏁伴噺" prop="quantity" />
               <el-table-column label="绋庣巼(%)" prop="taxRate" />
               <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
               <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
               <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
+            <!--鎿嶄綔-->
+              <el-table-column Width="60px" label="鎿嶄綔" align="center">
+                <template #default="scope">
+                  <el-button :disabled="scope.row.approveStatus!==2 || scope.row.approveStatus!==5" link type="primary" size="small" @click="openDeliveryForm(scope.row)">鍙戣揣</el-button>
+                </template>
+              </el-table-column>
             </el-table>
           </template>
         </el-table-column>
         <el-table-column align="center" label="搴忓彿" type="index" width="60" />
         <el-table-column label="閿�鍞悎鍚屽彿" prop="salesContractNo" width="180" show-overflow-tooltip />
+        <el-table-column label="瀹㈡埛鍚堝悓鍙�" prop="customerContractNo" width="180" show-overflow-tooltip />
         <el-table-column label="瀹㈡埛鍚嶇О" prop="customerName" width="300" show-overflow-tooltip />
         <el-table-column label="涓氬姟鍛�" prop="salesman" width="100" show-overflow-tooltip />
+        <el-table-column label="椤圭洰鍚嶇О" prop="projectName" width="180" show-overflow-tooltip />
+        <el-table-column label="浠樻鏂瑰紡" prop="paymentMethod" show-overflow-tooltip />
         <el-table-column label="鍚堝悓閲戦(鍏�)" prop="contractAmount" width="220" show-overflow-tooltip
           :formatter="formattedNumber" />
         <el-table-column label="褰曞叆浜�" prop="entryPersonName" width="100" show-overflow-tooltip />
-				<el-table-column label="鐢熶骇鐘舵��" prop="productionStatus" width="100" show-overflow-tooltip >
-					<template #default="scope">
-						<div>
-							<el-tag v-if="scope.row.productionStatus === '宸插畬鎴�'" type="success">宸插畬鎴�</el-tag>
-							<el-tag v-if="scope.row.productionStatus === '鐢熶骇涓�'" type="warning">鐢熶骇涓�</el-tag>
-							<el-tag v-if="scope.row.productionStatus === '鏈紑濮�'" type="danger">鏈紑濮�</el-tag>
-						</div>
-					</template>
-				</el-table-column>
-        <el-table-column label="鍙戣揣杞︾墝" prop="shippingCarNumber" width="120" show-overflow-tooltip>
-          <template #default="scope">
-            <div>
-              <div v-if="scope.row.shippingCarNumber">{{ scope.row.shippingCarNumber }}</div>
-              <el-tag v-else type="warning">鏈彂璐�</el-tag>
-            </div>
-          </template>
-        </el-table-column>
-        <el-table-column label="鍙戣揣鏃ユ湡" prop="shippingDate" width="120" show-overflow-tooltip />
-        <el-table-column label="绛捐鏃ユ湡" prop="executionDate" width="120" show-overflow-tooltip />
         <el-table-column label="褰曞叆鏃ユ湡" prop="entryDate" width="120" show-overflow-tooltip />
-        <el-table-column fixed="right" label="鎿嶄綔" min-width="200" align="center">
+        <el-table-column label="绛捐鏃ユ湡" prop="executionDate" width="120" show-overflow-tooltip />
+        <el-table-column fixed="right" label="鎿嶄綔" min-width="100" 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('view', scope.row)">璇︽儏</el-button>-->
             <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">闄勪欢</el-button>
-            <el-button v-if="!scope.row.shippingCarNumber" link type="primary" size="small" @click="openDeliveryForm(scope.row)">鍙戣揣</el-button>
+<!--            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">鍙戣揣</el-button>-->
           </template>
         </el-table-column>
       </el-table>
       <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
         :page="page.current" :limit="page.size" @pagination="paginationChange" />
     </div>
-    <FormDialog 
-      v-model="dialogFormVisible" 
-      :title="operationType === 'add' ? '鏂板閿�鍞彴璐﹂〉闈�' : '缂栬緫閿�鍞彴璐﹂〉闈�'" 
-      :width="'70%'"
-      :operation-type="operationType"
-      @close="closeDia"
-      @confirm="submitForm"
-      @cancel="closeDia">
+    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '鏂板閿�鍞彴璐﹂〉闈�' : '缂栬緫閿�鍞彴璐﹂〉闈�'" width="70%"
+      @close="closeDia">
       <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
-        <el-row v-if="operationType !== 'view'">
-          <el-col :span="24" style="display:flex; justify-content:flex-end; gap:10px; margin-bottom: 6px;">
-            <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">
@@ -111,9 +124,7 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="涓氬姟鍛橈細" prop="salesman">
-              <el-select v-model="form.salesman"
-												 filterable
-                         :reserve-keyword="false" placeholder="璇烽�夋嫨" clearable :disabled="operationType === 'view'">
+              <el-select v-model="form.salesman" placeholder="璇烽�夋嫨" clearable :disabled="operationType === 'view'">
                 <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName"
                   :value="item.nickName" />
               </el-select>
@@ -122,14 +133,26 @@
         </el-row>
         <el-row :gutter="30">
           <el-col :span="12">
+            <el-form-item label="瀹㈡埛鍚堝悓鍙凤細" prop="customerContractNo">
+              <el-input v-model="form.customerContractNo" placeholder="璇疯緭鍏�" clearable :disabled="operationType === 'view'"/>
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
             <el-form-item label="瀹㈡埛鍚嶇О锛�" prop="customerId">
-              <el-select v-model="form.customerId" placeholder="璇烽�夋嫨" clearable :disabled="operationType === 'view'" filterable>
+              <el-select v-model="form.customerId" placeholder="璇烽�夋嫨" clearable :disabled="operationType === 'view'">
                 <el-option v-for="item in customerOption" :key="item.id" :label="item.customerName" :value="item.id">
                   {{
                     item.customerName + "鈥斺��" + item.taxpayerIdentificationNumber
                   }}
                 </el-option>
               </el-select>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <el-form-item label="椤圭洰鍚嶇О锛�" prop="projectName">
+              <el-input v-model="form.projectName" placeholder="璇疯緭鍏�" clearable :disabled="operationType === 'view'" />
             </el-form-item>
           </el-col>
 					<el-col :span="12">
@@ -142,10 +165,7 @@
         <el-row :gutter="30">
 					<el-col :span="12">
 						<el-form-item label="褰曞叆浜猴細" prop="entryPerson">
-							<el-select v-model="form.entryPerson"
-												 filterable
-                         default-first-option
-                         :reserve-keyword="false" placeholder="璇烽�夋嫨" clearable @change="changs">
+							<el-select v-model="form.entryPerson" placeholder="璇烽�夋嫨" clearable @change="changs" disabled>
 								<el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
 							</el-select>
 						</el-form-item>
@@ -157,7 +177,13 @@
             </el-form-item>
           </el-col>
         </el-row>
-
+        <el-row :gutter="30">
+          <el-col :span="12">
+            <el-form-item label="浠樻鏂瑰紡">
+              <el-input v-model="form.paymentMethod" 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>
@@ -207,71 +233,14 @@
           </el-col>
         </el-row>
       </el-form>
-    </FormDialog>
-
-    <!-- 浠庢姤浠峰崟瀵煎叆锛堜粎瀹℃壒閫氳繃锛� -->
-    <el-dialog
-      v-model="quotationDialogVisible"
-      title="閫夋嫨瀹℃壒閫氳繃鐨勯攢鍞姤浠峰崟"
-      width="80%"
-      :close-on-click-modal="false"
-    >
-      <div style="margin-bottom: 12px; display:flex; gap: 12px; align-items:center;">
-        <el-input
-          v-model="quotationSearchForm.quotationNo"
-          placeholder="璇疯緭鍏ユ姤浠峰崟鍙�"
-          clearable
-          style="max-width: 260px;"
-          @change="fetchQuotationList"
-        />
-        <el-input
-          v-model="quotationSearchForm.customer"
-          placeholder="璇疯緭鍏ュ鎴峰悕绉�"
-          clearable
-          style="max-width: 260px;"
-          @change="fetchQuotationList"
-        />
-        <el-button type="primary" @click="fetchQuotationList">鎼滅储</el-button>
-        <el-button @click="resetQuotationSearch">閲嶇疆</el-button>
-      </div>
-
-      <el-table
-        :data="quotationList"
-        border
-        stripe
-        v-loading="quotationLoading"
-        height="420px"
-      >
-        <el-table-column align="center" label="搴忓彿" type="index" width="60" />
-        <el-table-column prop="quotationNo" label="鎶ヤ环鍗曞彿" width="180" show-overflow-tooltip />
-        <el-table-column prop="customer" label="瀹㈡埛鍚嶇О" min-width="220" show-overflow-tooltip />
-        <el-table-column prop="salesperson" label="涓氬姟鍛�" width="120" show-overflow-tooltip />
-        <el-table-column prop="quotationDate" label="鎶ヤ环鏃ユ湡" width="140" />
-        <el-table-column prop="status" label="瀹℃壒鐘舵��" width="120" align="center" />
-        <el-table-column prop="totalAmount" label="鎶ヤ环閲戦(鍏�)" width="160" align="right">
-          <template #default="scope">
-            {{ Number(scope.row.totalAmount ?? 0).toFixed(2) }}
-          </template>
-        </el-table-column>
-        <el-table-column fixed="right" label="鎿嶄綔" width="120" align="center">
-          <template #default="scope">
-            <el-button type="primary" link @click="applyQuotation(scope.row)">閫夋嫨</el-button>
-          </template>
-        </el-table-column>
-      </el-table>
-
       <template #footer>
-        <el-button @click="quotationDialogVisible = false">鍏抽棴</el-button>
+        <div class="dialog-footer">
+          <el-button type="primary" @click="submitForm">纭</el-button>
+          <el-button @click="closeDia">鍙栨秷</el-button>
+        </div>
       </template>
     </el-dialog>
-    <FormDialog 
-      v-model="productFormVisible" 
-      :title="productOperationType === 'add' ? '鏂板浜у搧' : '缂栬緫浜у搧'" 
-      :width="'40%'"
-      :operation-type="productOperationType"
-      @close="closeProductDia"
-      @confirm="submitProduct"
-      @cancel="closeProductDia">
+    <el-dialog v-model="productFormVisible" :title="productOperationType === 'add' ? '鏂板浜у搧' : '缂栬緫浜у搧'" width="40%" @close="closeProductDia">
       <el-form :model="productForm" label-width="140px" label-position="top" :rules="productRules" ref="productFormRef">
         <el-row :gutter="30">
           <el-col :span="24">
@@ -287,7 +256,7 @@
         <el-row :gutter="30">
           <el-col :span="24">
             <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productModelId">
-              <el-select v-model="productForm.productModelId" placeholder="璇烽�夋嫨" clearable @change="getProductModel" filterable>
+              <el-select v-model="productForm.productModelId" placeholder="璇烽�夋嫨" clearable @change="getProductModel">
                 <el-option v-for="item in modelOptions" :key="item.id" :label="item.model" :value="item.id" />
               </el-select>
             </el-form-item>
@@ -348,7 +317,13 @@
           </el-col>
         </el-row>
       </el-form>
-    </FormDialog>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" @click="submitProduct">纭</el-button>
+          <el-button @click="closeProductDia">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
 		<!-- 鎵撳嵃棰勮寮圭獥 -->
 		<el-dialog
 			v-model="printPreviewVisible"
@@ -383,15 +358,12 @@
 										<span class="value">{{ formatDate(item.createTime) }}</span>
 									</div>
 									<div>
-										<span class="label">鍙戣揣杞︾墝鍙凤細</span>
-										<span class="value">{{ item.shippingCarNumber }}</span>
-									</div>
-								</div>
-								<div class="info-row">
-									<div>
+
 										<span class="label">瀹㈡埛鍚嶇О锛�</span>
 										<span class="value">{{ item.customerName || '寮犵埍鏈�' }}</span>
 									</div>
+								</div>
+								<div class="info-row">
 									<span class="label">鍗曞彿锛�</span>
 									<span class="value">{{ item.salesContractNo }}</span>
 								</div>
@@ -500,6 +472,15 @@
 						</el-form-item>
 					</el-col>
 				</el-row>
+        <el-row :gutter="30">
+          <el-col :span="24">
+            <el-form-item label="瀹℃壒浜猴細" prop="approverId">
+              <el-select v-model="deliveryForm.approverId" placeholder="璇烽�夋嫨瀹℃壒浜�" clearable :disabled="operationType === 'view'">
+                <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
+              </el-select>
+            </el-form-item>
+          </el-col>
+        </el-row>
 			</el-form>
 			<template #footer>
 				<div class="dialog-footer">
@@ -509,35 +490,70 @@
 			</template>
 		</el-dialog>
     <FileListDialog ref="fileListRef" v-model="fileListDialogVisible" />
+    <!-- 瀵煎叆瀵硅瘽妗� -->
+    <el-dialog
+      :title="importUpload.title"
+      v-model="importUpload.open"
+      width="400px"
+      append-to-body
+    >
+      <el-upload
+        ref="importUploadRef"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="importUpload.headers"
+        :action="importUpload.url"
+        :disabled="importUpload.isUploading"
+        :before-upload="importUpload.beforeUpload"
+        :on-progress="importUpload.onProgress"
+        :on-success="importUpload.onSuccess"
+        :on-error="importUpload.onError"
+        :on-change="importUpload.onChange"
+        :auto-upload="false"
+        drag
+      >
+        <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
+        <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
+        <template #tip>
+          <div class="el-upload__tip text-center">
+            <span>浠呭厑璁稿鍏ls銆亁lsx鏍煎紡鏂囦欢銆�</span>
+          </div>
+        </template>
+      </el-upload>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" @click="submitImportFile" :loading="importUpload.isUploading">纭� 瀹�</el-button>
+          <el-button @click="importUpload.open = false">鍙� 娑�</el-button>
+        </div>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
 <script setup>
 import { getToken } from "@/utils/auth";
 import pagination from "@/components/PIMTable/Pagination.vue";
-import {onMounted, ref} from "vue";
+import {onMounted, ref, getCurrentInstance} from "vue";
 import { addShippingInfo } from "@/api/salesManagement/deliveryLedger.js";
-import { ElMessageBox } from "element-plus";
+import { ElMessageBox, ElMessage } from "element-plus";
+import { UploadFilled } from "@element-plus/icons-vue";
 import useUserStore from "@/store/modules/user";
 import { userListNoPage } from "@/api/system/user.js";
-import FileListDialog from '@/components/Dialog/FileListDialog.vue';
-import FormDialog from '@/components/Dialog/FormDialog.vue';
-import { getQuotationList } from "@/api/salesManagement/salesQuotation.js";
+import FileList from "./fileList.vue";
 import {
-	ledgerListPage,
-	productList,
-	customerList,
-	addOrUpdateSalesLedger,
-	getSalesLedgerWithProducts,
-	delLedger,
-	addOrUpdateSalesLedgerProduct,
-	delProduct,
-	delLedgerFile, getProductInventory,
+  ledgerListPage,
+  productList,
+  customerList,
+  addOrUpdateSalesLedger,
+  getSalesLedgerWithProducts,
+  delLedger,
+  addOrUpdateSalesLedgerProduct,
+  delProduct,
+  delLedgerFile, getProductInventory,
 } from "@/api/salesManagement/salesLedger.js";
 import { modelList, productTreeList } from "@/api/basicData/product.js";
 import useFormData from "@/hooks/useFormData.js";
 import dayjs from "dayjs";
-import { getCurrentDate } from "@/utils/index.js";
 
 const userStore = useUserStore();
 const { proxy } = getCurrentInstance();
@@ -563,7 +579,9 @@
 const data = reactive({
   searchForm: {
     customerName: "", // 瀹㈡埛鍚嶇О
+    customerContractNo: "", // 瀹㈡埛鍚堝悓缂栧彿
     salesContractNo: "", // 閿�鍞悎鍚岀紪鍙�
+    projectName: "", // 椤圭洰鍚嶇О
     entryDate: null, // 褰曞叆鏃ユ湡
     entryDateStart: undefined,
     entryDateEnd: undefined,
@@ -571,16 +589,23 @@
   form: {
     salesContractNo: "",
     salesman: "",
+    customerContractNo: "",
     customerId: "",
+    projectName: "",
     entryPerson: "",
     entryDate: "",
     maintenanceTime: "",
     productData: [],
     executionDate: "",
+    paymentMethod: "",
   },
   rules: {
     salesman: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+    customerContractNo: [
+      { required: true, message: "璇疯緭鍏�", trigger: "blur" },
+    ],
     customerId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+    projectName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
     entryPerson: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
     entryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
     executionDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
@@ -638,16 +663,6 @@
 const printPreviewVisible = ref(false);
 const printData = ref([]);
 
-// 鎶ヤ环鍗曞鍏ョ浉鍏�
-const quotationDialogVisible = ref(false);
-const quotationLoading = ref(false);
-const quotationList = ref([]);
-const quotationSearchForm = reactive({
-  quotationNo: "",
-  customer: "",
-});
-const selectedQuotation = ref(null);
-
 // 鍙戣揣鐩稿叧
 const deliveryFormVisible = ref(false);
 const currentDeliveryRow = ref(null);
@@ -663,9 +678,62 @@
     shippingCarNumber: [
       { required: true, message: "璇疯緭鍏ュ彂璐ц溅鐗屽彿", trigger: "blur" }
     ],
+    approverId:[
+      {
+        required: true,message: "",
+      }
+    ]
   },
 });
 const { deliveryForm, deliveryRules } = toRefs(deliveryFormData);
+
+// 瀵煎叆鐩稿叧
+const importUploadRef = ref(null);
+const importUpload = reactive({
+  title: "瀵煎叆閿�鍞彴璐�",
+  open: false,
+  url: import.meta.env.VITE_APP_BASE_API + "/sales/ledger/import",
+  headers: { Authorization: "Bearer " + getToken() },
+  isUploading: false,
+  beforeUpload: (file) => {
+    const isExcel = file.name.endsWith('.xlsx') || file.name.endsWith('.xls');
+    const isLt10M = file.size / 1024 / 1024 < 10;
+    if (!isExcel) {
+      proxy.$modal.msgError("涓婁紶鏂囦欢鍙兘鏄� xlsx/xls 鏍煎紡!");
+      return false;
+    }
+    if (!isLt10M) {
+      proxy.$modal.msgError("涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 10MB!");
+      return false;
+    }
+    return true;
+  },
+  onChange: (file, fileList) => {
+    console.log('鏂囦欢鐘舵�佹敼鍙�', file, fileList);
+  },
+  onProgress: (event, file, fileList) => {
+    console.log('涓婁紶涓�...', event.percent);
+  },
+  onSuccess: (response, file, fileList) => {
+    console.log('涓婁紶鎴愬姛', response, file, fileList);
+    importUpload.isUploading = false;
+    if (response.code === 200) {
+      proxy.$modal.msgSuccess("瀵煎叆鎴愬姛");
+      importUpload.open = false;
+      if (importUploadRef.value) {
+        importUploadRef.value.clearFiles();
+      }
+      getList();
+    } else {
+      proxy.$modal.msgError(response.msg || "瀵煎叆澶辫触");
+    }
+  },
+  onError: (error, file, fileList) => {
+    console.error('涓婁紶澶辫触', error, file, fileList);
+    importUpload.isUploading = false;
+    proxy.$modal.msgError("瀵煎叆澶辫触锛岃閲嶈瘯");
+  },
+});
 
 const changeDaterange = (value) => {
   if (value) {
@@ -681,11 +749,7 @@
 // 鏌ヨ鍒楄〃
 /** 鎼滅储鎸夐挳鎿嶄綔 */
 const handleQuery = () => {
-  // 鍙湁鍦ㄧ偣鍑绘悳绱㈡寜閽椂鎵嶉噸缃〉鐮佸埌绗竴椤�
-  // 閬垮厤琛ㄥ崟瀛楁change浜嬩欢骞叉壈鍒嗛〉
-  if (arguments.length === 0) {
-    page.current = 1;
-  }
+  page.current = 1;
 	expandedRowKeys.value = [];
   getList();
 };
@@ -694,14 +758,12 @@
   page.size = obj.limit;
   getList();
 };
-const getList = () => {
+const getList =async () => {
+  let userLists = await userListNoPage();
+  userList.value = userLists.data;
   tableLoading.value = true;
   const { entryDate, ...rest } = searchForm;
-  // 灏嗚寖鍥存棩鏈熷瓧娈典紶閫掔粰鍚庣
-  const params = { ...rest, ...page };
-  // 绉婚櫎褰曞叆鏃ユ湡鐨勯粯璁ゅ�艰缃紝鍙繚鐣欒寖鍥存棩鏈熷瓧娈�
-  delete params.entryDate;
-  ledgerListPage(params)
+  ledgerListPage({ ...rest, ...page })
     .then((res) => {
       tableLoading.value = false;
       tableData.value = res.records;
@@ -716,12 +778,8 @@
 };
 // 鑾峰彇浜у搧澶х被tree鏁版嵁
 const getProductOptions = () => {
-  // 杩斿洖 Promise锛屼究浜庡湪缂栬緫浜у搧鏃剁瓑寰呭姞杞藉畬鎴�
-  return productTreeList().then((res) => {
-    // 鍏煎鎺ュ彛杩斿洖 { data: [] } 鎴栫洿鎺ヨ繑鍥炴暟缁�
-    const list = Array.isArray(res) ? res : (res?.data ?? []);
-    productOptions.value = convertIdToValue(list);
-    return productOptions.value;
+  productTreeList().then((res) => {
+    productOptions.value = convertIdToValue(res);
   });
 };
 const formattedNumber = (row, column, cellValue) => {
@@ -773,19 +831,6 @@
     return newItem;
   });
 }
-// 鏍规嵁鍚嶇О鍙嶆煡浜у搧澶х被 id锛屼究浜庝粎瀛樺悕绉版椂鐨勫弽鏄�
-function findNodeIdByLabel(nodes, label) {
-  if (!label) return null;
-  for (let i = 0; i < nodes.length; i++) {
-    const node = nodes[i];
-    if (node.label === label) return node.value;
-    if (node.children && node.children.length > 0) {
-      const found = findNodeIdByLabel(node.children, label);
-      if (found !== null && found !== undefined) return found;
-    }
-  }
-  return null;
-}
 // 琛ㄦ牸閫夋嫨鏁版嵁
 const handleSelectionChange = (selection) => {
   // 杩囨护鎺夊瓙鏁版嵁
@@ -796,23 +841,31 @@
   productSelectedRows.value = selectedRows;
 };
 const expandedRowKeys = ref([]);
-// 灞曞紑琛�
-const expandChange = (row, expandedRows) => {
-  if (expandedRows.length > 0) {
+// 灞曞紑琛岋紙濮嬬粓鍙睍寮�涓�琛岋級
+const expandChange = (row) => {
+  const rowKey = row.id;
+  const isExpanded = expandedRowKeys.value.includes(rowKey);
+
+  if (isExpanded) {
+    // 褰撳墠琛屽凡灞曞紑 -> 鏀惰捣
     expandedRowKeys.value = [];
-    try {
-      productList({ salesLedgerId: row.id, type: 1 }).then((res) => {
-        const index = tableData.value.findIndex((item) => item.id === row.id);
-        if (index > -1) {
-          tableData.value[index].children = res.data;
-        }
-        expandedRowKeys.value.push(row.id);
-      });
-    } catch (error) {
-      console.log(error);
-    }
-  } else {
-    expandedRowKeys.value = [];
+    return;
+  }
+
+  // 灞曞紑褰撳墠琛屽墠锛屽厛鏀惰捣鍏跺畠琛�
+  expandedRowKeys.value = [];
+
+  try {
+    productList({ salesLedgerId: row.id, type: 1 }).then((res) => {
+      const index = tableData.value.findIndex((item) => item.id === row.id);
+      if (index > -1) {
+        tableData.value[index].children = res.data;
+      }
+      // 鍙繚鐣欏綋鍓嶈繖涓�琛屽浜庡睍寮�鐘舵��
+      expandedRowKeys.value = [rowKey];
+    });
+  } catch (error) {
+    console.log(error);
   }
 };
 // 涓昏〃鍚堣鏂规硶
@@ -836,19 +889,11 @@
   operationType.value = type;
   form.value = {};
   productData.value = [];
-  selectedQuotation.value = null;
-  let userLists = await userListNoPage();
-  userList.value = userLists.data;
   customerList().then((res) => {
     customerOption.value = res;
   });
   form.value.entryPerson = userStore.id;
-  if (type === "add") {
-    // 鏂板鏃惰缃綍鍏ユ棩鏈熶负褰撳ぉ
-    form.value.entryDate = getCurrentDate();
-    // 绛捐鏃ユ湡榛樿涓哄綋澶�
-    form.value.executionDate = getCurrentDate();
-  } else {
+  if (type !== "add") {
     currentId.value = row.id;
     getSalesLedgerWithProducts({ id: row.id, type: 1 }).then((res) => {
       form.value = { ...res };
@@ -865,87 +910,6 @@
   // });
   form.value.entryDate = getCurrentDate(); // 璁剧疆榛樿褰曞叆鏃ユ湡涓哄綋鍓嶆棩鏈�
   dialogFormVisible.value = true;
-};
-
-// 鎵撳紑鎶ヤ环鍗曢�夋嫨寮圭獥锛堜粎瀹℃壒閫氳繃锛�
-const openQuotationDialog = async () => {
-  if (operationType.value === "view") return;
-  quotationDialogVisible.value = true;
-  // 鍏堢‘淇濆鎴峰垪琛ㄥ凡鍔犺浇锛屼究浜庡悗缁洖濉� customerId
-  if (!customerOption.value || customerOption.value.length === 0) {
-    try {
-      const res = await customerList();
-      customerOption.value = res;
-    } catch (e) {
-      // ignore锛屽厑璁哥敤鎴峰悗缁墜鍔ㄩ�夋嫨瀹㈡埛
-    }
-  }
-  await fetchQuotationList();
-};
-
-const fetchQuotationList = async () => {
-  quotationLoading.value = true;
-  try {
-    const params = {
-      // 鍏煎鍚庣鍒嗛〉瀛楁锛氳繖閲屾部鐢ㄦ姤浠烽〉闈㈠凡鏈夊彲鐢ㄧ殑瀛楁鍛藉悕
-      currentPage: 1,
-      pageSize: 100,
-      ...quotationSearchForm,
-      status: "閫氳繃",
-    };
-    const res = await getQuotationList(params);
-    quotationList.value = res?.data?.records || [];
-  } finally {
-    quotationLoading.value = false;
-  }
-};
-
-const resetQuotationSearch = async () => {
-  quotationSearchForm.quotationNo = "";
-  quotationSearchForm.customer = "";
-  await fetchQuotationList();
-};
-
-// 閫変腑鎶ヤ环鍗曞悗鍥炲~鍒板彴璐﹁〃鍗�
-const applyQuotation = (row) => {
-  if (!row) return;
-  selectedQuotation.value = row;
-
-  // 涓氬姟鍛�
-  form.value.salesman = row.salesperson || "";
-
-  // 瀹㈡埛鍚嶇О -> customerId
-  const customer = (customerOption.value || []).find((c) => c.customerName === row.customer);
-  if (customer?.id) {
-    form.value.customerId = customer.id;
-  } else {
-    // 濡傛灉鎵句笉鍒帮紝淇濈暀鍘熷�硷紙鍏佽鐢ㄦ埛鎵嬪姩閫夋嫨/涓嶆墦鏂凡鏈夎緭鍏ワ級
-    form.value.customerId = form.value.customerId || "";
-  }
-
-  // 浜у搧淇℃伅鏄犲皠锛氭姤浠� products -> 鍙拌处 productData
-  const products = Array.isArray(row.products) ? row.products : [];
-  productData.value = products.map((p) => {
-    const quantity = Number(p.quantity ?? 0) || 0;
-    const unitPrice = Number(p.unitPrice ?? 0) || 0;
-    const taxRate = "13"; // 榛樿 13%锛屼究浜庣洿鎺ユ彁浜わ紙濡傞渶鍙湪浜у搧涓嚜琛屼慨鏀癸級
-    const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
-    const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(taxInclusiveTotalPrice, taxRate);
-    return {
-      // 鍙拌处瀛楁
-      productCategory: p.product || p.productName || "",
-      specificationModel: p.specification || "",
-      unit: p.unit || "",
-      quantity: quantity,
-      taxRate: taxRate,
-      taxInclusiveUnitPrice: unitPrice.toFixed(2),
-      taxInclusiveTotalPrice: taxInclusiveTotalPrice,
-      taxExclusiveTotalPrice: taxExclusiveTotalPrice,
-      invoiceType: "澧炴櫘绁�",
-    };
-  });
-
-  quotationDialogVisible.value = false;
 };
 function changs(val) {
   console.log(val);
@@ -1019,7 +983,7 @@
 
 const productIndex = ref(0);
 // 鎵撳紑浜у搧寮规
-const openProductForm = async (type, row, index) => {
+const openProductForm =async (type, row,index) => {
   productOperationType.value = type;
   productForm.value = {};
   proxy.resetForm("productFormRef");
@@ -1032,29 +996,9 @@
   if (type === "edit") {
     productForm.value = { ...row };
     productIndex.value = index;
-    // 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� 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;
-        }
-      }
-    } catch (e) {
-      // 鍔犺浇澶辫触鏃朵繚鎸佸彲缂栬緫锛屼笉涓柇寮圭獥
-      console.error("鍔犺浇浜у搧瑙勬牸鍨嬪彿澶辫触", e);
-    }
   }
   productFormVisible.value = true;
+  getProductOptions();
 };
 // 鎻愪氦浜у搧琛ㄥ崟
 const submitProduct = () => {
@@ -1130,6 +1074,21 @@
   proxy.resetForm("productFormRef");
   productFormVisible.value = false;
 };
+// 瀵煎叆
+const handleImport = () => {
+  importUpload.title = "瀵煎叆閿�鍞彴璐�";
+  importUpload.open = true;
+  if (importUploadRef.value) {
+    importUploadRef.value.clearFiles();
+  }
+};
+
+// 鎻愪氦瀵煎叆鏂囦欢
+const submitImportFile = () => {
+  importUpload.isUploading = true;
+  proxy.$refs["importUploadRef"].submit();
+};
+
 // 瀵煎嚭
 const handleOut = () => {
   ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�", "瀵煎嚭", {
@@ -1495,6 +1454,15 @@
 	const seconds = String(date.getSeconds()).padStart(2, "0");
 	return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
 };
+// 鑾峰彇褰撳墠鏃ユ湡骞舵牸寮忓寲涓� YYYY-MM-DD
+function getCurrentDate() {
+  const today = new Date();
+  const year = today.getFullYear();
+  const month = String(today.getMonth() + 1).padStart(2, "0"); // 鏈堜唤浠�0寮�濮�
+  const day = String(today.getDate()).padStart(2, "0");
+  return `${year}-${month}-${day}`;
+}
+
 // 璁$畻浜у搧鎬绘暟閲�
 const getTotalQuantity = (products) => {
   if (!products || products.length === 0) return '0';
@@ -1707,28 +1675,20 @@
  * @param row 涓嬭浇鏂囦欢鐨勭浉鍏充俊鎭璞�
  */
 const fileListRef = ref(null)
-const fileListDialogVisible = ref(false)
 const downLoadFile = (row) => {
   getSalesLedgerWithProducts({ id: row.id, type: 1 }).then((res) => {
-    if (fileListRef.value) {
-      fileListRef.value.open(res.salesLedgerFiles)
-      fileListDialogVisible.value = true
-    }
+    fileListRef.value.open(res.salesLedgerFiles)
   });
 }
 
 // 鎵撳紑鍙戣揣寮规
 const openDeliveryForm = (row) => {
-  getProductInventory({ salesLedgerId: row.id, type:1 }).then((res) => {
-    currentDeliveryRow.value = row;
-    deliveryForm.value = {
-      shippingDate: getCurrentDate(),
-      shippingCarNumber: "",
-    };
-    deliveryFormVisible.value = true;
-  }).catch(err => {
-    ElMessage.error(err.msg);
-  });
+  currentDeliveryRow.value = row;
+  deliveryForm.value = {
+    shippingDate: "", // 绉婚櫎榛樿鍊艰缃�
+    shippingCarNumber: "",
+  };
+  deliveryFormVisible.value = true;
 };
 
 // 鎻愪氦鍙戣揣琛ㄥ崟
@@ -1736,7 +1696,9 @@
   proxy.$refs["deliveryFormRef"].validate((valid) => {
     if (valid) {
       addShippingInfo({
-        salesLedgerId: currentDeliveryRow.value.id,
+        approverId:deliveryForm.value.approverId,
+        salesLedgerId: currentDeliveryRow.value.salesLedgerId,
+        salesLedgerProductId: currentDeliveryRow.value.id,
         shippingDate: deliveryForm.value.shippingDate,
         shippingCarNumber: deliveryForm.value.shippingCarNumber,
       })
@@ -1744,6 +1706,7 @@
           proxy.$modal.msgSuccess("鍙戣揣鎴愬姛");
           closeDeliveryDia();
           getList();
+          expandedRowKeys.value = [];
         })
         .catch(() => {
           proxy.$modal.msgError("鍙戣揣澶辫触锛岃閲嶈瘯");

--
Gitblit v1.9.3