| | |
| | | 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'; |
| | |
| | | export function useFormSchema( |
| | | formType: FormType, |
| | | formApi?: VbenFormApi, |
| | | onOrderChange?: (item: Record<string, unknown> | undefined) => void, |
| | | ): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | |
| | | label: '销售订单号', |
| | | component: markRaw(ErpSaleOrderSelect), |
| | | componentProps: { |
| | | outStatus: 3, |
| | | placeholder: '请选择销售订单', |
| | | onChange: (item: any) => { |
| | | if (formApi) { |
| | |
| | | formApi.setFieldValue('clientId', item.customerId); |
| | | } |
| | | } |
| | | onOrderChange?.(item); |
| | | }, |
| | | }, |
| | | rules: 'selectRequired', |
| | |
| | | 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, |
| | | })), |
| | | onChange: (value: number | undefined) => { |
| | | const selected = items.find((i) => i.productId === value); |
| | | onItemChange?.(selected); |
| | | }, |
| | | } |
| | | : { |
| | | placeholder: '请选择物料', |
| | | productIds: [], |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | | { |
| | |
| | | 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', |
| | | }, |
| | | { |
| | |
| | | component: markRaw(WmBatchSelect), |
| | | componentProps: { |
| | | clientId, |
| | | disabled: true, |
| | | placeholder: '请选择批次', |
| | | salesOrderCode, |
| | | }, |
| | |
| | | triggerFields: ['itemId'], |
| | | componentProps: (values) => ({ |
| | | clientId, |
| | | disabled: true, |
| | | itemId: values.itemId, |
| | | placeholder: '请选择批次', |
| | | salesOrderCode, |