gaoluyang
5 天以前 7b307741022678632e06bbed3c996a8ddd013759
src/views/erp/purchase/invoice/modules/form.vue
@@ -22,6 +22,7 @@
const emit = defineEmits(['success']);
const formData = ref<ErpPurchaseInvoiceApi.PurchaseInvoice>();
const formType = ref<FormType>('create');
const orderTotalTaxPrice = ref<number>(); // 所选采购订单合计税额(未开票金额,用于提示与校验)
const getTitle = computed(() => {
  if (formType.value === 'create') {
@@ -42,7 +43,7 @@
  },
  wrapperClass: 'grid-cols-2',
  layout: 'horizontal',
  schema: useFormSchema(),
  schema: useFormSchema(orderTotalTaxPrice),
  showDefaultActions: false,
});
@@ -71,12 +72,13 @@
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      orderTotalTaxPrice.value = undefined;
      return;
    }
    const data = modalApi.getData<{ formType: FormType; id?: number }>();
    formType.value = data.formType;
    formApi.setDisabled(formType.value === 'detail');
    formApi.updateSchema(useFormSchema());
    formApi.updateSchema(useFormSchema(orderTotalTaxPrice));
    await formApi.resetForm();
    if (!data || !data.id) {
      return;
@@ -85,9 +87,15 @@
    try {
      formData.value = await getPurchaseInvoice(data.id);
      if (formData.value?.attachmentList?.length) {
        // 用 attachmentList 代替 blobIds,让上传组件能展示文件名和预览链接
        // 转为上传组件的文件对象;提交时 formApi 会按 valueKey 提取附件 ID
        (formData.value as Record<string, unknown>).blobIds =
          formData.value.attachmentList;
          formData.value.attachmentList.map((item) => ({
            uid: String(item.id),
            name: item.name || '',
            url: item.url || '',
            status: 'done',
            id: item.id,
          }));
      }
      await formApi.setValues(formData.value as any);
    } finally {