gaoluyang
2026-11-02 2fe330a44f9e8bdd8a1afd6124c57851f2a5b7ea
src/views/mes/pro/workorder/data.ts
@@ -1,7 +1,7 @@
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesMdProductBomApi } from '#/api/mes/md/item/productBom';
import type { MesProWorkOrderApi } from '#/api/mes/pro/workorder';
import { type MesProWorkOrderApi, getWorkOrderApproveProcessList } from '#/api/mes/pro/workorder';
import { getSimpleRoleList } from '#/api/system/role';
import type { MesProWorkOrderBomApi } from '#/api/mes/pro/workorder/bom';
import type { MesProWorkOrderProcessApi } from '#/api/mes/pro/workorder/process';
@@ -18,13 +18,14 @@
import { Button } from 'ant-design-vue';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { getFactorySimpleList } from '#/api/mes/md/factory';
import CrmCustomerSelect from '#/components/crm-customer-select.vue';
import { getRangePickerDefaultProps } from '#/utils';
import {
  MdItemSelect,
  MdProductBomSelect,
} from '#/views/mes/md/item/components';
import { MdVendorSelect } from '#/views/mes/md/vendor/components';
import MdWorkshopSelect from '#/views/mes/md/workstation/components/workshop-select.vue';
/** 表单类型 */
export type FormType = 'confirm' | 'create' | 'detail' | 'finish' | 'update';
@@ -108,6 +109,37 @@
      rules: 'required',
    },
    {
      fieldName: 'factoryId',
      label: '工厂',
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        api: getFactorySimpleList,
        disabled: headerReadonly,
        labelField: 'name',
        placeholder: '请选择工厂',
        valueField: 'id',
      },
      help: '选择工单所属工厂(生产主体),用于按工厂筛选工单、归集领料;工厂可在「工厂」基础资料中维护。',
    },
    {
      fieldName: 'workshopId',
      label: '车间',
      component: markRaw(MdWorkshopSelect),
      componentProps: {
        disabled: headerReadonly,
        placeholder: '请选择车间',
      },
      dependencies: {
        triggerFields: ['factoryId'],
        componentProps: (values: { factoryId?: number }) => ({
          disabled: headerReadonly,
          factoryId: values.factoryId,
        }),
      },
      help: '选择工厂后,此处只显示该工厂下的车间;用于派工与工位归属。',
    },
    {
      fieldName: 'orderSourceType',
      label: '订单来源',
      component: 'Select',
@@ -128,6 +160,10 @@
          }
        },
      },
      help: (values: { orderSourceType?: number }) =>
        values.orderSourceType === MesProWorkOrderSourceTypeEnum.ORDER
          ? '已选客户订单:需补充来源单据编号与客户,便于追溯订单来源。'
          : '用于区分订单业务归属;选「客户订单」时才需关联来源单据与客户。',
      rules: 'selectRequired',
    },
    {
@@ -143,6 +179,7 @@
        show: (values) =>
          values.orderSourceType === MesProWorkOrderSourceTypeEnum.ORDER,
      },
      help: '填写上游单据(如销售订单)的编号,用于追溯该订单的来源。',
    },
    {
      fieldName: 'type',
@@ -162,6 +199,11 @@
          }
        },
      },
      help: (values: { type?: number }) =>
        values.type === MesProWorkOrderTypeEnum.OUTSOURCE ||
        values.type === MesProWorkOrderTypeEnum.PURCHASE
          ? '已选委外/采购生产:需指定供应商,委外报工与入库将按该供应商结算。'
          : '自营生产按本单工序排产;选「委外加工」或「采购生产」时需额外指定供应商。',
      rules: 'selectRequired',
    },
    {
@@ -172,6 +214,7 @@
        disabled: headerReadonly,
        placeholder: '请选择产品',
      },
      help: '选择产品后,工序将自动从其工艺路线带出并按需调整;产品需先在「工艺流程」中配置路线与投料 BOM。',
      rules: 'selectRequired',
    },
    {
@@ -200,6 +243,7 @@
        show: (values) =>
          values.orderSourceType === MesProWorkOrderSourceTypeEnum.ORDER,
      },
      help: '关联客户后,订单可在客户维度追溯并对接后续结算。',
    },
    {
      fieldName: 'vendorId',
@@ -215,6 +259,7 @@
          values.type === MesProWorkOrderTypeEnum.OUTSOURCE ||
          values.type === MesProWorkOrderTypeEnum.PURCHASE,
      },
      help: '委外/采购订单需指定供应商,委外报工与入库均以该供应商为准。',
    },
    {
      fieldName: 'batchCode',
@@ -234,10 +279,63 @@
        disabled: headerReadonly,
        format: 'YYYY-MM-DD',
        placeholder: '请选择需求日期',
        valueFormat: 'x',
        valueFormat: 'YYYY-MM-DD',
      },
      help: '预计交付/完成日期,用于排产、进度跟踪与交期预警。',
      rules: 'required',
    },
    // {
    //   fieldName: 'feedbackRole',
    //   label: '报工角色',
    //   component: 'ApiSelect',
    //   componentProps: {
    //     api: getSimpleRoleList,
    //     disabled: headerReadonly,
    //     labelField: 'name',
    //     valueField: 'code',
    //     mode: 'multiple',
    //     placeholder: '请选择报工角色',
    //   },
    //   rules: 'selectRequired',
    // },
    {
      fieldName: 'feedbackApprove',
      label: '是否报工审批',
      component: 'Switch',
      componentProps: {
        class: '!w-auto',
        checkedChildren: '是',
        unCheckedChildren: '否',
        disabled: headerReadonly,
      },
      defaultValue: false,
      help: '开启后,生产报工提交需经审批通过才计入产量;关闭则报工直接生效。',
      rules: 'required',
    },
    {
      fieldName: 'processDefinitionKey',
      label: '审批流程',
      component: 'ApiSelect',
      componentProps: {
        api: getWorkOrderApproveProcessList,
        disabled: headerReadonly,
        labelField: 'name',
        valueField: 'key',
        placeholder: '请选择审批流程',
      },
      dependencies: {
        triggerFields: ['feedbackApprove'],
        show: (values) => !!values.feedbackApprove,
        rules(values) {
          if (values.feedbackApprove) {
            return 'selectRequired';
          }
          return undefined;
        },
      },
      help: '选择报工提交后走的审批流程;流程需先在系统「流程管理」中部署,仅「报工审批」类流程可选。',
    },
    {
      fieldName: 'remark',
      label: '备注',
@@ -271,6 +369,32 @@
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单名称',
      },
    },
    {
      fieldName: 'factoryId',
      label: '工厂',
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        api: getFactorySimpleList,
        labelField: 'name',
        placeholder: '请选择工厂',
        valueField: 'id',
      },
    },
    {
      fieldName: 'workshopId',
      label: '车间',
      component: markRaw(MdWorkshopSelect),
      componentProps: {
        placeholder: '请选择车间',
      },
      dependencies: {
        triggerFields: ['factoryId'],
        componentProps: (values: { factoryId?: number }) => ({
          factoryId: values.factoryId,
        }),
      },
    },
    {
@@ -337,6 +461,16 @@
      minWidth: 150,
    },
    {
      field: 'factoryName',
      title: '工厂',
      width: 120,
    },
    {
      field: 'workshopName',
      title: '车间',
      width: 120,
    },
    {
      field: 'type',
      title: '订单类型',
      width: 100,
@@ -390,11 +524,6 @@
      width: 100,
    },
    {
      field: 'clientCode',
      title: '客户编码',
      width: 120,
    },
    {
      field: 'clientName',
      title: '客户名称',
      width: 120,
@@ -402,6 +531,12 @@
    {
      field: 'requestDate',
      title: '需求日期',
      width: 180,
      formatter: 'formatDate',
    },
    {
      field: 'actualStartTime',
      title: '实际开工时间',
      width: 180,
      formatter: 'formatDate',
    },
@@ -415,147 +550,34 @@
      },
    },
    {
      field: 'started',
      title: '开工状态',
      width: 100,
      slots: { default: 'started' },
    },
    {
      field: 'processProgressList',
      title: '工序生产进度',
      width: 350,
      slots: { default: 'processProgressList' },
    },
    {
      field: 'completionProgress',
      title: '完成进度',
      width: 200,
      slots: { default: 'completionProgress' },
    },
    {
      field: 'createTime',
      title: '创建时间',
      width: 180,
      formatter: 'formatDateTime',
      formatter: 'formatDate',
    },
    {
      title: '操作',
      width: 240,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
/** 订单 BOM 子表的字段 */
export function useBomGridColumns(
  editable: boolean,
  generatable: boolean,
): VxeTableGridOptions<MesProWorkOrderBomApi.WorkOrderBom>['columns'] {
  return [
    {
      field: 'itemCode',
      title: 'BOM 物料编码',
      width: 120,
    },
    {
      field: 'itemName',
      title: 'BOM 物料名称',
      minWidth: 150,
    },
    {
      field: 'itemSpecification',
      title: '规格型号',
      width: 120,
    },
    {
      field: 'unitMeasureName',
      title: '单位',
      width: 80,
    },
    {
      field: 'itemOrProduct',
      title: '物料/产品',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_MD_ITEM_OR_PRODUCT },
      },
    },
    {
      field: 'quantity',
      title: '预计使用量',
      width: 120,
    },
    {
      field: 'remark',
      title: '备注',
      minWidth: 120,
    },
    ...(editable || generatable
      ? [
          {
            title: '操作',
            width: 160,
            fixed: 'right',
            slots: { default: 'actions' },
          } as const,
        ]
      : []),
  ];
}
/** 订单 BOM 新增/修改的表单 */
export function useBomFormSchema(
  isCreate: boolean,
  productId?: number,
  formApi?: VbenFormApi,
): VbenFormSchema[] {
  return [
    {
      fieldName: 'itemId',
      label: '物料',
      component: markRaw(MdProductBomSelect),
      componentProps: {
        itemId: productId,
        placeholder: '请选择物料',
        // BOM 物料选中后自动回填预计使用量
        onChange: async (bom?: MesMdProductBomApi.ProductBom) => {
          await formApi?.setFieldValue('quantity', bom?.quantity ?? undefined);
        },
      },
      rules: 'selectRequired',
      dependencies: {
        triggerFields: [''],
        show: () => isCreate,
      },
    },
    {
      fieldName: 'itemName',
      label: '物料',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
      dependencies: {
        triggerFields: [''],
        show: () => !isCreate,
      },
    },
    {
      fieldName: 'unitMeasureName',
      label: '单位',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
      dependencies: {
        triggerFields: [''],
        show: () => !isCreate,
      },
    },
    {
      fieldName: 'quantity',
      label: '预计使用量',
      component: 'InputNumber',
      componentProps: {
        class: '!w-full',
        min: 0,
        placeholder: '请输入预计使用量',
        precision: 2,
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入备注',
        rows: 3,
      },
    },
  ];
}
@@ -669,11 +691,6 @@
      width: 100,
    },
    {
      field: 'clientCode',
      title: '客户编码',
      width: 120,
    },
    {
      field: 'clientName',
      title: '客户名称',
      minWidth: 120,
@@ -747,7 +764,6 @@
            field: 'drag',
            title: '',
            width: 40,
            fixed: 'left',
            slots: { default: 'dragHandle' },
          } as const,
        ]
@@ -755,6 +771,7 @@
    {
      type: 'expand',
      width: 50,
      slots: { content: 'expand_content' },
    } as const,
    {
      field: 'sort',
@@ -819,14 +836,20 @@
      slots: { default: 'backflushFlag' },
    },
    {
      field: 'outputItemCode',
      title: '产出物料编码',
      width: 120,
      field: 'outputItemNames',
      title: '产出物料',
      width: 160,
    },
    {
      field: 'outputItemName',
      title: '产出物料名称',
      width: 120,
      field: 'warehouseName',
      title: '报工仓库',
      width: 130,
      formatter: ({ cellValue, row }) => {
        if (!cellValue) return '-';
        return row.areaName
          ? `${cellValue}/${row.locationName ?? ''}/${row.areaName}`
          : cellValue;
      },
    },
    {
      field: 'remark',
@@ -835,7 +858,7 @@
    },
    {
      title: '操作',
      width: 120,
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },