From f3cac4aa2db56d6017c1d1dc035bcfeaec76c3e2 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 05 十一月 2026 18:31:13 +0800
Subject: [PATCH] feat(crm): 投标保证金迁移到销售管理并接入销售台账

---
 src/views/erp/purchase/statement/index.vue |  531 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 358 insertions(+), 173 deletions(-)

diff --git a/src/views/erp/purchase/statement/index.vue b/src/views/erp/purchase/statement/index.vue
index fddb58b..3033b9c 100644
--- a/src/views/erp/purchase/statement/index.vue
+++ b/src/views/erp/purchase/statement/index.vue
@@ -2,25 +2,65 @@
 import type { Dayjs } from 'dayjs';
 
 import type { ErpSupplierStatementApi } from '#/api/erp/purchase/statement';
-import type { SrmSupplierApi } from '#/api/srm/supplier';
 
-import { onMounted, ref } from 'vue';
+import { computed, onMounted, ref } from 'vue';
 
+import { Page } from '@vben/common-ui';
 import { DICT_TYPE } from '@vben/constants';
 import { getDictLabel } from '@vben/hooks';
 
-import { message } from 'ant-design-vue';
+import {
+  Button,
+  Card,
+  Checkbox,
+  Col,
+  Empty,
+  Input,
+  RangePicker,
+  Row,
+  Spin,
+  Table,
+} from 'ant-design-vue';
 
-import { getSupplierStatement } from '#/api/erp/purchase/statement';
-import { getSupplierSimpleList } from '#/api/srm/supplier';
+import {
+  getSupplierStatement,
+  getSupplierStatementSummaryList,
+} from '#/api/erp/purchase/statement';
 
 defineOptions({ name: 'ErpSupplierStatement' });
 
-const supplierId = ref<number>();
 const dateRange = ref<[Dayjs, Dayjs]>();
-const supplierOptions = ref<SrmSupplierApi.SupplierVO[]>([]);
+const includeUnapproved = ref(false);
+const keyword = ref('');
+
+/** 宸︿晶锛氬悇渚涘簲鍟嗗線鏉ユ眹鎬� */
+const summaries = ref<ErpSupplierStatementApi.SupplierSummary[]>([]);
+const listLoading = ref(false);
+/** 褰撳墠閫変腑鐨勪緵搴斿晢 */
+const selectedId = ref<number>();
+/** 鍙充晶锛氬綋鍓嶄緵搴斿晢寰�鏉ユ槑缁� */
 const statement = ref<ErpSupplierStatementApi.Statement>();
-const loading = ref(false);
+const detailLoading = ref(false);
+
+const filteredSummaries = computed(() => {
+  const kw = keyword.value.trim().toLowerCase();
+  if (!kw) {
+    return summaries.value;
+  }
+  return summaries.value.filter(
+    (item) =>
+      (item.supplierName ?? '').toLowerCase().includes(kw) ||
+      (item.supplierCode ?? '').toLowerCase().includes(kw),
+  );
+});
+
+const selectedSummary = computed(() =>
+  summaries.value.find((item) => item.supplierId === selectedId.value),
+);
+
+const totalUnpaid = computed(() =>
+  summaries.value.reduce((sum, item) => sum + (item.unpaidAmount ?? 0), 0),
+);
 
 const orderColumns = [
   { title: '閲囪喘璁㈠崟鍙�', dataIndex: 'no', key: 'no', width: 170 },
@@ -58,7 +98,12 @@
     key: 'remainingPayable',
     width: 120,
   },
-  { title: '閲囪喘璁㈠崟', dataIndex: 'purchaseOrderNo', key: 'purchaseOrderNo', width: 160 },
+  {
+    title: '閲囪喘璁㈠崟',
+    dataIndex: 'purchaseOrderNo',
+    key: 'purchaseOrderNo',
+    width: 160,
+  },
 ];
 
 const paymentColumns = [
@@ -75,7 +120,13 @@
 ];
 
 function formatMoney(value?: number) {
-  return value === undefined || value === null ? '-' : Number(value).toFixed(2);
+  if (value === undefined || value === null) {
+    return '-';
+  }
+  return Number(value).toLocaleString('zh-CN', {
+    maximumFractionDigits: 2,
+    minimumFractionDigits: 2,
+  });
 }
 
 function getStatusLabel(status?: number) {
@@ -86,185 +137,319 @@
 }
 
 function getPaymentStatusLabel(status?: number) {
-  return (
-    ['鏈粯娆�', '閮ㄥ垎浠樻', '鍏ㄩ儴浠樻'][status ?? 0] ?? '-'
-  );
+  return ['鏈粯娆�', '閮ㄥ垎浠樻', '鍏ㄩ儴浠樻'][status ?? 0] ?? '-';
 }
 
