| | |
| | | |
| | | 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 { getProcess } from '#/api/mes/pro/process'; |
| | | import { getSimpleUserList } from '#/api/system/user'; |
| | | import { loadParamDetails } from './param-state'; |
| | | |
| | |
| | | |
| | | /** 生产报工表单类型 */ |
| | | 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: '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 }, |
| | |
| | | * 报工只填写"报工数量";合格品/不良品数量由质检确定,报工环节不采集。 |
| | | * 报工审批后产出均待检验,合格品经检验后入库。 |
| | | */ |
| | | /** 报工表单与工时试算组件的联动回调 */ |
| | | 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', |
| | |
| | | workstationId: task.workstationId, |
| | | reportableQuantity: task.reportableQuantity, |
| | | }); |
| | | // 带出工序的计费类型与工资定额,用于展示和即时预览报工工资 |
| | | 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', |
| | |
| | | min: 0, |
| | | precision: 2, |
| | | placeholder: '请输入报工数量', |
| | | onChange: () => recalculateWagePreview(), |
| | | }, |
| | | rules: 'required', |
| | | }, |
| | | { |
| | | fieldName: 'productionLength', |
| | | label: '生产长度(米)', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | min: 0, |
| | | precision: 2, |
| | | placeholder: '用于标准工时计算;单位为米时默认等于报工数量', |
| | | onChange: (value?: number) => |
| | | hooks?.onProductionLengthChange?.(value), |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId'], |
| | | show: (values) => |
| | | !!values.taskId && ['create', 'update'].includes(formType), |
| | | }, |
| | | }, |
| | | { |
| | | 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, |
| | | placeholder: '请输入本次报工工时', |
| | | onChange: (value?: number) => { |
| | | hooks?.onWorkHoursChange?.(value); |
| | | recalculateWagePreview(); |
| | | }, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId', 'billingType'], |
| | | show: (values) => !!values.taskId && values.billingType === 1, |
| | | rules: (values) => |
| | | values.billingType === 1 |
| | | ? z.number().min(0.01, '计时计薪的工序必须填写大于 0 的报工工时') |
| | | : null, |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'wageAmount', |
| | | label: '报工工资', |
| | | component: 'InputNumber', |
| | | componentProps: { |
| | | class: 'w-full', |
| | | disabled: true, |
| | | precision: 2, |
| | | }, |
| | | dependencies: { |
| | | triggerFields: ['taskId', 'billingType'], |
| | | show: (values) => !!values.taskId, |
| | | componentProps: (values) => ({ |
| | | addonAfter: '元', |
| | | placeholder: |
| | | values.billingType === 1 |
| | | ? '按工时 × 工资定额自动计算' |
| | | : '按报工数量 × 工资定额自动计算', |
| | | }), |
| | | }, |
| | | }, |
| | | { |
| | | fieldName: 'feedbackUserId', |
| | |
| | | { 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: '工废数量' }, |