From 1ef08126ca554a8cd4b9ba47d19dc3b790e2c018 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期二, 19 五月 2026 17:21:19 +0800
Subject: [PATCH] Merge branch 'dev-new_pro_OA' of http://114.132.189.42:9002/r/product-inventory-management into dev-new_pro_OA

---
 src/views/financialManagement/receivable/invoiceApply.vue |  602 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 497 insertions(+), 105 deletions(-)

diff --git a/src/views/financialManagement/receivable/invoiceApply.vue b/src/views/financialManagement/receivable/invoiceApply.vue
index e637a3e..ac691bc 100644
--- a/src/views/financialManagement/receivable/invoiceApply.vue
+++ b/src/views/financialManagement/receivable/invoiceApply.vue
@@ -6,19 +6,31 @@
       </el-form-item>
       <el-form-item label="瀹㈡埛:">
         <el-select v-model="filters.customerId" placeholder="璇烽�夋嫨瀹㈡埛" clearable style="width: 200px;">
-          <el-option v-for="item in customerList" :key="item.id" :label="item.name" :value="item.id" />
+          <el-option v-for="item in customerList" :key="item.id" :label="item.customerName" :value="item.id" />
         </el-select>
       </el-form-item>
-      <el-form-item label="鐘舵��:">
-        <el-select v-model="filters.status" placeholder="璇烽�夋嫨鐘舵��" clearable style="width: 150px;">
-          <el-option label="寰呭鏍�" value="pending" />
-          <el-option label="宸插鏍�" value="approved" />
-          <el-option label="宸查┏鍥�" value="rejected" />
-          <el-option label="宸插紑绁�" value="invoiced" />
+      <el-form-item label="瀹℃牳鐘舵��:">
+        <el-select v-model="filters.status" placeholder="璇烽�夋嫨瀹℃牳鐘舵��" clearable style="width: 150px;">
+          <el-option label="寰呭鏍�" :value="0" />
+          <el-option label="瀹℃牳閫氳繃" :value="1" />
+          <el-option label="瀹℃牳涓嶉�氳繃" :value="2" />
         </el-select>
+      </el-form-item>
+      <el-form-item label="鐢宠鏃ユ湡:">
+        <el-date-picker
+          v-model="filters.dateRange"
+          type="daterange"
+          value-format="YYYY-MM-DD"
+          format="YYYY-MM-DD"
+          range-separator="鑷�"
+          start-placeholder="寮�濮嬫棩鏈�"
+          end-placeholder="缁撴潫鏃ユ湡"
+          clearable
+          style="width: 240px;"
+        />
       </el-form-item>
       <el-form-item>
-        <el-button type="primary" @click="getTableData">鎼滅储</el-button>
+        <el-button type="primary" @click="onSearch">鎼滅储</el-button>
         <el-button @click="resetFilters">閲嶇疆</el-button>
       </el-form-item>
     </el-form>
@@ -27,12 +39,13 @@
         <div></div>
         <div>
           <el-button type="primary" @click="add" icon="Plus">鏂板鐢宠</el-button>
-          <el-button @click="handleBatchApply" icon="Document" :disabled="selectedRows.length === 0">鎵归噺鐢宠</el-button>
+          <el-button type="success" @click="handleExport" icon="Download">瀵煎嚭寮�绁ㄧ敵璇�</el-button>
         </div>
       </div>
       <PIMTable
         rowKey="id"
         isSelection
+        v-loading="tableLoading"
         :column="columns"
         :tableData="dataList"
         :page="{
@@ -50,29 +63,80 @@
           <span>{{ row.taxRate }}%</span>
         </template>
         <template #status="{ row }">
-          <el-tag :type="getStatusType(row.status)">{{ getStatusLabel(row.status) }}</el-tag>
+          <el-tag :type="getStatusType(row.status)" effect="light" round>
+            {{ getStatusLabel(row.status) }}
+          </el-tag>
         </template>
         <template #operation="{ row }">
           <el-button type="primary" link @click="view(row)">鏌ョ湅</el-button>
