| | |
| | | DICT_TYPE, |
| | | MesAutoCodeRuleCode, |
| | | MesProTaskStatusEnum, |
| | | MesProWorkOrderStatusEnum, |
| | | } from '@vben/constants'; |
| | | import { getDictOptions } from '@vben/hooks'; |
| | | import { formatDate } from '@vben/utils'; |
| | | |
| | | import { Button } from 'ant-design-vue'; |
| | | |
| | | import { z } from '#/adapter/form'; |
| | | import { getMachinerySimpleList } from '#/api/mes/dv/machinery'; |
| | | import { generateAutoCode } from '#/api/mes/md/autocode/record'; |
| | | import { getRouteProcessByRouteAndProcess } from '#/api/mes/pro/route/process'; |
| | | import { getProcess } from '#/api/mes/pro/process'; |
| | | import { getSimpleUserList } from '#/api/system/user'; |
| | | import { loadParamDetails } from './param-state'; |
| | | |
| | | import { getRangePickerDefaultProps } from '#/utils'; |
| | | import { MdItemSelect } from '#/views/mes/md/item/components'; |
| | | import { MdWorkstationSelect } from '#/views/mes/md/workstation/components'; |
| | |
| | | |
| | | /** 生产报工表单类型 */ |
| | | export type FormType = 'approve' | 'create' | 'detail' | 'submit' | 'update'; |
| | | |
| | | /** 工序计费类型:1-计时 2-计件 */ |
| | | const FEEDBACK_BILLING_TYPE_OPTIONS = [ |
| | | { label: '计时(按工时)', value: 1 }, |
| | | { label: '计件(按数量)', value: 2 }, |
| | | ]; |
| | | |
| | | /** 工资定额单位 */ |
| | | function getWageRateUnit(billingType?: number) { |
| | | return billingType === 1 ? '元/小时' : '元/件'; |
| | | } |
| | | |
| | | /** 列表的搜索表单 */ |
| | | export function useGridFormSchema(): VbenFormSchema[] { |
| | |
| | | { field: 'workstationName', title: '工作站', width: 120 }, |
| | | { field: 'processName', title: '工序', width: 100 }, |
| | | { field: 'workOrderCode', title: '生产订单编码', width: 160 }, |
| | | { field: 'reelNo', title: '盘号', minWidth: 120 }, |
| | | { field: 'itemCode', title: '产品物料编码', width: 120 }, |
| | | { field: 'itemName', title: '产品物料名称', minWidth: 140 }, |
| | | { field: 'itemSpecification', title: '规格型号', width: 120 }, |
| | | { field: 'unitMeasureName', title: '单位', width: 80 }, |
| | | { field: 'feedbackQuantity', title: '报工数量', width: 100 }, |
| | | { |
| | | field: 'billingType', |
| | | title: '计费类型', |
| | | width: 100, |
| | | formatter: ({ cellValue }) => |
| | | FEEDBACK_BILLING_TYPE_OPTIONS.find((item) => item.value === cellValue) |
| | | ?.label ?? '-', |
| | | }, |
| | | { field: 'workHours', title: '报工工时(h)', width: 110 }, |
| | | { field: 'productionLength', title: '生产长度(m)', width: 120 }, |
| | | { field: 'standardWorkHours', title: '标准工时(h)', width: 110 }, |
| | | { |
| | | field: 'workHoursDiff', |
| | | title: '工时差异(h)', |
| | | width: 110, |
| | | formatter: ({ cellValue }) => |
| | | cellValue == null |
| | | ? '-' |
| | | : `${Number(cellValue) > 0 ? '+' : ''}${cellValue}`, |
| | | }, |
| | | { |
| | | field: 'workHoursDiffRate', |
| | | title: '差异率', |
| | | width: 100, |
| | | formatter: ({ cellValue, row }) => |
| | | cellValue == null |
| | | ? '-' |
| | | : `${Number(cellValue) > 0 ? '+' : ''}${cellValue}%`, |
| | | }, |
| | | { |
| | | field: 'wageAmount', |
| | | title: '报工工资', |
| | | width: 110, |
| | | formatter: 'formatAmount2', |
| | | }, |
| | | { field: 'qualifiedQuantity', title: '质检合格数量', width: 120 }, |
| | | { field: 'unqualifiedQuantity', title: '质检不合格数量', width: 130 }, |
| | | { field: 'feedbackUserNickname', title: '报工人', width: 100 }, |
| | | { |
| | | field: 'feedbackTime', |
| | | title: '报工时间', |
| | | width: 180, |
| | | formatter: 'formatDateTime', |
| | | formatter: 'formatDate', |
| | | }, |
| | | { field: 'approveUserNickname', title: '审核人', width: 100 }, |
| | | { |
| | |
| | | * - create / update:录入报工主体信息和数量 |
| | | * - submit / approve / detail:主体字段只读 |
| | | * |
| | | * 数量区域根据 `checkFlag` 和 `unqualifiedQuantity` 动态显示: |
| | | * - 非质检工序:报工数量 = 合格 + 不良;不良 > 0 时再展开工废/料废/其他废品 |
| | | * - 质检工序:只填报工数量(视为待检数量) |
| | | * 报工只填写"报工数量";合格品/不良品数量由质检确定,报工环节不采集。 |
| | | * 报工审批后产出均待检验,合格品经检验后入库。 |
| | | */ |
| | | /** 报工表单与工时试算组件的联动回调 */ |
| | | export interface FeedbackFormHooks { |
| | | /** 任务选择变化:把任务信息同步给辅助工时录入组件 */ |
| | | onTaskChange?: (task?: MesProTaskApi.Task) => void; |
| | | /** 生产长度变化:用于辅助工时试算 */ |
| | | onProductionLengthChange?: (value?: number) => void; |
| | | /** 实际工时变化:用于实时展示工时差异 */ |
| | | onWorkHoursChange?: (value?: number) => void; |
| | | /** 表单关键字段变化:触发后端工资试算(含辅助工资与质量调整) */ |
| | | onPreviewWage?: () => void; |
| | | } |
| | | |
| | | export function useFormSchema( |
| | | formType: FormType, |
| | | formApi?: VbenFormApi, |
| | | hooks?: FeedbackFormHooks, |
| | | ): VbenFormSchema[] { |
| | | const isHeaderReadonly = ['approve', 'detail', 'submit'].includes(formType); |
| | | |
| | | /** |
| | | * 前端按工序快照预览报工工资:计时=工时×定额,计件=报工数量×定额。 |
| | | * 以后端保存/审批时重算的结果为准,这里只用于录入时即时展示。 |
| | | */ |
| | | const recalculateWagePreview = async () => { |
| | | if (!formApi) { |
| | | return; |
| | | } |
| | | const values = await formApi.getValues(); |
| | | const wageRate = Number(values?.wageRate ?? 0); |
| | | const quantity = Number(values?.feedbackQuantity ?? 0); |
| | | const hours = Number(values?.workHours ?? 0); |
| | | const wage = values?.billingType === 1 ? hours * wageRate : quantity * wageRate; |
| | | await formApi.setFieldValue( |
| | | 'wageAmount', |
| | | Number.isFinite(wage) ? Math.round(wage * 100) / 100 : 0, |
| | | ); |
| | | hooks?.onPreviewWage?.(); |
| | | }; |
| | | |
| | | return [ |
| | | { |
| | | fieldName: 'id', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | }, |
| | | { |
| | | fieldName: 'checkFlag', |
| | | component: 'Input', |
| | | dependencies: { triggerFields: [''], show: () => false }, |
| | | defaultValue: true, |
| | | }, |
| | | { |
| | | fieldName: 'routeId', |
| | |
| | | componentProps: { |
| | | disabled: isHeaderReadonly, |
| | | placeholder: '请选择订单', |
| | | status: MesProWorkOrderStatusEnum.CONFIRMED, |
| | | // 订单变更:清空任务及任务带出的产品信息、数量区域控制位 |
| | | onChange: async () => { |
| | | await formApi?.setValues({ |
| | | checkFlag: true, |
| | | itemCode: undefined, |
| | | itemId: undefined, |
| | | itemName: undefined, |
| | |
| | | workstationId: values.workstationId, |
| | | }), |
| | | }, |
| | | // 任务变更:自动填充关联字段、产品信息、checkFlag,并加载任务绑定的工艺参数 |
| | | // 任务变更:自动填充关联字段、产品信息,并加载任务绑定的工艺参数 |
| | | componentProps: { |
| | | onChange: async (task?: MesProTaskApi.Task) => { |
| | | await loadParamDetails(task?.id); |
| | |
| | | workstationId: task.workstationId, |
| | | reportableQuantity: task.reportableQuantity, |
| | | }); |
| | | // 工艺路线工序的 checkFlag 决定数量区域展示 |
| | | if (task.routeId && task.processId) { |
| | | try { |
| | | const routeProcess = await getRouteProcessByRouteAndProcess( |
| | | task.routeId, |
| | | task.processId, |
| | | ); |
| | | await formApi?.setFieldValue( |
| | | 'checkFlag', |
| | | routeProcess?.checkFlag ?? false, |
| | | ); |
| | | } catch { |
| | | await formApi?.setFieldValue('checkFlag', true); |
| | | } |
| | | // 带出工序的计费类型与工资定额,用于展示和即时预览报工工资 |
| | | if (task.processId) { |
| | | const process = await getProcess(task.processId); |
| | | const billingType = process?.billingType ?? 2; |
| | | const wageRate = process?.wageRate ?? 0; |
| | | await formApi?.setValues({ billingType, wageRate }); |
| | | await recalculateWagePreview(); |
| | | } |
| | | hooks?.onTaskChange?.(task); |
| | | }, |
| | | }, |
| | | rules: 'selectRequired', |
| | |
| | | placeholder: '请选择工作站', |
| | | }, |
| | | rules: 'selectRequired', |
| | | }, |
| | | { |
| | | fieldName: 'machineryId', |
| | | label: '使用设备', |
| | | component: 'ApiSelect', |
| | | componentProps: { |
| | | allowClear: true, |
| | | api: getMachinerySimpleList, |
| | | disabled: isHeaderReadonly, |
| | | labelField: 'name', |
| | | placeholder: '本次报工主用设备(影响工资单价)', |
| | | showSearch: true, |
| | | filterOption: true, |
| | | valueField: 'id', |
| | | onChange: () => recalculateWagePreview(), |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId', 'workstationId'], |
| | | componentProps: (values) => ({ |
| | | allowClear: true, |
| | | // 只列出当前任务工作站已绑定的设备,避免误选其他工序的设备 |
| | | api: () => getMachinerySimpleList(values.workstationId), |
| | | disabled: isHeaderReadonly, |
| | | labelField: 'name', |
| | | placeholder: values.workstationId |
| | | ? '本次报工主用设备(仅显示该工作站绑定的设备)' |
| | | : '请先选择工作站', |
| | | showSearch: true, |
| | | filterOption: true, |
| | | valueField: 'id', |
| | | onChange: () => recalculateWagePreview(), |
| | | }), |
| | | show: (values) => !!values.taskId, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'itemCode', |
| | |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag'], |
| | | // 非质检工序时,报工数量 = 合格 + 不良,禁用直接编辑 |
| | | componentProps: (values) => ({ |
| | | class: 'w-full', |
| | | disabled: !values.checkFlag, |
| | | min: 0, |
| | | placeholder: '请输入报工数量', |
| | | precision: 2, |
| | | }), |
| | | placeholder: '请输入报工数量', |
| | | onChange: () => recalculateWagePreview(), |
| | | }, |
| | | rules: 'required', |
| | | }, |
| | | { |
| | | fieldName: 'qualifiedQuantity', |
| | | label: '合格品数量', |
| | | fieldName: 'productionLength', |
| | | label: '生产长度(米)', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | // 合格/不良变更,自动累计为报工数量 |
| | | onChange: async () => { |
| | | const values = await formApi?.getValues(); |
| | | await formApi?.setFieldValue( |
| | | 'feedbackQuantity', |
| | | (values?.qualifiedQuantity || 0) + |
| | | (values?.unqualifiedQuantity || 0), |
| | | ); |
| | | }, |
| | | placeholder: '用于标准工时计算;单位为米时默认等于报工数量', |
| | | onChange: (value?: number) => |
| | | hooks?.onProductionLengthChange?.(value), |
| | | }, |
| | | defaultValue: 0, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag'], |
| | | show: (values) => !values.checkFlag, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'unqualifiedQuantity', |
| | | label: '不良品数量', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | // 合格/不良变更,自动累计为报工数量 |
| | | onChange: async () => { |
| | | const values = await formApi?.getValues(); |
| | | await formApi?.setFieldValue( |
| | | 'feedbackQuantity', |
| | | (values?.qualifiedQuantity || 0) + |
| | | (values?.unqualifiedQuantity || 0), |
| | | ); |
| | | }, |
| | | }, |
| | | defaultValue: 0, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag'], |
| | | show: (values) => !values.checkFlag, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'laborScrapQuantity', |
| | | label: '工废数量', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | // 废品分类变更,自动累计为不良品数量及报工数量 |
| | | onChange: async () => { |
| | | const values = await formApi?.getValues(); |
| | | const unqualified = |
| | | (values?.laborScrapQuantity || 0) + |
| | | (values?.materialScrapQuantity || 0) + |
| | | (values?.otherScrapQuantity || 0); |
| | | await formApi?.setValues({ |
| | | feedbackQuantity: (values?.qualifiedQuantity || 0) + unqualified, |
| | | unqualifiedQuantity: unqualified, |
| | | }); |
| | | }, |
| | | }, |
| | | defaultValue: 0, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag', 'unqualifiedQuantity'], |
| | | triggerFields: ['taskId'], |
| | | show: (values) => |
| | | !values.checkFlag && (values.unqualifiedQuantity || 0) > 0, |
| | | !!values.taskId && ['create', 'update'].includes(formType), |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'materialScrapQuantity', |
| | | label: '料废数量', |
| | | fieldName: 'billingType', |
| | | label: '计费类型', |
| | | component: 'Select', |
| | | componentProps: { |
| | | disabled: true, |
| | | options: FEEDBACK_BILLING_TYPE_OPTIONS, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId'], |
| | | show: (values) => !!values.taskId, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'wageRate', |
| | | label: '工资定额', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | disabled: true, |
| | | precision: 2, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId', 'billingType'], |
| | | show: (values) => !!values.taskId, |
| | | componentProps: (values) => ({ |
| | | addonAfter: getWageRateUnit(values.billingType), |
| | | }), |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'workHours', |
| | | label: '报工工时(h)', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | // 废品分类变更,自动累计为不良品数量及报工数量 |
| | | onChange: async () => { |
| | | const values = await formApi?.getValues(); |
| | | const unqualified = |
| | | (values?.laborScrapQuantity || 0) + |
| | | (values?.materialScrapQuantity || 0) + |
| | | (values?.otherScrapQuantity || 0); |
| | | await formApi?.setValues({ |
| | | feedbackQuantity: (values?.qualifiedQuantity || 0) + unqualified, |
| | | unqualifiedQuantity: unqualified, |
| | | }); |
| | | placeholder: '请输入本次报工工时', |
| | | onChange: (value?: number) => { |
| | | hooks?.onWorkHoursChange?.(value); |
| | | recalculateWagePreview(); |
| | | }, |
| | | }, |
| | | defaultValue: 0, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag', 'unqualifiedQuantity'], |
| | | show: (values) => |
| | | !values.checkFlag && (values.unqualifiedQuantity || 0) > 0, |
| | | triggerFields: ['taskId', 'billingType'], |
| | | show: (values) => !!values.taskId && values.billingType === 1, |
| | | rules: (values) => |
| | | values.billingType === 1 |
| | | ? z.number().min(0.01, '计时计薪的工序必须填写大于 0 的报工工时') |
| | | : null, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'otherScrapQuantity', |
| | | label: '其他废品', |
| | | fieldName: 'wageAmount', |
| | | label: '报工工资', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | disabled: true, |
| | | precision: 2, |
| | | // 废品分类变更,自动累计为不良品数量及报工数量 |
| | | onChange: async () => { |
| | | const values = await formApi?.getValues(); |
| | | const unqualified = |
| | | (values?.laborScrapQuantity || 0) + |
| | | (values?.materialScrapQuantity || 0) + |
| | | (values?.otherScrapQuantity || 0); |
| | | await formApi?.setValues({ |
| | | feedbackQuantity: (values?.qualifiedQuantity || 0) + unqualified, |
| | | unqualifiedQuantity: unqualified, |
| | | }); |
| | | }, |
| | | }, |
| | | defaultValue: 0, |
| | | dependencies: { |
| | | triggerFields: ['checkFlag', 'unqualifiedQuantity'], |
| | | show: (values) => |
| | | !values.checkFlag && (values.unqualifiedQuantity || 0) > 0, |
| | | triggerFields: ['taskId', 'billingType'], |
| | | show: (values) => !!values.taskId, |
| | | componentProps: (values) => ({ |
| | | addonAfter: '元', |
| | | placeholder: |
| | | values.billingType === 1 |
| | | ? '按工时 × 工资定额自动计算' |
| | | : '按报工数量 × 工资定额自动计算', |
| | | }), |
| | | }, |
| | | }, |
| | | { |
| | |
| | | render: (val) => |
| | | h(DictTag, { type: DICT_TYPE.MES_PRO_FEEDBACK_TYPE, value: val }), |
| | | }, |
| | | { field: 'workOrderId', label: '生产订单', render: (_val, data) => data.workOrderCode }, |
| | | { field: 'taskId', label: '生产任务', render: (_val, data) => data.taskCode }, |
| | | { field: 'workOrderId', label: '生产订单', render: (_val, data) => data?.workOrderCode }, |
| | | { field: 'taskId', label: '生产任务', render: (_val, data) => data?.taskCode }, |
| | | { field: 'workstationName', label: '工作站' }, |
| | | { field: 'machineryName', label: '使用设备' }, |
| | | { field: 'itemCode', label: '产品编码' }, |
| | | { field: 'itemName', label: '产品名称' }, |
| | | { field: 'unitMeasureName', label: '单位' }, |
| | | { field: 'itemSpecification', label: '规格' }, |
| | | { field: 'reportableQuantity', label: '可报工数量' }, |
| | | { field: 'feedbackQuantity', label: '报工数量' }, |
| | | { |
| | | field: 'billingType', |
| | | label: '计费类型', |
| | | render: (val) => |
| | | FEEDBACK_BILLING_TYPE_OPTIONS.find((item) => item.value === val) |
| | | ?.label ?? '-', |
| | | }, |
| | | { field: 'wageRate', label: '工资定额' }, |
| | | { field: 'workHours', label: '报工工时(h)' }, |
| | | { field: 'auxPaidHours', label: '辅助计薪工时(h)' }, |
| | | { field: 'wageAmount', label: '报工工资(含质量调整)' }, |
| | | { field: 'auxWageAmount', label: '辅助工资' }, |
| | | { field: 'qualityPassRate', label: '过程检验合格率(%)' }, |
| | | { field: 'productionLength', label: '生产长度(米)' }, |
| | | { field: 'standardWorkHours', label: '标准工时(h)' }, |
| | | { field: 'standardPrimaryHours', label: '标准主工时(h)' }, |
| | | { field: 'standardAuxHours', label: '标准辅助工时(h)' }, |
| | | { field: 'workHoursDiff', label: '工时差异(h)' }, |
| | | { field: 'workHoursDiffRate', label: '工时差异率(%)' }, |
| | | { field: 'stdCalcNote', label: '标准工时计算依据' }, |
| | | { field: 'qualifiedQuantity', label: '合格品数量' }, |
| | | { field: 'unqualifiedQuantity', label: '不良品数量' }, |
| | | { field: 'laborScrapQuantity', label: '工废数量' }, |
| | | { field: 'materialScrapQuantity', label: '料废数量' }, |
| | | { field: 'otherScrapQuantity', label: '其他废品' }, |
| | | { field: 'feedbackUserNickname', label: '报工人' }, |
| | | { field: 'feedbackTime', label: '报工时间' }, |
| | | { |
| | | field: 'feedbackTime', |
| | | label: '报工时间', |
| | | render: (val) => formatDate(val) as string, |
| | | }, |
| | | { field: 'approveUserNickname', label: '审核人' }, |
| | | { field: 'remark', label: '备注' }, |
| | | ]; |