| | |
| | | import { |
| | | DICT_TYPE, |
| | | MesAutoCodeRuleCode, |
| | | MesWmWarehouseTypeEnum, |
| | | } from '@vben/constants'; |
| | | |
| | | import { Button } from 'ant-design-vue'; |
| | |
| | | import { z } from '#/adapter/form'; |
| | | import { generateAutoCode } from '#/api/mes/md/autocode/record'; |
| | | import CrmCustomerSelect from '#/components/crm-customer-select.vue'; |
| | | import { ErpSaleOrderSelect } from '#/views/erp/sale/order/components'; |
| | | import { MdItemSelect } from '#/views/mes/md/item/components'; |
| | | import { |
| | | getStockSummaryByBatch, |
| | | getStockSummaryByItem, |
| | | type MesWmMaterialStockApi, |
| | | } from '#/api/mes/wm/materialstock'; |
| | | |
| | | /** 表单类型 */ |
| | | export type FormType = 'create' | 'detail' | 'update'; |
| | |
| | | rules: 'required', |
| | | }, |
| | | { |
| | | fieldName: 'saleOrderId', |
| | | label: '销售订单', |
| | | component: markRaw(ErpSaleOrderSelect), |
| | | componentProps: { |
| | | placeholder: '请选择销售订单', |
| | | // 选择销售订单后,自动回填客户信息 |
| | | onChange: (item: any) => { |
| | | if (item?.customerId && formApi) { |
| | | formApi.setFieldValue('clientId', item.customerId); |
| | | } |
| | | }, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'clientId', |
| | | label: '客户', |
| | | component: markRaw(CrmCustomerSelect), |
| | | componentProps: { |
| | | placeholder: '请选择客户', |
| | | disabled: true, |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'saleOrderCode', |
| | | label: '销售订单编号', |
| | | component: 'Input', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请输入销售订单编号', |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'clientId', |
| | | label: '客户', |
| | | component: markRaw(CrmCustomerSelect), |
| | |
| | | field: 'name', |
| | | title: '通知单名称', |
| | | minWidth: 150, |
| | | }, |
| | | { |
| | | field: 'saleOrderCode', |
| | | title: '销售订单编号', |
| | | minWidth: 140, |
| | | }, |
| | | { |
| | | field: 'clientName', |
| | |
| | | ]; |
| | | } |
| | | |
| | | /** 通知单行新增/修改的表单 */ |
| | | /** 正式库(合格库库存,stockState = 20)有库存的物料选项 */ |
| | | export async function loadQualifiedStockItemOptions(): Promise< |
| | | { label: string; value: number }[] |
| | | > { |
| | | const list = await getStockSummaryByItem({ |
| | | stockState: 20, |
| | | warehouseType: MesWmWarehouseTypeEnum.QUALIFIED, |
| | | }); |
| | | return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({ |
| | | label: [item.itemName, item.itemCode, `库存 ${item.totalQuantity}`] |
| | | .filter(Boolean) |
| | | .join(' '), |
| | | value: item.itemId as number, |
| | | })); |
| | | } |
| | | |
| | | /** 指定物料的正式库存批次选项 */ |
| | | export async function loadQualifiedStockBatchOptions( |
| | | itemId: number, |
| | | ): Promise<{ label: string; value: number }[]> { |
| | | const list = await getStockSummaryByBatch({ |
| | | stockState: 20, |
| | | itemId, |
| | | warehouseType: MesWmWarehouseTypeEnum.QUALIFIED, |
| | | }); |
| | | return list.map((item: MesWmMaterialStockApi.MaterialStockSummary) => ({ |
| | | label: [item.batchCode, `库存 ${item.totalQuantity}`].filter(Boolean).join(' '), |
| | | value: item.batchId as number, |
| | | })); |
| | | } |
| | | |
| | | /** |
| | | * 可发货数量:所选物料/批次的正式库存(stockState = 20)汇总。 |
| | | * |
| | | * 指定批次时精确到该批次,否则返回物料全部正式库存。 |
| | | */ |
| | | export async function loadAvailableQuantity( |
| | | itemId?: number, |
| | | batchId?: number, |
| | | ): Promise<number> { |
| | | if (!itemId) { |
| | | return 0; |
| | | } |
| | | if (batchId) { |
| | | const list = await getStockSummaryByBatch({ |
| | | stockState: 20, |
| | | itemId, |
| | | warehouseType: MesWmWarehouseTypeEnum.QUALIFIED, |
| | | }); |
| | | return list.find((item) => item.batchId === batchId)?.totalQuantity ?? 0; |
| | | } |
| | | const list = await getStockSummaryByItem({ |
| | | stockState: 20, |
| | | itemId, |
| | | warehouseType: MesWmWarehouseTypeEnum.QUALIFIED, |
| | | }); |
| | | return list.find((item) => item.itemId === itemId)?.totalQuantity ?? 0; |
| | | } |
| | | |
| | | /** |
| | | * 通知单行新增/修改的表单。 |
| | | * |
| | | * 物料、批次均从正式库库存(stockState = 20)中选择, |
| | | * 批次选项随物料联动加载,可用库存不足由后端保存时校验。 |
| | | */ |
| | | export function useLineFormSchema(): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | fieldName: 'itemId', |
| | | label: '物料', |
| | | component: markRaw(MdItemSelect), |
| | | component: 'Select', |
| | | componentProps: { |
| | | placeholder: '请选择物料', |
| | | allowClear: true, |
| | | filterOption: true, |
| | | optionFilterProp: 'label', |
| | | options: [], |
| | | placeholder: '请选择物料(仅正式库库存)', |
| | | showSearch: true, |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | | { |
| | | fieldName: 'batchId', |
| | | label: '批次', |
| | | component: 'Select', |
| | | componentProps: { |
| | | allowClear: true, |
| | | filterOption: true, |
| | | optionFilterProp: 'label', |
| | | options: [], |
| | | placeholder: '请选择批次(仅正式库库存)', |
| | | showSearch: true, |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | |
| | | componentProps: { |
| | | class: '!w-full', |
| | | min: 0.01, |
| | | placeholder: '请输入发货数量', |
| | | placeholder: '请输入发货数量(不可超过正式库存)', |
| | | precision: 2, |
| | | }, |
| | | rules: 'required', |
| | | }, |
| | | { |
| | | fieldName: 'batchCode', |
| | | label: '批次号', |
| | | fieldName: 'availableQuantity', |
| | | label: '可发货数量', |
| | | component: 'Input', |
| | | componentProps: { |
| | | placeholder: '请输入批次号', |
| | | disabled: true, |
| | | placeholder: '选择物料/批次后自动带出', |
| | | }, |
| | | }, |
| | | { |