| | |
| | | import type { VbenFormSchema } from "#/adapter/form"; |
| | | import type { VbenFormApi, VbenFormSchema } from "#/adapter/form"; |
| | | import type { VxeTableGridOptions } from "#/adapter/vxe-table"; |
| | | |
| | | import { h } from 'vue'; |
| | | |
| | | import { CommonStatusEnum, DICT_TYPE } from "#/packages/constants/src"; |
| | | import { getDictOptions } from "#/packages/effects/hooks/src"; |
| | | |
| | | import { z } from '#/adapter/form'; |
| | | import { generateAutoCode } from '#/api/mes/md/autocode/record'; |
| | | import { MesAutoCodeRuleCode } from '@vben/constants'; |
| | | import { getItemTypeSimpleList } from '#/api/mes/md/item/type'; |
| | | import { getUnitPage } from '#/api/mdm/unit'; |
| | | |
| | | /** 物料类型选项 */ |
| | | export const ITEM_TYPE_OPTIONS = [ |
| | | { label: "原料", value: 1 }, |
| | | { label: "半成品", value: 2 }, |
| | | { label: "成品", value: 3 }, |
| | | { label: "辅料", value: 4 }, |
| | | ]; |
| | | import { Button } from 'ant-design-vue'; |
| | | |
| | | /** 物料类型映射 */ |
| | | export const ITEM_TYPE_MAP: Record<number, string> = { |
| | | 1: "原料", |
| | | 2: "半成品", |
| | | 3: "成品", |
| | | 4: "辅料", |
| | | }; |
| | | // 缓存单位列表 |
| | | let unitListCache: any[] | null = null; |
| | | let unitListPromise: Promise<any[]> | null = null; |
| | | |
| | | /** 物料类型颜色映射 */ |
| | | export const ITEM_TYPE_COLOR_MAP: Record<number, string> = { |
| | | 1: "green", |
| | | 2: "orange", |
| | | 3: "blue", |
| | | 4: "purple", |
| | | }; |
| | | /** 获取单位列表(带缓存) */ |
| | | async function getUnitListCached() { |
| | | if (unitListCache) { |
| | | return unitListCache; |
| | | } |
| | | if (unitListPromise) { |
| | | return unitListPromise; |
| | | } |
| | | unitListPromise = getUnitPage({ pageNo: 1, pageSize: 100, status: 0 }).then((res) => { |
| | | unitListCache = res.list || []; |
| | | return unitListCache; |
| | | }).finally(() => { |
| | | unitListPromise = null; |
| | | }); |
| | | return unitListPromise; |
| | | } |
| | | |
| | | /** 新增/修改的表单 */ |
| | | export function useFormSchema(): VbenFormSchema[] { |
| | | export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] { |
| | | return [ |
| | | { |
| | | component: "Input", |
| | |
| | | fieldName: "code", |
| | | label: "物料编码", |
| | | componentProps: { |
| | | maxLength: 64, |
| | | placeholder: "请输入物料编码", |
| | | }, |
| | | rules: "required", |
| | | rules: z.string().min(1, '物料编码不能为空').max(64), |
| | | suffix: () => |
| | | h( |
| | | Button, |
| | | { |
| | | type: 'default', |
| | | onClick: async () => { |
| | | const code = await generateAutoCode( |
| | | MesAutoCodeRuleCode.MD_ITEM_CODE, |
| | | ); |
| | | await formApi?.setFieldValue('code', code); |
| | | }, |
| | | }, |
| | | { default: () => '生成' }, |
| | | ), |
| | | }, |
| | | { |
| | | component: "Input", |
| | |
| | | rules: "required", |
| | | }, |
| | | { |
| | | component: "RadioGroup", |
| | | fieldName: "itemType", |
| | | label: "物料类型", |
| | | component: "ApiSelect", |
| | | fieldName: "categoryId", |
| | | label: "物料分类", |
| | | rules: "selectRequired", |
| | | componentProps: { |
| | | options: ITEM_TYPE_OPTIONS, |
| | | buttonStyle: "solid", |
| | | optionType: "button", |
| | | placeholder: "请选择物料分类", |
| | | allowClear: true, |
| | | api: async () => { |
| | | const res = await getItemTypeSimpleList(); |
| | | return res || []; |
| | | }, |
| | | labelField: "name", |
| | | valueField: "id", |
| | | }, |
| | | rules: "required", |
| | | }, |
| | | { |
| | | component: "Input", |
| | |
| | | componentProps: { |
| | | placeholder: "请选择计量单位", |
| | | allowClear: true, |
| | | api: async () => { |
| | | const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | return res.list || []; |
| | | }, |
| | | api: getUnitListCached, |
| | | labelField: "name", |
| | | valueField: "id", |
| | | }, |
| | |
| | | componentProps: { |
| | | placeholder: "请选择辅单位1", |
| | | allowClear: true, |
| | | api: async () => { |
| | | const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | return res.list || []; |
| | | }, |
| | | api: getUnitListCached, |
| | | labelField: "name", |
| | | valueField: "id", |
| | | }, |
| | |
| | | componentProps: { |
| | | placeholder: "请选择辅单位2", |
| | | allowClear: true, |
| | | api: async () => { |
| | | const res = await getUnitPage({ pageNo: 1, pageSize: 100, status: 0 }); |
| | | return res.list || []; |
| | | }, |
| | | api: getUnitListCached, |
| | | labelField: "name", |
| | | valueField: "id", |
| | | }, |
| | |
| | | component: 'Switch', |
| | | fieldName: 'isBatchManaged', |
| | | label: '批次管理', |
| | | defaultValue: true, |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | rules: z.boolean().default(true), |
| | | rules: z.boolean().default(false), |
| | | }, |
| | | { |
| | | component: "Switch", |
| | |
| | | rows: 3, |
| | | }, |
| | | }, |
| | | // ===== 批次属性配置(isBatchManaged = true 时显示) ===== |
| | | { |
| | | component: "Divider", |
| | | fieldName: "batchConfigDivider", |
| | | label: "批次属性配置", |
| | | formItemClass: "col-span-2", |
| | | componentProps: { |
| | | orientation: "left", |
| | | plain: true, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "produceDateFlag", |
| | | label: "生产日期必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "expireDateFlag", |
| | | label: "有效期必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "receiptDateFlag", |
| | | label: "入库日期必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "vendorFlag", |
| | | label: "供应商必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "purchaseOrderCodeFlag", |
| | | label: "采购订单号必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "lotNumberFlag", |
| | | label: "生产批号必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | { |
| | | component: "Switch", |
| | | fieldName: "qualityStatusFlag", |
| | | label: "质量状态必填", |
| | | defaultValue: false, |
| | | componentProps: { |
| | | class: "w-auto", |
| | | checkedChildren: "是", |
| | | unCheckedChildren: "否", |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ["isBatchManaged"], |
| | | show: (values) => values.isBatchManaged === true, |
| | | }, |
| | | }, |
| | | ]; |
| | | } |
| | | |
| | |
| | | componentProps: { |
| | | placeholder: "请输入物料名称", |
| | | allowClear: true, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: "itemType", |
| | | label: "物料类型", |
| | | component: "Select", |
| | | componentProps: { |
| | | placeholder: "请选择物料类型", |
| | | allowClear: true, |
| | | options: ITEM_TYPE_OPTIONS, |
| | | }, |
| | | }, |
| | | { |
| | |
| | | minWidth: 150, |
| | | }, |
| | | { |
| | | field: "categoryName", |
| | | title: "物料分类", |
| | | minWidth: 120, |
| | | slots: { default: "categoryName" }, |
| | | }, |
| | | { |
| | | field: "unitMeasureName", |
| | | title: "单位", |
| | | minWidth: 80, |
| | |
| | | field: "warehouseName", |
| | | title: "默认仓库", |
| | | minWidth: 100, |
| | | }, |
| | | { |
| | | field: "itemType", |
| | | title: "物料类型", |
| | | minWidth: 100, |
| | | slots: { default: "itemType" }, |
| | | }, |
| | | { |
| | | field: "purchasePrice", |