-          <el-button type="primary" link @click="edit(row)" v-if="row.status === 'pending'">缂栬緫</el-button>
-          <el-button type="success" link @click="handleAudit(row)" v-if="row.status === 'pending'">瀹℃牳</el-button>
-          <el-button type="warning" link @click="handleInvoice(row)" v-if="row.status === 'approved'">寮�绁�</el-button>
+          <el-button type="primary" link @click="edit(row)" v-if="isPendingStatus(row.status)">缂栬緫</el-button>
+          <el-button type="danger" link @click="handleDelete(row)" v-if="isPendingStatus(row.status)">鍒犻櫎</el-button>
+          <el-button type="success" link @click="handleAudit(row)" v-if="isPendingStatus(row.status)">瀹℃牳</el-button>
+          <!-- <el-button type="warning" link @click="handleInvoice(row)" v-if="isApprovedStatus(row.status)">寮�绁�</el-button> -->
         </template>
       </PIMTable>
     </div>
 
-    <el-dialog :title="dialogTitle" v-model="dialogVisible" width="800px" append-to-body>
+    <FormDialog
+      :title="dialogTitle"
+      v-model="dialogVisible"
+      width="800px"
+      :operation-type="isView ? 'detail' : ''"
+      @confirm="submitForm"
+      @cancel="closeDialog"
+    >
       <el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
-        <el-row :gutter="20">
+        <el-row v-if="isView" :gutter="20">
           <el-col :span="12">
+            <el-form-item label="瀹℃牳鐘舵��">
+              <el-tag :type="getStatusType(form.status)" effect="light" round>
+                {{ getStatusLabel(form.status) }}
+              </el-tag>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-row :gutter="20">
+          <el-col :span="24">
             <el-form-item label="鐢宠鍗曞彿" prop="applyCode">
               <el-input v-model="form.applyCode" placeholder="绯荤粺鑷姩鐢熸垚" disabled />
             </el-form-item>
           </el-col>
+        </el-row>
+        <el-row :gutter="20">
           <el-col :span="12">
             <el-form-item label="瀹㈡埛" prop="customerId">
-              <el-select v-model="form.customerId" placeholder="璇烽�夋嫨瀹㈡埛" style="width: 100%;" :disabled="isEdit">
-                <el-option v-for="item in customerList" :key="item.id" :label="item.name" :value="item.id" />
+              <el-select
+                v-model="form.customerId"
+                placeholder="璇烽�夋嫨瀹㈡埛"
+                style="width: 100%;"
+                :disabled="isEdit || isView"
+                filterable
+                @change="handleCustomerChange"
+              >
+                <el-option v-for="item in customerList" :key="item.id" :label="item.customerName" :value="item.id" />
+              </el-select>
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="鍑哄簱鍗曞彿" prop="outboundBatchNos">
+              <el-select
+                v-model="form.outboundBatchNos"
+                multiple
+                collapse-tags
+                collapse-tags-tooltip
+                filterable
+                placeholder="璇峰厛閫夋嫨瀹㈡埛"
+                style="width: 100%;"
+                :disabled="!form.customerId || isView"
+                :loading="outboundBatchLoading"
+                @change="handleOutboundBatchChange"
+              >
+                <el-option
+                  v-for="item in outboundBatchOptions"
+                  :key="item.value"
+                  :label="item.label"
+                  :value="item.value"
+                />
               </el-select>
             </el-form-item>
           </el-col>
@@ -80,17 +144,25 @@
         <el-row :gutter="20">
           <el-col :span="12">
             <el-form-item label="寮�绁ㄩ噾棰�" prop="amount">
-              <el-input-number v-model="form.amount" :min="0" :precision="2" style="width: 100%;" />
+              <el-input-number
+                v-model="form.amount"
+                :min="0"
+                :precision="2"
+                :disabled="isView"
+                style="width: 100%;"
+                placeholder="鏍规嵁鎵�閫夊嚭搴撳崟鑷姩姹囨�伙紝鍙慨鏀�"
+              />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="绋庣巼" prop="taxRate">
-              <el-select v-model="form.taxRate" placeholder="璇烽�夋嫨绋庣巼" style="width: 100%;">
-                <el-option label="0%" :value="0" />
-                <el-option label="3%" :value="3" />
-                <el-option label="6%" :value="6" />
-                <el-option label="9%" :value="9" />
-                <el-option label="13%" :value="13" />
+              <el-select v-model="form.taxRate" placeholder="璇烽�夋嫨绋庣巼" style="width: 100%;" :disabled="isView">
+                <el-option
+                  v-for="dict in tax_rate"
+                  :key="dict.value"
+                  :label="dict.label"
+                  :value="Number(dict.value)"
+                />
               </el-select>
             </el-form-item>
           </el-col>