-async function handleQuery() {
-  if (!supplierId.value) {
-    message.warning('璇烽�夋嫨渚涘簲鍟�');
+/** 缁勮鏃堕棿鑼冨洿鍙傛暟 */
+function buildTimeParams() {
+  const params: {
+    beginTime?: string;
+    endTime?: string;
+  } = {};
+  if (dateRange.value?.length === 2) {
+    params.beginTime = dateRange.value[0]!
+      .startOf('day')
+      .format('YYYY-MM-DD HH:mm:ss');
+    params.endTime = dateRange.value[1]!
+      .endOf('day')
+      .format('YYYY-MM-DD HH:mm:ss');
+  }
+  return params;
+}
+
+/** 鍔犺浇宸︿晶渚涘簲鍟嗘眹鎬伙紝榛樿閫変腑绗竴涓緵搴斿晢 */
+async function loadSummaries() {
+  listLoading.value = true;
+  try {
+    summaries.value =
+      (await getSupplierStatementSummaryList({
+        ...buildTimeParams(),
+        includeUnapprovedOrder: includeUnapproved.value,
+      })) ?? [];
+    const stillExists = summaries.value.some(
+      (item) => item.supplierId === selectedId.value,
+    );
+    if (!stillExists) {
+      selectedId.value = summaries.value[0]?.supplierId;
+    }
+    const targetId = selectedId.value;
+    if (targetId === undefined) {
+      statement.value = undefined;
+      return;
+    }
+    await loadDetail(targetId);
+  } finally {
+    listLoading.value = false;
+  }
+}
+
+/** 鐐瑰嚮宸︿晶渚涘簲鍟嗭紝鍔犺浇鍙充晶鏄庣粏 */
+async function handleSelect(supplierId: number) {
+  if (selectedId.value === supplierId && statement.value) {
     return;
   }
-  loading.value = true;
+  selectedId.value = supplierId;
+  await loadDetail(supplierId);
+}
+
+/** 鍔犺浇鎸囧畾渚涘簲鍟嗙殑寰�鏉ユ槑缁� */
+async function loadDetail(supplierId: number) {
+  detailLoading.value = true;
   try {
-    const params: {
-      supplierId: number;
-      beginTime?: string;
-      endTime?: string;
-    } = { supplierId: supplierId.value };
-    if (dateRange.value?.length === 2) {
-      params.beginTime = dateRange.value[0]!.startOf('day').format('YYYY-MM-DD HH:mm:ss');
-      params.endTime = dateRange.value[1]!.endOf('day').format('YYYY-MM-DD HH:mm:ss');
-    }
-    statement.value = await getSupplierStatement(params);
+    statement.value = await getSupplierStatement({
+      ...buildTimeParams(),
+      includeUnapprovedOrder: includeUnapproved.value,
+      supplierId,
+    });
   } finally {
-    loading.value = false;
+    detailLoading.value = false;
   }
 }
 
-onMounted(async () => {
-  supplierOptions.value = (await getSupplierSimpleList()) ?? [];
-});
+onMounted(loadSummaries);
 </script>
 
 <template>
   <Page auto-content-height>
-    <div class="p-4" :class="{ 'pointer-events-none opacity-60': loading }">
-      <div class="mb-4 flex flex-wrap items-center gap-3">
-        <span class="text-sm text-gray-500">渚涘簲鍟�</span>
-        <a-select
-          v-model:value="supplierId"
-          show-search
-          option-filter-prop="label"
-          placeholder="璇烽�夋嫨渚涘簲鍟�"
-          style="width: 260px"
-          :options="
-            supplierOptions.map((item) => ({
-              label: item.name,
-              value: item.id,
-            }))
-          "
-        />
-        <a-range-picker v-model:value="dateRange" />
-        <a-button type="primary" :loading="loading" @click="handleQuery">
-          鏌ヨ
-        </a-button>
-        <span v-if="statement?.supplierName" class="text-sm text-gray-600">
-          褰撳墠渚涘簲鍟嗭細{{ statement.supplierName }}
-        </span>
+    <div class="flex h-full gap-4">
+      <!-- 宸︿晶锛氫緵搴斿晢鎬昏锛岀偣鍑绘煡鐪嬪彸渚ф槑缁� -->
+      <div class="flex w-[360px] shrink-0 flex-col rounded-lg border">
+        <div class="border-b p-3">
+          <Input
+            v-model:value="keyword"
+            allow-clear
+            placeholder="鎼滅储渚涘簲鍟嗗悕绉� / 缂栫爜"
+          />
+          <div class="mt-2 flex items-center gap-2">
+            <RangePicker
+              v-model:value="dateRange"
+              class="min-w-0 flex-1"
+              size="small"
+            />
+          </div>
+          <div class="mt-2 flex items-center justify-between">
+            <Checkbox v-model:checked="includeUnapproved">
+              鍚湭瀹℃牳閲囪喘璁㈠崟
+            </Checkbox>
+            <Button
+              size="small"
+              type="primary"
+              :loading="listLoading"
+              @click="loadSummaries"
+            >
+              鏌ヨ
+            </Button>
+          </div>
+          <div class="mt-2 text-xs text-gray-500">
+            鍏� {{ filteredSummaries.length }} 涓緵搴斿晢锛屾湭浠樺悎璁�
+            <span class="font-medium text-red-600">
+              楼{{ formatMoney(totalUnpaid) }}
+            </span>
+          </div>
+        </div>
+        <div class="min-h-0 flex-1 overflow-y-auto p-2">
+          <Spin :spinning="listLoading">
+            <div
+              v-if="filteredSummaries.length === 0"
+              class="p-6 text-center text-sm text-gray-500"
+            >
+              {{
+                summaries.length > 0
+                  ? '娌℃湁鍖归厤鐨勪緵搴斿晢'
+                  : '鎵�閫夋椂闂磋寖鍥村唴娌℃湁渚涘簲鍟嗗線鏉�'
+              }}
+            </div>
+            <div
+              v-for="item in filteredSummaries"
+              :key="item.supplierId"
+              class="mb-2 cursor-pointer rounded-lg border p-3 transition-colors"
+              :class="
+                item.supplierId === selectedId
+                  ? 'border-blue-500 bg-blue-50'
+                  : 'hover:border-blue-300 hover:bg-gray-50'
+              "
+              @click="handleSelect(item.supplierId!)"
+            >
+              <div class="flex items-start justify-between gap-2">
+                <div class="min-w-0">
+                  <div class="truncate text-sm font-medium">
+                    {{ item.supplierName }}
+                  </div>
+                  <div class="text-xs text-gray-400">
+                    {{ item.supplierCode || '-' }}
+                  </div>
+                </div>
+                <div class="shrink-0 text-right">
+                  <div class="text-xs text-gray-500">鏈粯浣欓</div>
+                  <div
+                    class="text-sm font-semibold"
+                    :class="
+                      (item.unpaidAmount ?? 0) > 0
+                        ? 'text-red-600'
+                        : 'text-gray-700'
+                    "
+                  >
+                    {{ formatMoney(item.unpaidAmount) }}
+                  </div>
+                </div>
+              </div>
+              <div class="mt-2 grid grid-cols-3 gap-1 text-xs text-gray-500">
+                <span>閲囪喘 {{ formatMoney(item.totalPurchaseAmount) }}</span>
+                <span>寮�绁� {{ formatMoney(item.totalInvoiceAmount) }}</span>
+                <span>浠樻 {{ formatMoney(item.totalPaymentAmount) }}</span>
+              </div>
+            </div>
+          </Spin>
+        </div>
       </div>
 
-      <a-row :gutter="16" class="mb-4">
-        <a-col :span="6">
-          <a-card size="small">
-            <div class="text-gray-500">绱閲囪喘棰�</div>
-            <div class="text-2xl font-semibold">
-              {{ formatMoney(statement?.summary?.totalPurchaseAmount) }}
-            </div>
-          </a-card>
-        </a-col>
-        <a-col :span="6">
-          <a-card size="small">
-            <div class="text-gray-500">绱寮�绁ㄩ</div>
-            <div class="text-2xl font-semibold text-blue-600">
-              {{ formatMoney(statement?.summary?.totalInvoiceAmount) }}
-            </div>
-          </a-card>
-        </a-col>
-        <a-col :span="6">
-          <a-card size="small">
-            <div class="text-gray-500">绱浠樻棰�</div>
-            <div class="text-2xl font-semibold text-green-600">
-              {{ formatMoney(statement?.summary?.totalPaymentAmount) }}
-            </div>
-          </a-card>
-        </a-col>
-        <a-col :span="6">
-          <a-card size="small">
-            <div class="text-gray-500">鏈粯浣欓锛堝紑绁� - 浠樻锛�</div>
-            <div class="text-2xl font-semibold text-red-600">
-              {{ formatMoney(statement?.summary?.unpaidAmount) }}
-            </div>
-          </a-card>
-        </a-col>
-      </a-row>
+      <!-- 鍙充晶锛氬綋鍓嶄緵搴斿晢寰�鏉ユ槑缁� -->
+      <div class="min-w-0 flex-1 overflow-y-auto">
+        <Empty
+          v-if="!selectedId"
+          class="mt-20"
+          description="璇峰湪宸︿晶閫夋嫨渚涘簲鍟嗭紝鏌ョ湅寰�鏉ユ槑缁�"
+        />
+        <Spin v-else :spinning="detailLoading">
+          <div class="mb-4 flex flex-wrap items-center gap-2">
+            <span class="text-lg font-semibold">
+              {{ statement?.supplierName ?? selectedSummary?.supplierName }}
+            </span>
+            <span class="text-sm text-gray-500">
+              {{ selectedSummary?.supplierCode || '-' }}
+            </span>
+            <span class="text-xs text-gray-400">
+              閲囪喘 {{ selectedSummary?.orderCount ?? 0 }} 鍗� / 鏉ョエ
+              {{ selectedSummary?.invoiceCount ?? 0 }} 寮� / 浠樻
+              {{ selectedSummary?.paymentCount ?? 0 }} 绗�
+            </span>
+          </div>
 
-      <a-row :gutter="16">
-        <a-col :span="12">
-          <a-card title="閲囪喘璁㈠崟娴佹按锛堝惈寮�绁ㄩ噾棰濓級" size="small">
-            <a-table
-              :columns="orderColumns"
-              :data-source="statement?.orders ?? []"
-              :pagination="false"
-              size="small"
-              bordered
-              :scroll="{ x: 800 }"
-            >
-              <template #bodyCell="{ column, record }">
-                <template v-if="column.key === 'orderAmount'">
-                  {{ formatMoney(record.orderAmount) }}
-                </template>
-                <template v-else-if="column.key === 'invoicedAmount'">
-                  <span class="text-blue-600">
-                    {{ formatMoney(record.invoicedAmount) }}
-                  </span>
-                </template>
-                <template v-else-if="column.key === 'uninvoicedAmount'">
-                  <span class="text-red-600">
-                    {{ formatMoney(record.uninvoicedAmount) }}
-                  </span>
-                </template>
-                <template v-else-if="column.key === 'status'">
-                  {{ getStatusLabel(record.status) }}
-                </template>
-              </template>
-            </a-table>
-          </a-card>
-        </a-col>
-        <a-col :span="12">
-          <a-card title="閲囪喘鏉ョエ娴佹按锛堝紑绁ㄩ噾棰� / 宸蹭粯 / 鍓╀綑搴斾粯锛�" size="small">
-            <a-table
-              :columns="invoiceColumns"
-              :data-source="statement?.invoices ?? []"
-              :pagination="false"
-              size="small"
-              bordered
-              :scroll="{ x: 900 }"
-            >
-              <template #bodyCell="{ column, record }">
-                <template v-if="column.key === 'invoiceAmount'">
-                  <span class="text-blue-600">
-                    {{ formatMoney(record.invoiceAmount) }}
-                  </span>
-                </template>
-                <template v-else-if="column.key === 'paidAmount'">
-                  {{ formatMoney(record.paidAmount) }}
-                </template>
-                <template v-else-if="column.key === 'remainingPayable'">
-                  <span class="text-red-600">
-                    {{ formatMoney(record.remainingPayable) }}
-                  </span>
-                </template>
-                <template v-else-if="column.key === 'paymentStatus'">
-                  {{ getPaymentStatusLabel(record.paymentStatus) }}
-                </template>
-              </template>
-            </a-table>
-          </a-card>
-          <a-card title="浠樻娴佹按" size="small" class="mt-4">
-            <a-table
-              :columns="paymentColumns"
-              :data-source="statement?.payments ?? []"
-              :pagination="false"
-              size="small"
-              bordered
-              :scroll="{ x: 700 }"
-            >
-              <template #bodyCell="{ column, record }">
-                <template v-if="column.key === 'paymentAmount'">
-                  <span class="text-green-600">
-                    {{ formatMoney(record.paymentAmount) }}
-                  </span>
-                </template>
-                <template v-else-if="column.key === 'status'">
-                  {{ getStatusLabel(record.status) }}
-                </template>
-              </template>
-            </a-table>
-          </a-card>
-        </a-col>
-      </a-row>
+          <Row :gutter="16" class="mb-4">
+            <Col :span="6">
+              <Card size="small">
+                <div class="text-gray-500">绱閲囪喘棰�</div>
+                <div class="text-2xl font-semibold">
+                  {{ formatMoney(statement?.summary?.totalPurchaseAmount) }}
+                </div>
+              </Card>
+            </Col>
+            <Col :span="6">
+              <Card size="small">
+                <div class="text-gray-500">绱寮�绁ㄩ</div>
+                <div class="text-2xl font-semibold text-blue-600">
+                  {{ formatMoney(statement?.summary?.totalInvoiceAmount) }}
+                </div>
+              </Card>
+            </Col>
+            <Col :span="6">
+              <Card size="small">
+                <div class="text-gray-500">绱浠樻棰�</div>
+                <div class="text-2xl font-semibold text-green-600">
+                  {{ formatMoney(statement?.summary?.totalPaymentAmount) }}
+                </div>
+              </Card>
+            </Col>
+            <Col :span="6">
+              <Card size="small">
+                <div class="text-gray-500">鏈粯浣欓锛堝紑绁� - 浠樻锛�</div>
+                <div class="text-2xl font-semibold text-red-600">
+                  {{ formatMoney(statement?.summary?.unpaidAmount) }}
+                </div>
+              </Card>
+            </Col>
+          </Row>
+
+          <Row :gutter="16">
+            <Col :span="12">
+              <Card title="閲囪喘璁㈠崟娴佹按锛堝惈寮�绁ㄩ噾棰濓級" size="small">
+                <Table
+                  :columns="orderColumns"
+                  :data-source="statement?.orders ?? []"
+                  :pagination="false"
+                  bordered
+                  size="small"
+                  :scroll="{ x: 800 }"
+                >
+                  <template #bodyCell="{ column, record }">
+                    <template v-if="column.key === 'orderAmount'">
+                      {{ formatMoney(record.orderAmount) }}
+                    </template>
+                    <template v-else-if="column.key === 'invoicedAmount'">
+                      <span class="text-blue-600">
+                        {{ formatMoney(record.invoicedAmount) }}
+                      </span>
+                    </template>
+                    <template v-else-if="column.key === 'uninvoicedAmount'">
+                      <span class="text-red-600">
+                        {{ formatMoney(record.uninvoicedAmount) }}
+                      </span>
+                    </template>
+                    <template v-else-if="column.key === 'status'">
+                      {{ getStatusLabel(record.status) }}
+                    </template>
+                  </template>
+                </Table>
+              </Card>
+            </Col>
+            <Col :span="12">
+              <Card
+                title="閲囪喘鏉ョエ娴佹按锛堝紑绁ㄩ噾棰� / 宸蹭粯 / 鍓╀綑搴斾粯锛�"
+                size="small"
+              >
+                <Table
+                  :columns="invoiceColumns"
+                  :data-source="statement?.invoices ?? []"
+                  :pagination="false"
+                  bordered
+                  size="small"
+                  :scroll="{ x: 900 }"
+                >
+                  <template #bodyCell="{ column, record }">
+                    <template v-if="column.key === 'invoiceAmount'">
+                      <span class="text-blue-600">
+                        {{ formatMoney(record.invoiceAmount) }}
+                      </span>
+                    </template>
+                    <template v-else-if="column.key === 'paidAmount'">
+                      {{ formatMoney(record.paidAmount) }}
+                    </template>
+                    <template v-else-if="column.key === 'remainingPayable'">
+                      <span class="text-red-600">
+                        {{ formatMoney(record.remainingPayable) }}
+                      </span>
+                    </template>
+                    <template v-else-if="column.key === 'paymentStatus'">
+                      {{ getPaymentStatusLabel(record.paymentStatus) }}
+                    </template>
+                  </template>
+                </Table>
+              </Card>
+              <Card class="mt-4" size="small" title="浠樻娴佹按">
+                <Table
+                  :columns="paymentColumns"
+                  :data-source="statement?.payments ?? []"
+                  :pagination="false"
+                  bordered
+                  size="small"
+                  :scroll="{ x: 700 }"
+                >
+                  <template #bodyCell="{ column, record }">
+                    <template v-if="column.key === 'paymentAmount'">
+                      <span class="text-green-600">
+                        {{ formatMoney(record.paymentAmount) }}
+                      </span>
+                    </template>
+                    <template v-else-if="column.key === 'status'">
+                      {{ getStatusLabel(record.status) }}
+                    </template>
+                  </template>
+                </Table>
+              </Card>
+            </Col>
+          </Row>
+        </Spin>
+      </div>
     </div>
   </Page>
 </template>

--
Gitblit v1.9.3