gaoluyang
5 天以前 7b307741022678632e06bbed3c996a8ddd013759
src/views/erp/purchase/invoice/data.ts
@@ -1,7 +1,10 @@
import type { Ref } from 'vue';
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { getSupplierSimpleList } from '#/api/srm/supplier';
import { z } from '#/adapter/form';
import { markRaw } from 'vue';
@@ -11,7 +14,9 @@
export type FormType = 'create' | 'detail' | 'edit';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
export function useFormSchema(
  orderTotalTaxPrice?: Ref<number | undefined>,
): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
@@ -41,8 +46,15 @@
      },
      componentProps: (_values, form) => ({
        placeholder: '请选择采购订单',
        onChange: (order: { supplierName?: string } | undefined) => {
        onChange: (
          order:
            | { supplierName?: string; totalTaxPrice?: number }
            | undefined,
        ) => {
          form.setFieldValue('supplierName', order?.supplierName);
          if (orderTotalTaxPrice) {
            orderTotalTaxPrice.value = order?.totalTaxPrice;
          }
        },
      }),
    },
@@ -78,11 +90,37 @@
      label: '来票金额(元)',
      component: 'InputNumber',
      rules: 'required',
      description: () =>
        orderTotalTaxPrice?.value != null
          ? `采购订单未开票金额:${Number(orderTotalTaxPrice.value).toFixed(2)} 元`
          : '',
      componentProps: {
        class: '!w-full',
        placeholder: '请输入来票金额',
        min: 0,
        precision: 2,
      },
      dependencies: {
        triggerFields: ['purchaseOrderId'],
        componentProps: () => ({
          class: '!w-full',
          placeholder: '请输入来票金额',
          min: 0,
          max: orderTotalTaxPrice?.value ?? undefined,
          precision: 2,
        }),
        rules: () => {
          const max = orderTotalTaxPrice?.value;
          if (max != null) {
            return z
              .number({ message: '请输入来票金额' })
              .min(0, '来票金额不能小于 0')
              .max(max, `来票金额不能大于未开票金额 ${Number(max).toFixed(2)}`);
          }
          return z
            .number({ message: '请输入来票金额' })
            .min(0, '来票金额不能小于 0');
        },
      },
    },
    {
@@ -148,19 +186,6 @@
        valueField: 'id',
      },
    },
    {
      fieldName: 'auditStatus',
      label: '审核状态',
      component: 'Select',
      componentProps: {
        options: [
          { label: '未审核', value: 10 },
          { label: '已审核', value: 20 },
        ],
        placeholder: '请选择审核状态',
        allowClear: true,
      },
    },
  ];
}
@@ -197,12 +222,6 @@
      formatter: 'formatAmount2',
    },
    {
      title: '剩余可付金额',
      field: 'remainingInvoicePrice',
      minWidth: 150,
      formatter: 'formatAmount2',
    },
    {
      title: '来票日期',
      field: 'invoiceTime',
      minWidth: 150,
@@ -221,16 +240,9 @@
      slots: { default: 'attachment' },
    },
    {
      title: '审批状态',
      field: 'auditStatus',
      minWidth: 100,
      fixed: 'right',
      slots: { default: 'auditStatus' },
    },
    {
      title: '操作',
      field: 'actions',
      minWidth: 280,
      minWidth: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },