2026-08-10 76c9a49c3ded285857f0c252def2552469b85825
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"