From 8f7438e43f48985401befd7a25e5598d74b32ba2 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期一, 19 一月 2026 14:05:56 +0800
Subject: [PATCH] Merge branch 'dev_New' of http://114.132.189.42:9002/r/product-inventory-management into dev_New

---
 src/views/salesManagement/salesLedger/index.vue |  303 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 297 insertions(+), 6 deletions(-)

diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 6fa5859..e46ce5f 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -26,6 +26,7 @@
           <el-button type="primary" @click="openForm('add')">
             鏂板鍙拌处
           </el-button>
+          <el-button @click="handleImport">瀵煎叆</el-button>
           <el-button @click="handleOut">瀵煎嚭</el-button>
           <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>
           <el-button type="primary" plain @click="handlePrint">鎵撳嵃</el-button>
@@ -75,8 +76,8 @@
           </template>
         </el-table-column>
         <el-table-column label="鍙戣揣鏃ユ湡" prop="shippingDate" width="120" 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 label="褰曞叆鏃ユ湡" prop="entryDate" width="120" 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>
@@ -98,6 +99,11 @@
       @confirm="submitForm"
       @cancel="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">
@@ -203,6 +209,62 @@
         </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>
+      </template>
+    </el-dialog>
     <FormDialog 
       v-model="productFormVisible" 
       :title="productOperationType === 'add' ? '鏂板浜у搧' : '缂栬緫浜у搧'" 
@@ -448,19 +510,58 @@
 			</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 {
 	ledgerListPage,
 	productList,
@@ -576,6 +677,16 @@
 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);
@@ -594,6 +705,54 @@
   },
 });
 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) {
@@ -644,8 +803,10 @@
 };
 // 鑾峰彇浜у搧澶х被tree鏁版嵁
 const getProductOptions = () => {
-  productTreeList().then((res) => {
+  // 杩斿洖 Promise锛屼究浜庡湪缂栬緫浜у搧鏃剁瓑寰呭姞杞藉畬鎴�
+  return productTreeList().then((res) => {
     productOptions.value = convertIdToValue(res);
+    return productOptions.value;
   });
 };
 const formattedNumber = (row, column, cellValue) => {
@@ -695,6 +856,19 @@
 
     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) => {
@@ -746,6 +920,7 @@
   operationType.value = type;
   form.value = {};
   productData.value = [];
+  selectedQuotation.value = null;
   let userLists = await userListNoPage();
   userList.value = userLists.data;
   customerList().then((res) => {
@@ -774,6 +949,87 @@
   // });
   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);
@@ -847,16 +1103,36 @@
 
 const productIndex = ref(0);
 // 鎵撳紑浜у搧寮规
-const openProductForm = (type, row,index) => {
+const openProductForm = async (type, row, index) => {
   productOperationType.value = type;
   productForm.value = {};
   proxy.resetForm("productFormRef");
   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 = () => {
@@ -932,6 +1208,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("閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�", "瀵煎嚭", {

--
Gitblit v1.9.3