src/views/mes/pro/workorder/data.ts
@@ -1,8 +1,9 @@
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';
import { h, markRaw } from 'vue';
@@ -11,17 +12,16 @@
  MesAutoCodeRuleCode,
  MesProWorkOrderSourceTypeEnum,
  MesProWorkOrderTypeEnum,
} from '..\..\..\..\packages\constants\src';
import { getDictOptions } from '..\..\..\..\packages\effects\hooks\src';
} from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { Button } from 'ant-design-vue';
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import CrmCustomerSelect from '#/components/crm-customer-select.vue';
import { getRangePickerDefaultProps } from '#/utils';
import { MdClientSelect } from '#/views/mes/md/client/components';
import {
  MdItemSelect,
  MdProductBomSelect,
} from '#/views/mes/md/item/components';
import { MdVendorSelect } from '#/views/mes/md/vendor/components';
@@ -58,7 +58,7 @@
    },
    {
      fieldName: 'status',
      label: '工单状态',
      label: '订单状态',
      component: 'Select',
      componentProps: {
        disabled: true,
@@ -71,11 +71,11 @@
    },
    {
      fieldName: 'code',
      label: '工单编码',
      label: '订单编码',
      component: 'Input',
      componentProps: {
        disabled: headerReadonly,
        placeholder: '请输入工单编码',
        placeholder: '请输入订单编码',
      },
      rules: 'required',
      suffix:
@@ -98,17 +98,17 @@
    },
    {
      fieldName: 'name',
      label: '工单名称',
      label: '订单名称',
      component: 'Input',
      componentProps: {
        disabled: headerReadonly,
        placeholder: '请输入工单名称',
        placeholder: '请输入订单名称',
      },
      rules: 'required',
    },
    {
      fieldName: 'orderSourceType',
      label: '工单来源',
      label: '订单来源',
      component: 'Select',
      componentProps: {
        disabled: headerReadonly,
@@ -116,8 +116,8 @@
          DICT_TYPE.MES_PRO_WORK_ORDER_SOURCE_TYPE,
          'number',
        ),
        placeholder: '请选择工单来源',
        // 工单来源变更:非客户订单时清空来源单据编号和客户
        placeholder: '请选择订单来源',
        // 订单来源变更:非客户订单时清空来源单据编号和客户
        onChange: async (value: number) => {
          if (value !== MesProWorkOrderSourceTypeEnum.ORDER) {
            await formApi?.setValues({
@@ -145,13 +145,13 @@
    },
    {
      fieldName: 'type',
      label: '工单类型',
      label: '订单类型',
      component: 'Select',
      componentProps: {
        disabled: headerReadonly,
        options: getDictOptions(DICT_TYPE.MES_PRO_WORK_ORDER_TYPE, 'number'),
        placeholder: '请选择工单类型',
        // 工单类型变更:非代工/采购时清空供应商
        placeholder: '请选择订单类型',
        // 订单类型变更:非代工/采购时清空供应商
        onChange: async (value: number) => {
          if (
            value !== MesProWorkOrderTypeEnum.OUTSOURCE &&
@@ -175,13 +175,13 @@
    },
    {
      fieldName: 'quantity',
      label: '工单数量',
      label: '订单数量',
      component: 'InputNumber',
      componentProps: {
        class: '!w-full',
        disabled: headerReadonly,
        min: 1,
        placeholder: '请输入工单数量',
        placeholder: '请输入订单数量',
        precision: 2,
      },
      rules: 'required',
@@ -189,7 +189,7 @@
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: markRaw(CrmCustomerSelect),
      componentProps: {
        disabled: headerReadonly,
        placeholder: '请选择客户',
@@ -233,10 +233,60 @@
        disabled: headerReadonly,
        format: 'YYYY-MM-DD',
        placeholder: '请选择需求日期',
        valueFormat: 'x',
        valueFormat: 'YYYY-MM-DD',
      },
      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,
      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;
        },
      },
    },
    {
      fieldName: 'remark',
      label: '备注',
@@ -256,20 +306,20 @@
  return [
    {
      fieldName: 'code',
      label: '工单编码',
      label: '订单编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入工单编码',
        placeholder: '请输入订单编码',
      },
    },
    {
      fieldName: 'name',
      label: '工单名称',
      label: '订单名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入工单名称',
        placeholder: '请输入订单名称',
      },
    },
    {
@@ -292,19 +342,19 @@
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: markRaw(CrmCustomerSelect),
      componentProps: {
        placeholder: '请选择客户',
      },
    },
    {
      fieldName: 'type',
      label: '工单类型',
      label: '订单类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.MES_PRO_WORK_ORDER_TYPE, 'number'),
        placeholder: '请选择工单类型',
        placeholder: '请选择订单类型',
      },
    },
    {
@@ -324,7 +374,7 @@
  return [
    {
      field: 'code',
      title: '工单编码',
      title: '订单编码',
      fixed: 'left',
      width: 200,
      treeNode: true,
@@ -332,12 +382,12 @@
    },
    {
      field: 'name',
      title: '工单名称',
      title: '订单名称',
      minWidth: 150,
    },
    {
      field: 'type',
      title: '工单类型',
      title: '订单类型',
      width: 100,
      cellRender: {
        name: 'CellDict',
@@ -346,7 +396,7 @@
    },
    {
      field: 'orderSourceType',
      title: '工单来源',
      title: '订单来源',
      width: 100,
      cellRender: {
        name: 'CellDict',
@@ -380,7 +430,7 @@
    },
    {
      field: 'quantity',
      title: '工单数量',
      title: '订单数量',
      width: 100,
    },
    {
@@ -406,12 +456,33 @@
    },
    {
      field: 'status',
      title: '工单状态',
      title: '订单状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_PRO_WORK_ORDER_STATUS },
      },
    },
    {
      field: 'productionStatus',
      title: '生产状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.ORDER_PRODUCTION_STATUS },
      },
    },
    {
      field: 'processProgressList',
      title: '工序生产进度',
      width: 350,
      slots: { default: 'processProgressList' },
    },
    {
      field: 'completionProgress',
      title: '完成进度',
      width: 200,
      slots: { default: 'completionProgress' },
    },
    {
      field: 'createTime',
@@ -428,156 +499,25 @@
  ];
}
/** 工单 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,
      },
    },
  ];
}
/** 工单选择弹窗的搜索表单 */
/** 订单选择弹窗的搜索表单 */
export function useWorkOrderSelectGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'code',
      label: '工单编码',
      label: '订单编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入工单编码',
        placeholder: '请输入订单编码',
      },
    },
    {
      fieldName: 'name',
      label: '工单名称',
      label: '订单名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入工单名称',
        placeholder: '请输入订单名称',
      },
    },
    {
@@ -591,25 +531,25 @@
    {
      fieldName: 'clientId',
      label: '客户',
      component: markRaw(MdClientSelect),
      component: markRaw(CrmCustomerSelect),
      componentProps: {
        placeholder: '请选择客户',
      },
    },
    {
      fieldName: 'status',
      label: '工单状态',
      label: '订单状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.MES_PRO_WORK_ORDER_STATUS, 'number'),
        placeholder: '请选择工单状态',
        placeholder: '请选择订单状态',
      },
    },
  ];
}
/** 工单选择弹窗的字段 */
/** 订单选择弹窗的字段 */
export function useWorkOrderSelectGridColumns(
  multiple = false,
): VxeTableGridOptions<MesProWorkOrderApi.WorkOrder>['columns'] {
@@ -620,17 +560,17 @@
    },
    {
      field: 'code',
      title: '工单编码',
      title: '订单编码',
      width: 180,
    },
    {
      field: 'name',
      title: '工单名称',
      title: '订单名称',
      minWidth: 180,
    },
    {
      field: 'orderSourceType',
      title: '工单来源',
      title: '订单来源',
      width: 100,
      cellRender: {
        name: 'CellDict',
@@ -664,7 +604,7 @@
    },
    {
      field: 'quantity',
      title: '工单数量',
      title: '订单数量',
      width: 100,
    },
    {
@@ -679,7 +619,7 @@
    },
    {
      field: 'status',
      title: '工单状态',
      title: '订单状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
@@ -695,7 +635,7 @@
  ];
}
/** 工单物料需求子表的字段(只读) */
/** 订单物料需求子表的字段(只读) */
export function useItemGridColumns(): VxeTableGridOptions<MesProWorkOrderBomApi.WorkOrderBom>['columns'] {
  return [
    {
@@ -734,3 +674,104 @@
    },
  ];
}
/** 订单工序列表的字段 */
export function useProcessGridColumns(
  draggable = false,
): VxeTableGridOptions<MesProWorkOrderProcessApi.WorkOrderProcess>['columns'] {
  return [
    ...(draggable
      ? [
          {
            field: 'drag',
            title: '',
            width: 40,
            slots: { default: 'dragHandle' },
          } as const,
        ]
      : []),
    {
      type: 'expand',
      width: 50,
      slots: { content: 'expand_content' },
    } as const,
    {
      field: 'sort',
      title: '序号',
      width: 80,
    },
    {
      field: 'processCode',
      title: '工序编码',
      width: 120,
    },
    {
      field: 'processName',
      title: '工序名称',
      minWidth: 150,
    },
    {
      field: 'nextProcessName',
      title: '下一道工序',
      width: 120,
    },
    {
      field: 'linkType',
      title: '工序关系',
      width: 100,
      formatter: ({ cellValue }) => {
        const map: Record<number, string> = {
          0: '开始-开始',
          1: '结束-结束',
          2: '开始-结束',
          3: '结束-开始',
        };
        return map[cellValue] ?? '-';
      },
    },
    {
      field: 'prepareTime',
      title: '准备时间(分)',
      width: 100,
    },
    {
      field: 'waitTime',
      title: '等待时间(分)',
      width: 100,
    },
    {
      field: 'keyFlag',
      title: '关键工序',
      width: 80,
      slots: { default: 'keyFlag' },
    },
    {
      field: 'checkFlag',
      title: '质检工序',
      width: 80,
      slots: { default: 'checkFlag' },
    },
    {
      field: 'backflushFlag',
      title: '倒冲',
      width: 80,
      slots: { default: 'backflushFlag' },
    },
    {
      field: 'outputItemNames',
      title: '产出物料',
      width: 160,
    },
    {
      field: 'remark',
      title: '备注',
      minWidth: 120,
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}