gaoluyang
9 天以前 6ebcfebf58fe23ea401de1050b15ba85e41763a9
src/views/wls/returnsales/data.ts
@@ -1,3 +1,4 @@
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmReturnSalesApi } from '#/api/mes/wm/returnsales';
@@ -13,7 +14,6 @@
import { z } from '#/adapter/form';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { MdClientSelect } from '#/views/mes/md/client/components';
import { MdItemSelect } from '#/views/mes/md/item/components';
import { WmBatchSelect } from '#/views/wls/batch/components';
import {
@@ -95,13 +95,13 @@
      },
    },
    {
      fieldName: 'clientId',
      fieldName: 'clientName',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: 'Input',
      componentProps: {
        placeholder: '请选择客户',
        placeholder: '请输入客户名称',
      },
      rules: 'selectRequired',
      rules: 'required',
    },
    {
      fieldName: 'returnDate',
@@ -111,7 +111,7 @@
        class: '!w-full',
        format: 'YYYY-MM-DD',
        placeholder: '请选择退货日期',
        valueFormat: 'x',
        valueFormat: 'YYYY-MM-DD',
      },
      rules: 'required',
    },
@@ -170,11 +170,12 @@
      },
    },
    {
      fieldName: 'clientId',
      fieldName: 'clientName',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: 'Input',
      componentProps: {
        placeholder: '请选择客户',
        allowClear: true,
        placeholder: '请输入客户名称',
      },
    },
    {
@@ -324,15 +325,32 @@
export function useLineFormSchema(
  clientId?: number,
  salesOrderCode?: string,
  items?: ErpSaleOrderApi.SaleOrderItem[],
  onItemChange?: (item: ErpSaleOrderApi.SaleOrderItem | undefined) => void,
): VbenFormSchema[] {
  const hasItems = items && items.length > 0;
  return [
    {
      fieldName: 'itemId',
      label: '物料',
      component: markRaw(MdItemSelect),
      componentProps: {
        placeholder: '请选择物料',
      },
      component: hasItems ? 'Select' : markRaw(MdItemSelect),
      componentProps: hasItems
        ? {
            placeholder: '请选择物料',
            options: items.map((item) => ({
              label: `${item.productName || ''}(${item.productBarCode || ''})`,
              value: item.productId,
            })),
            showSearch: true,
            onChange: (value: number | undefined) => {
              const selected = items.find((i) => i.productId === value);
              onItemChange?.(selected);
            },
          }
        : {
            placeholder: '请选择物料',
            productIds: [],
          },
      rules: 'selectRequired',
    },
    {
@@ -345,6 +363,30 @@
        placeholder: '请输入退货数量',
        precision: 2,
      },
      dependencies: {
        triggerFields: ['itemId'],
        componentProps: (values) => {
          const selected = items?.find((i) => i.productId === values.itemId);
          return {
            class: '!w-full',
            max: selected?.count ?? undefined,
            min: 0,
            placeholder: '请输入退货数量',
            precision: 2,
          };
        },
        rules: (values) => {
          const selected = items?.find((i) => i.productId === values.itemId);
          const max = selected?.count;
          if (max !== undefined && max !== null) {
            return z
              .number({ message: '请输入退货数量' })
              .min(0)
              .max(max, `可退货数量不能超过 ${max}`);
          }
          return z.number({ message: '请输入退货数量' }).min(0);
        },
      },
      rules: 'required',
    },
    {
@@ -353,6 +395,7 @@
      component: markRaw(WmBatchSelect),
      componentProps: {
        clientId,
        disabled: true,
        placeholder: '请选择批次',
        salesOrderCode,
      },
@@ -360,6 +403,7 @@
        triggerFields: ['itemId'],
        componentProps: (values) => ({
          clientId,
          disabled: true,
          itemId: values.itemId,
          placeholder: '请选择批次',
          salesOrderCode,