@@ -98,7 +170,7 @@
         <el-row :gutter="20">
           <el-col :span="12">
             <el-form-item label="鍙戠エ绫诲瀷" prop="invoiceType">
-              <el-select v-model="form.invoiceType" placeholder="璇烽�夋嫨鍙戠エ绫诲瀷" style="width: 100%;">
+              <el-select v-model="form.invoiceType" placeholder="璇烽�夋嫨鍙戠エ绫诲瀷" style="width: 100%;" :disabled="isView">
                 <el-option label="澧炲�肩◣涓撶敤鍙戠エ" value="special" />
                 <el-option label="澧炲�肩◣鏅�氬彂绁�" value="normal" />
                 <el-option label="鐢靛瓙鍙戠エ" value="electronic" />
@@ -107,37 +179,58 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="鐢宠鏃ユ湡" prop="applyDate">
-              <el-date-picker v-model="form.applyDate" type="date" placeholder="閫夋嫨鏃ユ湡" value-format="YYYY-MM-DD" style="width: 100%;" />
+              <el-date-picker
+                v-model="form.applyDate"
+                type="date"
+                placeholder="閫夋嫨鏃ユ湡"
+                value-format="YYYY-MM-DD"
+                style="width: 100%;"
+                :disabled="isView"
+              />
             </el-form-item>
           </el-col>
         </el-row>
         <el-form-item label="鍙戠エ鍐呭" prop="content">
-          <el-input v-model="form.content" type="textarea" :rows="3" placeholder="璇疯緭鍏ュ彂绁ㄥ唴瀹�" />
+          <el-input v-model="form.content" type="textarea" :rows="3" placeholder="璇疯緭鍏ュ彂绁ㄥ唴瀹�" :disabled="isView" />
         </el-form-item>
         <el-form-item label="澶囨敞" prop="remark">
-          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="璇疯緭鍏ュ娉�" />
+          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="璇疯緭鍏ュ娉�" :disabled="isView" />
         </el-form-item>
       </el-form>
-      <template #footer>
-        <el-button @click="dialogVisible = false">鍙栨秷</el-button>
-        <el-button type="primary" @click="submitForm">纭畾</el-button>
+      <template v-if="!isView" #footer>
+        <el-button type="primary" :loading="submitLoading" @click="submitForm">纭畾</el-button>
+        <el-button @click="closeDialog">鍙栨秷</el-button>
       </template>
-    </el-dialog>
+    </FormDialog>
   </div>
 </template>
 
 <script setup>
-import { ref, reactive, onMounted } from "vue";
+import { ref, reactive, onMounted, getCurrentInstance } from "vue";
 import { ElMessage, ElMessageBox } from "element-plus";
+import FormDialog from "@/components/Dialog/FormDialog.vue";
+import { listCustomer } from "@/api/basicData/customer.js";
+import {
+  getOutboundBatchesByCustomer,
+  addAccountInvoiceApplication,
+  listPageAccountInvoiceApplication,
+  auditAccountInvoiceApplication,
+  updateAccountInvoiceApplication,
+  deleteAccountInvoiceApplication,
+} from "@/api/financialManagement/invoiceApply.js";
 
 defineOptions({
   name: "寮�绁ㄧ敵璇�",
 });
 
