| | |
| | | |
| | | import { computed, ref } from 'vue'; |
| | | |
| | | import { useVbenModal } from '../../../../../packages/effects/common-ui/src'; |
| | | import { $t } from '../../../../../packages/locales/src'; |
| | | import { useVbenModal } from '@vben/common-ui'; |
| | | import { $t } from '@vben/locales'; |
| | | |
| | | import { message } from 'ant-design-vue'; |
| | | |
| | |
| | | getFinancePayment, |
| | | updateFinancePayment, |
| | | } from '#/api/erp/finance/payment'; |
| | | import { getPurchaseInvoiceSimpleList } from '#/api/erp/purchase/invoice'; |
| | | |
| | | import { useFormSchema } from '../data'; |
| | | import ItemForm from './item-form.vue'; |
| | | |
| | | const emit = defineEmits(['success']); |
| | | const formData = ref< |
| | | ErpFinancePaymentApi.FinancePayment & { |
| | | fileUrl?: string; |
| | | } |
| | | ErpFinancePaymentApi.FinancePayment |
| | | >({ |
| | | id: undefined, |
| | | no: '', |
| | |
| | | financeUserId: undefined, |
| | | paymentTime: undefined, |
| | | remark: '', |
| | | fileUrl: undefined, |
| | | totalPrice: 0, |
| | | discountPrice: 0, |
| | | paymentPrice: 0, |
| | |
| | | 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; |
| | |
| | | } |
| | | }, |
| | | }); |
| | | |
| | | /** 关联来票变化时,加载来票信息,供付款明细自动生成 */ |
| | | 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[]) { |
| | |
| | | formData.value = await getFinancePayment(data.id); |
| | | // 设置到 values |
| | | await formApi.setValues(formData.value, false); |
| | | // 详情模式下,关联来票字段用 Input 展示来票编号 |
| | | if (formType.value === 'detail' && formData.value?.invoice) { |
| | | await formApi.setFieldValue('invoiceId', formData.value.invoice.no); |
| | | } |
| | | if (formData.value?.attachmentList?.length) { |
| | | const blobIds = formData.value.attachmentList.map((item) => ({ |
| | | uid: String(item.id), |
| | | name: item.name || '', |
| | | url: item.url || '', |
| | | status: 'done', |
| | | id: item.id, |
| | | })); |
| | | await formApi.setFieldValue('blobIds', blobIds); |
| | | } |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | |
| | | :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" |