liu
4 天以前 6373c12e97dc5d52ad87271d1adb6743b0052607
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(
  orderRemainInvoicePrice?: Ref<number | undefined>,
): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
@@ -41,8 +46,15 @@
      },
      componentProps: (_values, form) => ({
        placeholder: '请选择采购订单',
        onChange: (order: { supplierName?: string } | undefined) => {
        onChange: (
          order:
            | { supplierName?: string; remainInvoicePrice?: number }
            | undefined,
        ) => {
          form.setFieldValue('supplierName', order?.supplierName);
          if (orderRemainInvoicePrice) {
            orderRemainInvoicePrice.value = order?.remainInvoicePrice;
          }
        },
      }),
    },
@@ -78,11 +90,37 @@
      label: '来票金额(元)',
      component: 'InputNumber',
      rules: 'required',
      description: () =>
        orderRemainInvoicePrice?.value != null
          ? `采购订单未开票金额:${Number(orderRemainInvoicePrice.value).toFixed(2)} 元`
          : '',
      componentProps: {
        class: '!w-full',
        placeholder: '请输入来票金额',
        min: 0,
        precision: 2,
      },
      dependencies: {
        triggerFields: ['purchaseOrderId'],
        componentProps: () => ({
          class: '!w-full',
          placeholder: '请输入来票金额',
          min: 0,
          max: orderRemainInvoicePrice?.value ?? undefined,
          precision: 2,
        }),
        rules: () => {
          const max = orderRemainInvoicePrice?.value;
          if (max != null) {
            return z
              .number({ message: '请输入来票金额' })
              .min(0, '来票金额不能小于 0')
              .max(max, `来票金额不能大于未开票金额 ${Number(max).toFixed(2)}`);
          }
          return z
            .number({ message: '请输入来票金额' })
            .min(0, '来票金额不能小于 0');
        },
      },
    },
    {
@@ -180,12 +218,6 @@
    {
      title: '来票金额(元)',
      field: 'price',
      minWidth: 150,
      formatter: 'formatAmount2',
    },
    {
      title: '剩余可付金额',
      field: 'remainingInvoicePrice',
      minWidth: 150,
      formatter: 'formatAmount2',
    },