2026-08-10 76c9a49c3ded285857f0c252def2552469b85825
feat(erp): 新增采购发票功能并优化付款流程

- 在ERP业务枚举中添加采购发票类型(PURCHASE_INVOICE: 13)
- 为付款表单添加关联来票选择功能和自动生成明细逻辑
- 实现付款基于来票的自动明细生成功能,移除手动添加选项
- 优化付款表单验证逻辑,确保必须选择关联来票
- 在采购发票模块中添加采购订单选择功能并优化交互
- 移除原有的采购入库单和采购退货单手动添加功能
- 更新付款明细表格列配置以适配新的来票模式
- 添加付款账户帮助提示信息和默认值设置
已修改5个文件
已删除2个文件
441 ■■■■ 文件已修改
src/packages/constants/src/biz-erp-enum.ts 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/finance/payment/data.ts 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/finance/payment/modules/form.vue 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/finance/payment/modules/item-form.vue 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/finance/payment/modules/purchase-in-select.vue 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/finance/payment/modules/sale-return-select.vue 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/purchase/invoice/modules/purchase-order-select.vue 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/packages/constants/src/biz-erp-enum.ts
@@ -2,6 +2,7 @@
  PURCHASE_ORDER: 10,
  PURCHASE_IN: 11,
  PURCHASE_RETURN: 12,
  PURCHASE_INVOICE: 13,
  SALE_ORDER: 20,
  SALE_OUT: 21,
  SALE_RETURN: 22,
