351 lines
9.5 KiB
TypeScript
351 lines
9.5 KiB
TypeScript
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
|
||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||
import type { MesProRouteApi } from '#/api/mes/pro/route';
|
||
import type { MesProRouteProcessApi } from '#/api/mes/pro/route/process';
|
||
import type { MesProRouteProductApi } from '#/api/mes/pro/route/product';
|
||
import type { MesProRouteProductBomApi } from '#/api/mes/pro/route/productbom';
|
||
|
||
import { h } from 'vue';
|
||
|
||
import { DICT_TYPE } from '@vben/constants';
|
||
import { getDictOptions } from '@vben/hooks';
|
||
|
||
import { ElButton } from 'element-plus';
|
||
|
||
import { z } from '#/adapter/form';
|
||
import { generateAutoCode } from '#/api/mes/md/autocode/record';
|
||
import { MesAutoCodeRuleCode } from '#/views/mes/utils/constants';
|
||
|
||
/** 工艺路线表单 */
|
||
export function useFormSchema(formApi?: VbenFormApi): VbenFormSchema[] {
|
||
return [
|
||
{
|
||
fieldName: 'id',
|
||
component: 'Input',
|
||
dependencies: { triggerFields: [''], show: () => false },
|
||
},
|
||
{
|
||
fieldName: 'code',
|
||
label: '路线编码',
|
||
component: 'Input',
|
||
componentProps: {
|
||
maxLength: 64,
|
||
placeholder: '请输入工艺路线编码',
|
||
},
|
||
rules: z.string().min(1, '路线编码不能为空').max(64),
|
||
suffix: () =>
|
||
h(
|
||
ElButton,
|
||
{
|
||
type: 'default',
|
||
onClick: async () => {
|
||
try {
|
||
const code = await generateAutoCode(
|
||
MesAutoCodeRuleCode.PRO_ROUTE_CODE,
|
||
);
|
||
await formApi?.setFieldValue('code', code);
|
||
} catch (error) {
|
||
console.error(error);
|
||
}
|
||
},
|
||
},
|
||
{ default: () => '生成' },
|
||
),
|
||
},
|
||
{
|
||
fieldName: 'name',
|
||
label: '路线名称',
|
||
component: 'Input',
|
||
componentProps: {
|
||
maxLength: 100,
|
||
placeholder: '请输入工艺路线名称',
|
||
},
|
||
rules: z.string().min(1, '路线名称不能为空').max(100),
|
||
},
|
||
{
|
||
fieldName: 'description',
|
||
label: '路线说明',
|
||
component: 'Textarea',
|
||
formItemClass: 'col-span-2',
|
||
componentProps: {
|
||
maxLength: 500,
|
||
placeholder: '请输入工艺路线说明',
|
||
rows: 3,
|
||
},
|
||
},
|
||
{
|
||
fieldName: 'remark',
|
||
label: '备注',
|
||
component: 'Textarea',
|
||
formItemClass: 'col-span-2',
|
||
componentProps: {
|
||
maxLength: 250,
|
||
placeholder: '请输入备注',
|
||
rows: 2,
|
||
},
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 列表搜索表单 */
|
||
export function useGridFormSchema(): VbenFormSchema[] {
|
||
return [
|
||
{
|
||
fieldName: 'code',
|
||
label: '路线编码',
|
||
component: 'Input',
|
||
componentProps: { clearable: true, placeholder: '请输入路线编码' },
|
||
},
|
||
{
|
||
fieldName: 'name',
|
||
label: '路线名称',
|
||
component: 'Input',
|
||
componentProps: { clearable: true, placeholder: '请输入路线名称' },
|
||
},
|
||
{
|
||
fieldName: 'status',
|
||
label: '状态',
|
||
component: 'Select',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||
placeholder: '请选择状态',
|
||
},
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 列表字段 */
|
||
export function useGridColumns(): VxeTableGridOptions<MesProRouteApi.Route>['columns'] {
|
||
return [
|
||
{
|
||
field: 'code',
|
||
title: '路线编码',
|
||
minWidth: 160,
|
||
slots: { default: 'code' },
|
||
},
|
||
{ field: 'name', title: '路线名称', minWidth: 180 },
|
||
{ field: 'description', title: '路线说明', minWidth: 200 },
|
||
{
|
||
field: 'status',
|
||
title: '状态',
|
||
width: 110,
|
||
slots: { default: 'status' },
|
||
},
|
||
{ field: 'remark', title: '备注', minWidth: 160 },
|
||
{
|
||
field: 'createTime',
|
||
title: '创建时间',
|
||
width: 180,
|
||
formatter: 'formatDateTime',
|
||
},
|
||
{
|
||
title: '操作',
|
||
width: 160,
|
||
fixed: 'right',
|
||
slots: { default: 'actions' },
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 工艺路线工序明细表单 */
|
||
export function useRouteProcessFormSchema(
|
||
processOptions: Array<{ label: string; value: number }>,
|
||
): VbenFormSchema[] {
|
||
return [
|
||
{
|
||
fieldName: 'id',
|
||
component: 'Input',
|
||
dependencies: { triggerFields: [''], show: () => false },
|
||
},
|
||
{
|
||
fieldName: 'routeId',
|
||
component: 'Input',
|
||
dependencies: { triggerFields: [''], show: () => false },
|
||
},
|
||
{
|
||
fieldName: 'sort',
|
||
label: '序号',
|
||
component: 'InputNumber',
|
||
componentProps: {
|
||
class: '!w-full',
|
||
controlsPosition: 'right',
|
||
min: 1,
|
||
precision: 0,
|
||
},
|
||
rules: z.number().default(1),
|
||
},
|
||
{
|
||
fieldName: 'processId',
|
||
label: '工序',
|
||
component: 'Select',
|
||
componentProps: {
|
||
clearable: true,
|
||
filterable: true,
|
||
options: processOptions,
|
||
placeholder: '请选择工序',
|
||
},
|
||
rules: 'selectRequired',
|
||
},
|
||
{
|
||
fieldName: 'linkType',
|
||
label: '与下道工序关系',
|
||
component: 'Select',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: getDictOptions(DICT_TYPE.MES_PRO_LINK_TYPE, 'number'),
|
||
placeholder: '请选择',
|
||
},
|
||
rules: z.number().default(3),
|
||
},
|
||
{
|
||
fieldName: 'colorCode',
|
||
label: '甘特图颜色',
|
||
component: 'Input',
|
||
componentProps: {
|
||
maxLength: 16,
|
||
placeholder: '请输入颜色 hex,例如 #00AEF3',
|
||
},
|
||
},
|
||
{
|
||
fieldName: 'keyFlag',
|
||
label: '是否关键工序',
|
||
component: 'Switch',
|
||
componentProps: { activeText: '是', inactiveText: '否' },
|
||
rules: z.boolean().default(false),
|
||
},
|
||
{
|
||
fieldName: 'checkFlag',
|
||
label: '是否质检确认',
|
||
component: 'Switch',
|
||
componentProps: { activeText: '是', inactiveText: '否' },
|
||
rules: z.boolean().default(false),
|
||
},
|
||
{
|
||
fieldName: 'prepareTime',
|
||
label: '准备时间(分)',
|
||
component: 'InputNumber',
|
||
componentProps: {
|
||
class: '!w-full',
|
||
controlsPosition: 'right',
|
||
min: 0,
|
||
precision: 0,
|
||
},
|
||
rules: z.number().default(0),
|
||
},
|
||
{
|
||
fieldName: 'waitTime',
|
||
label: '等待时间(分)',
|
||
component: 'InputNumber',
|
||
componentProps: {
|
||
class: '!w-full',
|
||
controlsPosition: 'right',
|
||
min: 0,
|
||
precision: 0,
|
||
},
|
||
rules: z.number().default(0),
|
||
},
|
||
{
|
||
fieldName: 'remark',
|
||
label: '备注',
|
||
component: 'Textarea',
|
||
formItemClass: 'col-span-2',
|
||
componentProps: { maxLength: 250, placeholder: '请输入备注', rows: 2 },
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 工艺路线工序列表字段 */
|
||
export function useRouteProcessGridColumns(): VxeTableGridOptions<MesProRouteProcessApi.RouteProcess>['columns'] {
|
||
return [
|
||
{ field: 'sort', title: '序号', width: 70, align: 'center', fixed: 'left' },
|
||
{ field: 'processCode', title: '工序编码', width: 140, fixed: 'left' },
|
||
{ field: 'processName', title: '工序名称', width: 140, fixed: 'left' },
|
||
{ field: 'nextProcessName', title: '下一道工序', width: 140 },
|
||
{
|
||
field: 'linkType',
|
||
title: '与下一道工序关系',
|
||
width: 160,
|
||
cellRender: {
|
||
name: 'CellDict',
|
||
props: { type: DICT_TYPE.MES_PRO_LINK_TYPE },
|
||
},
|
||
},
|
||
{
|
||
field: 'keyFlag',
|
||
title: '关键工序',
|
||
width: 90,
|
||
cellRender: {
|
||
name: 'CellDict',
|
||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||
},
|
||
},
|
||
{
|
||
field: 'checkFlag',
|
||
title: '质检确认',
|
||
width: 100,
|
||
cellRender: {
|
||
name: 'CellDict',
|
||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||
},
|
||
},
|
||
{ field: 'prepareTime', title: '准备时间(分)', width: 110 },
|
||
{ field: 'waitTime', title: '等待时间(分)', width: 110 },
|
||
{
|
||
field: 'colorCode',
|
||
title: '甘特图颜色',
|
||
width: 130,
|
||
slots: { default: 'colorCode' },
|
||
},
|
||
{ field: 'remark', title: '备注', minWidth: 160 },
|
||
{
|
||
title: '操作',
|
||
width: 130,
|
||
fixed: 'right',
|
||
slots: { default: 'actions' },
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 工艺路线产品列表字段 */
|
||
export function useRouteProductGridColumns(): VxeTableGridOptions<MesProRouteProductApi.RouteProduct>['columns'] {
|
||
return [
|
||
{ field: 'itemCode', title: '产品物料编码', width: 150 },
|
||
{ field: 'itemName', title: '产品物料名称', width: 150 },
|
||
{ field: 'specification', title: '规格型号', width: 150 },
|
||
{ field: 'unitName', title: '单位', width: 80 },
|
||
{ field: 'quantity', title: '生产数量', width: 100 },
|
||
{
|
||
field: 'productionTime',
|
||
title: '生产用时',
|
||
width: 130,
|
||
slots: { default: 'productionTime' },
|
||
},
|
||
{ field: 'remark', title: '备注', minWidth: 160 },
|
||
{
|
||
title: '操作',
|
||
width: 130,
|
||
fixed: 'right',
|
||
slots: { default: 'actions' },
|
||
},
|
||
];
|
||
}
|
||
|
||
/** 工艺路线产品 BOM 列表字段 */
|
||
export function useRouteProductBomGridColumns(): VxeTableGridOptions<MesProRouteProductBomApi.RouteProductBom>['columns'] {
|
||
return [
|
||
{ field: 'itemCode', title: 'BOM 物料编码', width: 150 },
|
||
{ field: 'itemName', title: 'BOM 物料名称', width: 150 },
|
||
{ field: 'specification', title: '规格型号', width: 150 },
|
||
{ field: 'unitName', title: '单位', width: 80 },
|
||
{ field: 'quantity', title: '用料比例', width: 100 },
|
||
{ field: 'remark', title: '备注', minWidth: 160 },
|
||
{
|
||
title: '操作',
|
||
width: 130,
|
||
fixed: 'right',
|
||
slots: { default: 'actions' },
|
||
},
|
||
];
|
||
}
|