liu
3 天以前 726b359e53c1ee75bd756212c9b6e2a02c23b6b3
src/views/mes/pro/task/data.ts
@@ -1,5 +1,9 @@
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { z } from '#/adapter/form';
import { getSimpleUserListByRoleCode } from '#/api/system/user';
import { getTemplatePage } from '#/api/mes/pro/processdesign/template';
import { getUserListByWorkstationId } from '#/api/mes/md/workstation/worker';
import type { MesProTaskApi } from '#/api/mes/pro/task';
import type { MesProWorkOrderApi } from '#/api/mes/pro/workorder';
@@ -130,19 +134,43 @@
      width: 80,
    },
    {
      field: 'status',
      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: 'quantity',
      title: '订单数量',
      width: 100,
    },
    {
      field: 'quantityChanged',
      title: '调整数量',
      width: 100,
    },
    // {
    //   field: 'quantityChanged',
    //   title: '调整数量',
    //   width: 100,
    // },
    {
      field: 'quantityProduced',
      title: '已生产数量',
      width: 100,
    },
    {
      field: 'progressPercent',
      title: '完成进度',
      width: 150,
      slots: { default: 'progressPercent' },
    },
    {
      field: 'clientCode',
@@ -160,15 +188,7 @@
      width: 120,
      formatter: 'formatDate',
    },
    {
      field: 'status',
      title: '排产状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_PRO_WORK_ORDER_STATUS },
      },
    },
    {
      title: '操作',
      width: 160,
@@ -335,6 +355,12 @@
      width: 120,
    },
    {
      field: 'paramTemplateId',
      title: '工艺参数模板',
      minWidth: 140,
      formatter: ({ cellValue }) => cellValue ? `模板 #${cellValue}` : '未配置',
    },
    {
      field: 'quantity',
      title: '排产数量',
      width: 100,
@@ -383,6 +409,19 @@
/** 生产任务新增/修改的表单 */
export function useTaskFormSchema(formApi?: VbenFormApi, workOrderQuantity?: Ref<number | undefined>): VbenFormSchema[] {
  return [
    {
      fieldName: 'paramTemplateId',
      label: '工艺参数模板',
      component: 'ApiSelect',
      componentProps: {
        api: () => getTemplatePage({ pageNo: 1, pageSize: 100 }),
        labelField: 'templateName',
        valueField: 'id',
        resultField: 'list',
        allowClear: true,
        placeholder: '请选择工艺参数模板',
      },
    },
    {
      fieldName: 'workstationId',
      label: '工作站',
@@ -458,6 +497,27 @@
      },
    },
    {
      fieldName: 'assigneeUserIds',
      label: '报工人',
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择报工人',
        api: getUserListByWorkstationId,
        labelField: 'nickname',
        valueField: 'id',
        mode: 'multiple',
      },
      dependencies: {
        triggerFields: ['workstationId'],
        componentProps: (values) => ({
          params: { workstationId: values.workstationId },
          disabled: !values.workstationId,
          placeholder: values.workstationId ? '请选择报工人' : '请先选择工作站',
        }),
      },
      rules: z.array(z.number()).min(1, '请选择报工人').default([]),
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
@@ -474,6 +534,18 @@
async function recalcDuration(formApi?: VbenFormApi) {
  if (!formApi) return;
  const values = await formApi.getValues();
  if (values.workstationId) {
    try {
      const users = await getUserListByWorkstationId({ workstationId: values.workstationId });
      if (!users || users.length === 0) {
        message.warning('当前工作站没有配置人力资源');
      }
    } catch {
      // ignore
    }
  }
  if (!values.workstationId || !values.quantity) return;
  try {
    const res = await calculateTaskDuration(values.workstationId, values.quantity);