src/views/erp/finance/payment/data.ts
@@ -163,6 +163,7 @@
        labelField: 'name',
        valueField: 'id',
      },
      help: '付款账户数据来自【财务管理 â†’ ç»“算账户】菜单维护的开启状态账户,无选项时请先在结算账户页面新增。',
    },
    {
      fieldName: 'totalPrice',
@@ -180,6 +181,7 @@
      fieldName: 'discountPrice',
      label: '优惠金额',
      component: 'InputNumber',
      defaultValue: 0,
      componentProps: {
        class: '!w-full',
        disabled: formType === 'detail',
@@ -212,15 +214,13 @@
  ];
}
/** è¡¨å•的明细表格列 */
export function useFormItemColumns(
  disabled: boolean,
): VxeTableGridOptions['columns'] {
/** è¡¨å•的明细表格列(付款基于来票,明细由来票自动生成,不可删除) */
export function useFormItemColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'seq', title: '序号', minWidth: 50, fixed: 'left' },
    {
      field: 'bizNo',
      title: '采购单据编号',
      title: '来票编号',
      minWidth: 200,
    },
    {
@@ -247,13 +247,6 @@
      title: '备注',
      minWidth: 150,
      slots: { default: 'remark' },
    },
    {
      title: '操作',
      width: 50,
      fixed: 'right',
      slots: { default: 'actions' },
      visible: !disabled,
    },
  ];
}
src/views/erp/finance/payment/modules/form.vue
@@ -17,6 +17,7 @@
  getFinancePayment,
  updateFinancePayment,
} from '#/api/erp/finance/payment';
import { getPurchaseInvoiceSimpleList } from '#/api/erp/purchase/invoice';
import { useFormSchema } from '../data';
import ItemForm from './item-form.vue';
@@ -68,6 +69,11 @@
      if (changedFields.includes('supplierId')) {
        formData.value.supplierId = values.supplierId;
      }
      // å…³è”来票变化时,加载来票信息供明细自动生成
      if (changedFields.includes('invoiceId')) {
        formData.value.invoiceId = values.invoiceId;
        handleInvoiceChange(values.invoiceId);
      }
      // ç›®çš„:同步到 item-form ç»„件,触发整体的价格计算
      if (changedFields.includes('discountPrice')) {
        formData.value.discountPrice = values.discountPrice;
@@ -80,6 +86,27 @@
    }
  },
});
/** å…³è”来票变化时,加载来票信息,供付款明细自动生成 */
async function handleInvoiceChange(invoiceId: number | undefined) {
  if (formType.value === 'detail' || !invoiceId) {
    if (!invoiceId) {
      formData.value.invoice = undefined;
    }
    return;
  }
  const supplierId = formData.value.supplierId;
  if (!supplierId) {
    return;
  }
  const invoices = await getPurchaseInvoiceSimpleList(supplierId);
  // è¯·æ±‚期间来票已再次切换时,丢弃过期结果,避免回显错乱
  if (formData.value.invoiceId !== invoiceId) {
    return;
  }
  const invoice = invoices.find((item) => item.id === invoiceId);
  formData.value.invoice = invoice;
}
/** æ›´æ–°ä»˜æ¬¾é¡¹ */
function handleUpdateItems(items: ErpFinancePaymentApi.FinancePaymentItem[]) {
@@ -198,6 +225,7 @@
          :supplier-id="formData?.supplierId"
          :disabled="formType === 'detail'"
          :discount-price="formData?.discountPrice ?? 0"
          :invoice="formData?.invoice"
          @update:items="handleUpdateItems"
          @update:total-price="handleUpdateTotalPrice"
          @update:payment-price="handleUpdatePaymentPrice"
src/views/erp/finance/payment/modules/item-form.vue
@@ -1,26 +1,30 @@
<script lang="ts" setup>
import type { ErpFinancePaymentApi } from '#/api/erp/finance/payment';
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
import type { ErpPurchaseReturnApi } from '#/api/erp/purchase/return';
import { computed, nextTick, ref, watch } from 'vue';
import { ErpBizType } from '@vben/constants';
import { erpPriceInputFormatter } from '@vben/utils';
import { Input, InputNumber, message } from 'ant-design-vue';
import { Input, InputNumber } from 'ant-design-vue';
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { useFormItemColumns } from '../data';
import PurchaseInSelect from './purchase-in-select.vue';
import SaleReturnSelect from './sale-return-select.vue';
interface InvoiceForItem {
  id?: number;
  no?: string;
  price?: number;
  remainingInvoicePrice?: number;
}
interface Props {
  items?: ErpFinancePaymentApi.FinancePaymentItem[];
  supplierId?: number;
  disabled?: boolean;
  discountPrice?: number;
  invoice?: InvoiceForItem;
}
const props = withDefaults(defineProps<Props>(), {
@@ -28,6 +32,7 @@
  supplierId: undefined,
  disabled: false,
  discountPrice: 0,
  invoice: undefined,
});
const emit = defineEmits([
@@ -37,6 +42,9 @@
]);
const tableData = ref<ErpFinancePaymentApi.FinancePaymentItem[]>([]); // è¡¨æ ¼æ•°æ®
/** å·²æ ¹æ®è¯¥æ¥ç¥¨ç”Ÿæˆçš„æ˜Žç»†ï¼Œé¿å…é‡å¤ç”Ÿæˆ */
const generatedInvoiceId = ref<number | undefined>();
/** èŽ·å–è¡¨æ ¼åˆè®¡æ•°æ® */
const summaries = computed(() => {
@@ -59,7 +67,7 @@
/** è¡¨æ ¼é…ç½® */
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useFormItemColumns(props.disabled),
    columns: useFormItemColumns(),
    data: tableData.value,
    minHeight: 250,
    autoResize: true,
@@ -85,11 +93,44 @@
      return;
    }
    tableData.value = [...items];
    // ç¼–辑回显时,标记已根据当前来票生成过,避免重复生成
    generatedInvoiceId.value = props.invoice?.id;
    await nextTick(); // ç‰¹æ®Šï¼šä¿è¯ gridApi å·²ç»åˆå§‹åŒ–
    await gridApi.grid.reloadData(tableData.value);
  },
  {
    immediate: true,
  },
);
/** å…³è”来票变化时,自动生成唯一的付款明细(付款基于来票) */
watch(
  () => props.invoice?.id,
  async (newId) => {
    if (!newId || !props.invoice) {
      return;
    }
    if (generatedInvoiceId.value === newId) {
      return;
    }
    generatedInvoiceId.value = newId;
    const invoice = props.invoice;
    const price = invoice.price ?? 0;
    const remaining = invoice.remainingInvoicePrice ?? price;
    tableData.value = [
      {
        bizId: invoice.id ?? 0,
        bizType: ErpBizType.PURCHASE_INVOICE,
        bizNo: invoice.no ?? '',
        totalPrice: price,
        paidPrice: price - remaining,
        paymentPrice: remaining,
        remark: '',
      },
    ];
    await nextTick();
    await gridApi.grid.reloadData(tableData.value);
    emit('update:items', [...tableData.value]);
  },
);
@@ -116,74 +157,6 @@
  { deep: true },
);
/** æ·»åŠ é‡‡è´­å…¥åº“å• */
const purchaseInSelectRef = ref();
const handleOpenPurchaseIn = () => {
  if (!props.supplierId) {
    message.error('请选择供应商');
    return;
  }
  purchaseInSelectRef.value?.open(props.supplierId);
};
const handleAddPurchaseIn = (rows: ErpPurchaseInApi.PurchaseIn[]) => {
  rows.forEach((row) => {
    const totalPrice = row.totalPrice ?? 0;
    const paidPrice = row.paymentPrice ?? 0;
    const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
      bizId: row.id ?? 0,
      bizType: ErpBizType.PURCHASE_IN,
      bizNo: row.no ?? '',
      totalPrice,
      paidPrice,
      paymentPrice: totalPrice - paidPrice,
      remark: undefined,
    };
    tableData.value.push(newItem);
  });
  emit('update:items', [...tableData.value]);
};
/** æ·»åŠ é‡‡è´­é€€è´§å• */
const saleReturnSelectRef = ref();
const handleOpenSaleReturn = () => {
  if (!props.supplierId) {
    message.error('请选择供应商');
    return;
  }
  saleReturnSelectRef.value?.open(props.supplierId);
};
const handleAddSaleReturn = (rows: ErpPurchaseReturnApi.PurchaseReturn[]) => {
  rows.forEach((row) => {
    const totalPrice = row.totalPrice ?? 0;
    const refundPrice = row.refundPrice ?? 0;
    const newItem: ErpFinancePaymentApi.FinancePaymentItem = {
      bizId: row.id ?? 0,
      bizType: ErpBizType.PURCHASE_RETURN,
      bizNo: row.no ?? '',
      totalPrice: -totalPrice,
      paidPrice: -refundPrice,
      paymentPrice: -totalPrice + refundPrice,
      remark: undefined,
    };
    tableData.value.push(newItem);
  });
  emit('update:items', [...tableData.value]);
};
/** åˆ é™¤è¡Œ */
const handleDelete = async (row: any) => {
  const index = tableData.value.findIndex(
    (item) => item.bizId === row.bizId && item.bizType === row.bizType,
  );
  if (index !== -1) {
    tableData.value.splice(index, 1);
  }
  // é€šçŸ¥çˆ¶ç»„ä»¶æ›´æ–°
  emit('update:items', [...tableData.value]);
};
/** å¤„理行数据变更 */
const handleRowChange = (row: any) => {
  const index = tableData.value.findIndex(
@@ -201,7 +174,7 @@
const validate = () => {
  // æ£€æŸ¥æ˜¯å¦æœ‰æ˜Žç»†
  if (tableData.value.length === 0) {
    throw new Error('请添加付款明细');
    throw new Error('请先选择关联来票');
  }
  // æ£€æŸ¥æ¯è¡Œçš„付款金额
  for (let i = 0; i < tableData.value.length; i++) {
@@ -236,21 +209,6 @@
          @change="handleRowChange(row)"
        />
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: '删除',
              type: 'link',
              danger: true,
              popConfirm: {
                title: '确认删除该付款明细吗?',
                confirm: handleDelete.bind(null, row),
              },
            },
          ]"
        />
      </template>
      <template #bottom>
        <div class="mt-2 rounded border border-border bg-muted p-2">
@@ -258,7 +216,7 @@
            <span class="font-medium text-foreground">合计:</span>
            <div class="flex space-x-4">
              <span>
                åˆè®¡ä»˜æ¬¾ï¼š{{ erpPriceInputFormatter(summaries.totalPrice) }}
                åº”付金额:{{ erpPriceInputFormatter(summaries.totalPrice) }}
              </span>
              <span>
                å·²ä»˜é‡‘额:{{ erpPriceInputFormatter(summaries.paidPrice) }}
@@ -270,34 +228,13 @@
            </div>
          </div>
        </div>
        <TableAction
          v-if="!disabled"
          class="mt-2 flex justify-center"
          :actions="[
            {
              label: '添加采购入库单',
              type: 'default',
              onClick: handleOpenPurchaseIn,
            },
            {
              label: '添加采购退货单',
              type: 'default',
              onClick: handleOpenSaleReturn,
            },
          ]"
        />
        <div
          v-if="!invoice && !disabled"
          class="mt-2 flex justify-center text-sm text-muted-foreground"
        >
          è¯·å…ˆåœ¨ä¸Šæ–¹è¡¨å•选择关联来票,系统将自动生成付款明细
        </div>
      </template>
    </Grid>
    <!-- é‡‡è´­å…¥åº“单选择组件 -->
    <PurchaseInSelect
      ref="purchaseInSelectRef"
      @success="handleAddPurchaseIn"
    />
    <!-- é‡‡è´­é€€è´§å•选择组件 -->
    <SaleReturnSelect
      ref="saleReturnSelectRef"
      @success="handleAddSaleReturn"
    />
  </div>
</template>
src/views/erp/finance/payment/modules/purchase-in-select.vue
ÎļþÒÑɾ³ý
src/views/erp/finance/payment/modules/sale-return-select.vue
ÎļþÒÑɾ³ý
src/views/erp/purchase/invoice/modules/purchase-order-select.vue
@@ -7,7 +7,7 @@
import { DICT_TYPE } from '@vben/constants';
import { IconifyIcon } from '@vben/icons';
import { Input, Modal } from 'ant-design-vue';
import { Input, message, Modal } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
@@ -76,6 +76,7 @@
  },
  gridOptions: {
    columns: [
      { type: 'radio', width: 50, fixed: 'left' },
      { field: 'no', title: '订单单号', width: 200, fixed: 'left' },
      { field: 'supplierName', title: '供应商', minWidth: 120 },
      {
@@ -147,6 +148,7 @@
/** ç¡®è®¤é€‰æ‹©é‡‡è´­è®¢å• */
function handleOk() {
  if (!order.value?.id) {
    message.warning('请选择采购订单');
    return;
  }
  emit('update:modelValue', order.value.id);