+const { proxy } = getCurrentInstance();
+const { tax_rate } = proxy.useDict("tax_rate");
+
 const filters = reactive({
   applyCode: "",
   customerId: "",
   status: "",
+  dateRange: [],
 });
 
 const pagination = reactive({
@@ -149,32 +242,149 @@
 const columns = [
   { label: "鐢宠鍗曞彿", prop: "applyCode", width: "150" },
   { label: "瀹㈡埛鍚嶇О", prop: "customerName", width: "180" },
-  { label: "寮�绁ㄩ噾棰�", prop: "amount", slot: "amount" },
-  { label: "绋庣巼", prop: "taxRate", slot: "taxRate" },
+  { label: "寮�绁ㄩ噾棰�", prop: "amount", dataType: "slot", slot: "amount" },
+  { label: "绋庣巼", prop: "taxRate", dataType: "slot", slot: "taxRate" },
   { label: "鍙戠エ绫诲瀷", prop: "invoiceTypeLabel", width: "130" },
   { label: "鐢宠鏃ユ湡", prop: "applyDate", width: "120" },
-  { label: "鐘舵��", prop: "status", slot: "status" },
-  { label: "鎿嶄綔", prop: "operation", slot: "operation", width: "200", fixed: "right" },
+  { label: "瀹℃牳鐘舵��", prop: "status", dataType: "slot", slot: "status", width: "110", align: "center" },
+  { label: "鎿嶄綔", prop: "operation", dataType: "slot", slot: "operation", width: "260", fixed: "right" },
 ];
 
 const dataList = ref([]);
+const tableLoading = ref(false);
 const selectedRows = ref([]);
 const dialogVisible = ref(false);
 const dialogTitle = ref("");
 const formRef = ref(null);
 const isEdit = ref(false);
+const isView = ref(false);
 const currentId = ref(null);
 
-const customerList = [
-  { id: 1, name: "鍖椾含绉戞妧鏈夐檺鍏徃" },
-  { id: 2, name: "涓婃捣璐告槗鍏徃" },
-  { id: 3, name: "骞垮窞瀹炰笟鏈夐檺鍏徃" },
-  { id: 4, name: "娣卞湷鐢靛瓙鍏徃" },
-];
+const closeDialog = () => {
+  dialogVisible.value = false;
+  isView.value = false;
+  isEdit.value = false;
+};
+
+const customerList = ref([]);
+const outboundBatchOptions = ref([]);
+const outboundBatchLoading = ref(false);
+
+const getCustomerList = () => {
+  listCustomer({ current: -1, size: -1, type: 0 }).then((res) => {
+    if (res.code === 200) {
+      customerList.value = res.data?.records || [];
+    }
+  });
+};
+
+const normalizeOutboundBatchOptions = (data) => {
+  const list = Array.isArray(data) ? data : [];
+  return list.map((item, index) => {
+    if (typeof item === "string" || typeof item === "number") {
+      const text = String(item);
+      return { label: text, value: text, outboundAmount: 0 };
+    }
+    const label =
+      item.outboundBatches ??
+      item.batchNo ??
+      item.shippingNo ??
+      item.outboundNo ??
+      item.label ??
+      `鍑哄簱鍗�${index + 1}`;
+    const value = item.id ?? item.stockOutRecordId ?? item.stockOutRecordIds ?? label;
+    const outboundAmount = Number(item.outboundAmount) || 0;
+    const taxRate =
+      item.taxRate !== undefined && item.taxRate !== null && item.taxRate !== ""
+        ? Number(item.taxRate)
+        : undefined;
+    return { label: String(label), value, outboundAmount, taxRate };
+  });
+};
+
+const getSelectedOutboundOptions = () => {
+  const selected = form.outboundBatchNos || [];
+  return outboundBatchOptions.value.filter((opt) => selected.includes(opt.value));
+};
+
+/** 鏍¢獙鎵�閫夊嚭搴撳崟绋庣巼鏄惁涓�鑷达紝涓�鑷村垯鍥炲~ form.taxRate */
+const checkTaxRateConsistency = (showMessage = true) => {
+  const selected = getSelectedOutboundOptions();
+  if (selected.length === 0) return true;
+
+  const withTaxRate = selected.filter(
+    (opt) => opt.taxRate !== undefined && opt.taxRate !== null && !Number.isNaN(opt.taxRate)
+  );
+  if (withTaxRate.length === 0) return true;
+
+  const uniqueRates = [...new Set(withTaxRate.map((opt) => Number(opt.taxRate)))];
+  if (uniqueRates.length > 1) {
+    if (showMessage) {
+      const detail = withTaxRate.map((opt) => `${opt.label}(${opt.taxRate}%)`).join("銆�");
+      ElMessage.error(`鎵�閫夊嚭搴撳崟绋庣巼涓嶄竴鑷达紝鏃犳硶寮�绁細${detail}`);
+    }
+    return false;
+  }
+
+  form.taxRate = uniqueRates[0];
+  return true;
+};
+
+/** 鏍规嵁鎵�閫夊嚭搴撳崟姹囨�� outboundAmount 浣滀负寮�绁ㄩ噾棰� */
+const syncInvoiceAmount = () => {
+  const selected = form.outboundBatchNos || [];
+  const sum = outboundBatchOptions.value
+    .filter((opt) => selected.includes(opt.value))
+    .reduce((acc, opt) => acc + (Number(opt.outboundAmount) || 0), 0);
+  form.amount = sum > 0 ? Number(sum.toFixed(2)) : 0;
+};
+
+const handleOutboundBatchChange = () => {
+  syncInvoiceAmount();
+  checkTaxRateConsistency();
+};
+
+const loadOutboundBatches = (customerId, keepSelected = false) => {
+  if (!customerId) {
+    outboundBatchOptions.value = [];
+    if (!keepSelected) {
+      form.outboundBatchNos = [];
+      form.amount = 0;
+    }
+    return Promise.resolve();
+  }
+  outboundBatchLoading.value = true;
+  return getOutboundBatchesByCustomer({ customerId })
+    .then((res) => {
+      if (res.code === 200) {
+        const list = res.data?.records ?? res.data ?? [];
+        outboundBatchOptions.value = normalizeOutboundBatchOptions(list);
+      } else {
+        outboundBatchOptions.value = [];
+      }
+    })
+    .catch(() => {
+      outboundBatchOptions.value = [];
+    })
+    .finally(() => {
+      outboundBatchLoading.value = false;
+      if (keepSelected) {
+        syncInvoiceAmount();
+        checkTaxRateConsistency(false);
+      }
+    });
+};
+
+const handleCustomerChange = (customerId) => {
+  form.outboundBatchNos = [];
+  form.amount = 0;
+  loadOutboundBatches(customerId);
+};
 
 const form = reactive({
   applyCode: "",
   customerId: "",
+  outboundBatchNos: [],
   amount: 0,
   taxRate: 13,
   invoiceType: "special",
@@ -185,17 +395,92 @@
 
 const rules = {
   customerId: [{ required: true, message: "璇烽�夋嫨瀹㈡埛", trigger: "change" }],
+  outboundBatchNos: [{ required: true, type: "array", min: 1, message: "璇烽�夋嫨鍑哄簱鍗曞彿", trigger: "change" }],
   amount: [{ required: true, message: "璇疯緭鍏ュ紑绁ㄩ噾棰�", trigger: "blur" }],
   taxRate: [{ required: true, message: "璇烽�夋嫨绋庣巼", trigger: "change" }],
   invoiceType: [{ required: true, message: "璇烽�夋嫨鍙戠エ绫诲瀷", trigger: "change" }],
   applyDate: [{ required: true, message: "璇烽�夋嫨鐢宠鏃ユ湡", trigger: "change" }],
 };
 
-const mockData = [
-  { id: 1, applyCode: "KP2024001", customerId: 1, customerName: "鍖椾含绉戞妧鏈夐檺鍏徃", amount: 5000, taxRate: 13, invoiceType: "special", invoiceTypeLabel: "澧炲�肩◣涓撶敤鍙戠エ", applyDate: "2024-01-15", status: "pending", content: "杞欢鏈嶅姟璐�", remark: "" },
-  { id: 2, applyCode: "KP2024002", customerId: 2, customerName: "涓婃捣璐告槗鍏徃", amount: 8000, taxRate: 13, invoiceType: "normal", invoiceTypeLabel: "澧炲�肩◣鏅�氬彂绁�", applyDate: "2024-01-16", status: "approved", content: "鍟嗗搧閿�鍞�", remark: "" },
-  { id: 3, applyCode: "KP2024003", customerId: 3, customerName: "骞垮窞瀹炰笟鏈夐檺鍏徃", amount: 12000, taxRate: 6, invoiceType: "electronic", invoiceTypeLabel: "鐢靛瓙鍙戠エ", applyDate: "2024-01-18", status: "invoiced", content: "鎶�鏈湇鍔¤垂", remark: "" },
-];
+const INVOICE_TYPE_LABEL_MAP = {
+  special: "澧炲�肩◣涓撶敤鍙戠エ",
+  normal: "澧炲�肩◣鏅�氬彂绁�",
+  electronic: "鐢靛瓙鍙戠エ",
+};
+
+/** 瀹℃牳鐘舵�侊細0寰呭鏍� 1瀹℃牳閫氳繃 2瀹℃牳涓嶉�氳繃 */
+const STATUS_LABEL_MAP = {
+  0: "寰呭鏍�",
+  1: "瀹℃牳閫氳繃",
+  2: "瀹℃牳涓嶉�氳繃",
+};
+
+const STATUS_TYPE_MAP = {
+  0: "warning",
+  1: "success",
+  2: "danger",
+};
+
+const getInvoiceTypeLabel = (type) => INVOICE_TYPE_LABEL_MAP[type] || type || "";
+
+const normalizeStatus = (status) => {
+  if (status === undefined || status === null || status === "") return status;
+  const num = Number(status);
+  return Number.isNaN(num) ? status : num;
+};
+
+const isPendingStatus = (status) => normalizeStatus(status) === 0;
+const isApprovedStatus = (status) => normalizeStatus(status) === 1;
+
+const normalizeTableRow = (row) => ({
+  ...row,
+  applyCode: row.invoiceApplicationNo ?? row.applyCode,
+  amount: row.invoiceAmount ?? row.amount,
+  content: row.invoiceContent ?? row.content,
+  status: normalizeStatus(row.status ?? row.auditStatus),
+  invoiceTypeLabel: row.invoiceTypeLabel || getInvoiceTypeLabel(row.invoiceType),
+});
+
+const appendFilterParams = (params) => {
+  if (filters.applyCode) {
+    params.invoiceApplicationNo = filters.applyCode;
+  }
+  if (filters.customerId) {
+    params.customerId = filters.customerId;
+  }
+  if (filters.status !== "" && filters.status != null) {
+    params.status = filters.status;
+  }
+  if (filters.dateRange?.length === 2) {
+    params.startDate = filters.dateRange[0];
+    params.endDate = filters.dateRange[1];
+  }
+  return params;
+};
+
+const buildListParams = () => {
+  return appendFilterParams({
+    current: pagination.currentPage,
+    size: pagination.pageSize,
+  });
+};
+
+const buildExportParams = () => {
+  const params = appendFilterParams({});
+  if (selectedRows.value.length > 0) {
+    params.ids = selectedRows.value.map((row) => row.id).join(",");
+  }
+  return params;
+};
+
+const handleExport = () => {
+  const params = buildExportParams();
+  const filename =
+    selectedRows.value.length > 0
+      ? `寮�绁ㄧ敵璇穇宸查��${selectedRows.value.length}鏉${Date.now()}.xlsx`
+      : `寮�绁ㄧ敵璇穇${Date.now()}.xlsx`;
+  proxy.download("/accountInvoiceApplication/exportAccountInvoiceApplication", params, filename);
+};
 
 const formatMoney = (value) => {
   if (value === undefined || value === null) return "0.00";
@@ -203,34 +488,54 @@
 };
 
 const getStatusLabel = (status) => {
-  const map = { pending: "寰呭鏍�", approved: "宸插鏍�", rejected: "宸查┏鍥�", invoiced: "宸插紑绁�" };
-  return map[status] || status;
+  const num = normalizeStatus(status);
+  if (num === 0 || num === 1 || num === 2) {
+    return STATUS_LABEL_MAP[num];
+  }
+  return "-";
 };
 
 const getStatusType = (status) => {
-  const map = { pending: "warning", approved: "success", rejected: "danger", invoiced: "primary" };
-  return map[status] || "";
+  const num = normalizeStatus(status);
+  if (num === 0 || num === 1 || num === 2) {
+    return STATUS_TYPE_MAP[num];
+  }
+  return "info";
+};
+
+const onSearch = () => {
+  pagination.currentPage = 1;
+  getTableData();
 };
 
 const getTableData = () => {
-  let result = [...mockData];
-  if (filters.applyCode) {
-    result = result.filter(item => item.applyCode.includes(filters.applyCode));
-  }
-  if (filters.customerId) {
-    result = result.filter(item => item.customerId === filters.customerId);
-  }
-  if (filters.status) {
-    result = result.filter(item => item.status === filters.status);
-  }
-  pagination.total = result.length;
-  dataList.value = result.slice((pagination.currentPage - 1) * pagination.pageSize, pagination.currentPage * pagination.pageSize);
+  tableLoading.value = true;
+  listPageAccountInvoiceApplication(buildListParams())
+    .then((res) => {
+      const ok = res.code === 200 || res.code === 0;
+      if (ok && res.data) {
+        pagination.total = res.data.total ?? 0;
+        dataList.value = (res.data.records ?? []).map(normalizeTableRow);
+      } else {
+        ElMessage.error(res.msg || "鏌ヨ澶辫触");
+        dataList.value = [];
+        pagination.total = 0;
+      }
+    })
+    .catch(() => {
+      dataList.value = [];
+      pagination.total = 0;
+    })
+    .finally(() => {
+      tableLoading.value = false;
+    });
 };
 
 const resetFilters = () => {
   filters.applyCode = "";
   filters.customerId = "";
   filters.status = "";
+  filters.dateRange = [];
   pagination.currentPage = 1;
   getTableData();
 };
@@ -245,12 +550,28 @@
   selectedRows.value = selection;
 };
 
+const fillFormFromRow = (row) => {
+  const outboundBatchNos = Array.isArray(row.outboundBatchNos)
+    ? row.outboundBatchNos
+    : parseStockOutRecordIds(row.stockOutRecordIds ?? row.outboundBatches);
+  Object.assign(form, {
+    ...row,
+    applyCode: row.applyCode ?? row.invoiceApplicationNo ?? "",
+    amount: row.amount ?? row.invoiceAmount,
+    content: row.content ?? row.invoiceContent,
+    status: normalizeStatus(row.status ?? row.auditStatus),
+    outboundBatchNos,
+  });
+};
+
 const add = () => {
   isEdit.value = false;
+  isView.value = false;
   dialogTitle.value = "鏂板寮�绁ㄧ敵璇�";
   Object.assign(form, {
     applyCode: "KP" + Date.now().toString().slice(-8),
     customerId: "",
+    outboundBatchNos: [],
     amount: 0,
     taxRate: 13,
     invoiceType: "special",
@@ -258,44 +579,109 @@
     content: "",
     remark: "",
   });
+  outboundBatchOptions.value = [];
   dialogVisible.value = true;
+};
+
+const parseStockOutRecordIds = (value) => {
+  if (!value) return [];
+  if (Array.isArray(value)) return value;
+  return String(value)
+    .split(/[,锛宂/)
+    .map((s) => s.trim())
+    .filter(Boolean)
+    .map((s) => (/^\d+$/.test(s) ? Number(s) : s));
+};
+
+const buildSubmitPayload = (forUpdate = false) => {
+  const payload = {
+    customerId: form.customerId,
+    stockOutRecordIds: (form.outboundBatchNos || []).join(","),
+    invoiceApplicationNo: form.applyCode || "",
+    invoiceType: form.invoiceType,
+    applyDate: form.applyDate,
+    invoiceContent: form.content,
+    remark: form.remark || "",
+    invoiceAmount: form.amount,
+    taxRate: form.taxRate,
+    status: 0,
+  };
+  if (forUpdate) {
+    payload.id = currentId.value;
+  }
+  return payload;
 };
 
 const edit = (row) => {
   isEdit.value = true;
+  isView.value = false;
   currentId.value = row.id;
   dialogTitle.value = "缂栬緫寮�绁ㄧ敵璇�";
-  Object.assign(form, row);
+  fillFormFromRow(row);
   dialogVisible.value = true;
+  loadOutboundBatches(form.customerId, true);
 };
 
 const view = (row) => {
-  ElMessage.info(`鏌ョ湅鐢宠鍗�: ${row.applyCode}`);
+  isView.value = true;
+  isEdit.value = false;
+  dialogTitle.value = "鏌ョ湅寮�绁ㄧ敵璇�";
+  fillFormFromRow(row);
+  dialogVisible.value = true;
+  loadOutboundBatches(form.customerId, true);
+};
+
+const submitAudit = (row, status) => {
+  auditAccountInvoiceApplication({ id: row.id, status })
+    .then((res) => {
+      if (res.code === 200) {
+        ElMessage.success(status === 1 ? "瀹℃牳閫氳繃" : "瀹℃牳涓嶉�氳繃");
+        getTableData();
+      } else {
+        ElMessage.error(res.msg || "瀹℃壒澶辫触");
+      }
+    })
+    .catch(() => {
+      ElMessage.error("瀹℃壒澶辫触");
+    });
+};
+
+const handleDelete = (row) => {
+  ElMessageBox.confirm(`纭鍒犻櫎鐢宠鍗曘��${row.applyCode ?? row.invoiceApplicationNo}銆嶅悧锛焋, "鎻愮ず", {
+    confirmButtonText: "纭畾",
+    cancelButtonText: "鍙栨秷",
+    type: "warning",
+  }).then(() => {
+    deleteAccountInvoiceApplication([row.id])
+      .then((res) => {
+        if (res.code === 200) {
+          ElMessage.success("鍒犻櫎鎴愬姛");
+          getTableData();
+        } else {
+          ElMessage.error(res.msg || "鍒犻櫎澶辫触");
+        }
+      })
+      .catch(() => {
+        ElMessage.error("鍒犻櫎澶辫触");
+      });
+  });
 };
 
 const handleAudit = (row) => {
-  ElMessageBox.confirm("纭瀹℃牳閫氳繃璇ュ紑绁ㄧ敵璇峰悧锛�", "鎻愮ず", {
-    confirmButtonText: "閫氳繃",
-    cancelButtonText: "椹冲洖",
+  ElMessageBox.confirm("璇烽�夋嫨瀹℃壒缁撴灉", "寮�绁ㄧ敵璇峰鏍�", {
+    confirmButtonText: "瀹℃牳閫氳繃",
+    cancelButtonText: "瀹℃牳涓嶉�氳繃",
     distinguishCancelAndClose: true,
     type: "warning",
-  }).then(() => {
-    const index = mockData.findIndex(item => item.id === row.id);
-    if (index !== -1) {
-      mockData[index].status = "approved";
-    }
-    ElMessage.success("瀹℃牳閫氳繃");
-    getTableData();
-  }).catch((action) => {
-    if (action === "cancel") {
-      const index = mockData.findIndex(item => item.id === row.id);
-      if (index !== -1) {
-        mockData[index].status = "rejected";
+  })
+    .then(() => {
+      submitAudit(row, 1);
+    })
+    .catch((action) => {
+      if (action === "cancel") {
+        submitAudit(row, 2);
       }
-      ElMessage.warning("宸查┏鍥�");
-      getTableData();
-    }
-  });
+    });
 };
 
 const handleInvoice = (row) => {
@@ -304,10 +690,6 @@
     cancelButtonText: "鍙栨秷",
     type: "info",
   }).then(() => {
-    const index = mockData.findIndex(item => item.id === row.id);
-    if (index !== -1) {
-      mockData[index].status = "invoiced";
-    }
     ElMessage.success("寮�绁ㄥ畬鎴�");
     getTableData();
   });
@@ -317,29 +699,39 @@
   ElMessage.success(`鎵归噺鐢宠 ${selectedRows.value.length} 鏉¤褰昤);
 };
 
+const submitLoading = ref(false);
+
 const submitForm = () => {
   formRef.value.validate((valid) => {
-    if (valid) {
-      const customer = customerList.find(item => item.id === form.customerId);
-      const invoiceTypeMap = { special: "澧炲�肩◣涓撶敤鍙戠エ", normal: "澧炲�肩◣鏅�氬彂绁�", electronic: "鐢靛瓙鍙戠エ" };
-      if (isEdit.value) {
-        const index = mockData.findIndex(item => item.id === currentId.value);
-        if (index !== -1) {
-          mockData[index] = { ...mockData[index], ...form, customerName: customer?.name, invoiceTypeLabel: invoiceTypeMap[form.invoiceType] };
+    if (!valid) return;
+    if (!checkTaxRateConsistency()) return;
+
+    submitLoading.value = true;
+    const request = isEdit.value
+      ? updateAccountInvoiceApplication(buildSubmitPayload(true))
+      : addAccountInvoiceApplication(buildSubmitPayload());
+
+    request
+      .then((res) => {
+        if (res.code === 200) {
+          ElMessage.success(isEdit.value ? "淇敼鎴愬姛" : "鏂板鎴愬姛");
+          closeDialog();
+          getTableData();
+        } else {
+          ElMessage.error(res.msg || (isEdit.value ? "淇敼澶辫触" : "鏂板澶辫触"));
         }
-        ElMessage.success("缂栬緫鎴愬姛");
-      } else {
-        const newId = mockData.length > 0 ? Math.max(...mockData.map(item => item.id)) + 1 : 1;
-        mockData.push({ id: newId, ...form, customerName: customer?.name, invoiceTypeLabel: invoiceTypeMap[form.invoiceType], status: "pending" });
-        ElMessage.success("鏂板鎴愬姛");
-      }
-      dialogVisible.value = false;
-      getTableData();
-    }
+      })
+      .catch(() => {
+        ElMessage.error(isEdit.value ? "淇敼澶辫触" : "鏂板澶辫触");
+      })
+      .finally(() => {
+        submitLoading.value = false;
+      });
   });
 };
 
 onMounted(() => {
+  getCustomerList();
   getTableData();
 });
 </script>

--
Gitblit v1.9.3