Ben Lin
2025-03-05 abbc201b41a1a25a19ccf7cff8df633dadcf5d88
src/views/tigerprojects/system/lowcode/entityts/BIZ_MES_WO_BATCH.ts
@@ -4,27 +4,34 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-20 22:29:35
 * @LastEditTime: 2024-09-29 21:28:37
 */
import { Tag, Tooltip } from 'ant-design-vue';
import { ActionItem, BasicColumn } from '/@/components/Table';
import { ActionItem, BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { h, unref } from 'vue';
import { GetEnum } from '/@/api/tigerapi/system';
import { h } from 'vue';
import { getEntity, SaveEntity } from '/@/api/tigerapi/system';
import { useLocale } from '/@/locales/useLocale';
import { useModal } from '/@/components/Modal';
import { CustModalParams, FunctionType } from '/@/api/tigerapi/model/systemModel';
import { useForm } from '/@/components/Form';
import { useMessage } from '/@/hooks/web/useMessage';
import { UpdateWoBatchStatus } from '/@/api/tigerapi/mes/wo';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
const { getLocale } = useLocale();
const { createMessage, createErrorModal } = useMessage();
const { t } = useI18n();
function _default() {
  const ActionColumn: BasicColumn = {
    width: 80,
    width: 180,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: undefined,
    fixed: 'right',
  };
  /**
@@ -36,7 +43,7 @@
     * @description: 获取新增按钮的行为,必需要有的方法
     * @return {*}
     */
    CreateAction: (fnName: string) => {
    CreateAction: (type: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
@@ -46,6 +53,25 @@
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      data.map((x) => {
        if (x.name == 'handlePause') {
          x.onClick = handlePause.bind(null, args, params);
          x.color = 'error';
          x.tooltip = '暂停';
        }
        if (x.name == 'handleStart') {
          x.onClick = handleStart.bind(null, args, params);
          x.tooltip = '取消暂停';
        }
        if (x.name == 'handleRelease') {
          x.onClick = handleRelease.bind(null, args, params);
          x.tooltip = '下发';
        }
        if (x.name == 'handleUnRelease') {
          x.onClick = handleUnRelease.bind(null, args, params);
          x.tooltip = '取消下发';
        }
      });
      return data;
    },
    /**
@@ -141,6 +167,13 @@
          resizable: true,
        },
        {
          dataIndex: 'PLAN_DATE',
          title: '计划日期',
          ifShow: true,
          sorter: true,
          resizable: true,
        },
        {
          dataIndex: 'ACT_START_TIME',
          title: '实际开始时间',
          ifShow: true,
@@ -173,10 +206,377 @@
      return { ORDER_NO: val };
    },
    GetUseForm: () => {
      return {};
      return {
        forminfo: useForm({
          labelWidth: 120,
          schemas: woformSchema,
          actionColOptions: {
            span: 24,
          },
          showActionButtonGroup: false,
        }),
      };
    },
    /**
     * @description: 自定义方法
     * @param {string} type
     * @param {array} args
     * @return {*}
     */
    CustFunc: (param: CustModalParams) => {
      switch (param.cType) {
        case 'BIZ_MES_WO_BATCH':
          return getWoFns[param.FnName](param) as Promise<any>;
          break;
        default:
          return new Promise((resolve, reject) => {
            try {
              (e) => {};
              resolve(true);
            } catch {
              reject(false);
            } finally {
              // args[0][0]({ confirmLoading: false });
            }
          });
        // break;
      }
    },
    /**
     * @description: 获取多表单插槽列表
     * @return {*}
     */
    GetDtlSlots: (type: string) => {
      let result = [] as any[];
      switch (type) {
        case 'BIZ_MES_WO_BATCH':
          result = [
            {
              name: 'forminfo',
              slots: ['add', 'set'],
              preIcons: { add: 'search|svg', set: 'config|svg' }, //如果是多个表单,增加多个插槽。slots是弹出框按钮的插槽,preIcons是插槽对应的按钮图标
              title: '下发配置',
            },
          ];
          break;
      }
      return result;
    },
    /**
     * @description: 获取模态框应用列表
     * @return {*}
     */
    GetUseModals: () => {
      return {
        useModalData: {
          add: useModal(),
          set: useModal(),
          addRot: useModal(),
          setRot: useModal(),
        },
      };
    },
    /**
     * @description: 弹出选择框选择成功返回方法
     * @param {*} d
     * @param {*} u
     * @return {*}
     */
    GetSelectSuccess: (d, u) => {
      return {
        ROUTE_CODE: d.values['val'],
        // ID: d.values['id'],
        ROT_ID: d.values['id'],
      };
    },
    /**
     * @description: 打开弹出选择框
     * @param {Fn} openItemModal
     * @param {array} args
     * @return {*}
     */
    OpenSelectItem: (openItemModal: Fn, ...args) => {
      const slotName = args[0];
      switch (slotName) {
        case 'addRot':
        case 'add':
          openItemModal(true, {
            title: '工艺路线列表',
            schemas: [
              {
                field: 'ROT_CODE',
                component: 'Input',
                label: '工艺路线编码',
                colProps: {
                  span: 12,
                },
              },
            ],
            ItemColumns: [
              {
                title: t('工艺路线编码'),
                dataIndex: 'ROT_CODE',
                resizable: true,
                sorter: true,
                width: 200,
              },
              {
                title: t('工艺路线名称'),
                dataIndex: 'ROT_NAME',
                resizable: true,
                sorter: true,
                width: 180,
              },
            ],
            tableName: 'MES_ROUTE',
            rowKey: 'ROT_CODE',
            returnFieldName: ['ROUTE_CODE', 'ROT_ID'], //返回值要赋值的字段名称
            searchInfo: { TABLE_NAME: 'MES_ROUTE' },
          });
          break;
      }
    },
  };
  /* 以下是内部方法,不export,供上面的方法调用 */
  /**
   * @description: 自定义方法
   * @return {*}
   */
  const getWoFns: Record<string, FunctionType> = {
    /**
     * @description: 工单下发保存方法
     * @param {CustModalParams} param
     * @return {*}
     */
    SaveWoBatch: (param: CustModalParams) => {
      return new Promise((resolve, reject) => {
        try {
          const wo = param.values['mValues'];
          /* 更新工单批次状态 */
         return  UpdateWoBatchStatus({
            UserId: useUserStore().getUserInfo.userId as string,
            WorkOrder: wo.ORDER_NO,
            WoBatch: wo.BATCH_NO,
            ActLine: param.values['forminfo'].ACT_LINE,
            Status: 2,
            RouteStatus: 0,
          }).then((action) => {
            resolve(action);
          });
        } catch {
          reject(false);
        }
      });
    },
  };
  /**
   * @description: 工单暂停方法
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handlePause(args, params: Recordable) {
    const reload = args[1];
    if (params['record'].STATUS != 3) {
      createErrorModal({
        title: t('警告'),
        content: t('工单不是生产中状态,不能暂停!'),
        getContainer: () => document.body,
      });
      return;
    }
    /* 更新工单批次状态 */
    UpdateWoBatchStatus({
      UserId: useUserStore().getUserInfo.userId as string,
      WorkOrder: params['record'].ORDER_NO,
      WoBatch: params['record'].BATCH_NO,
      Status: 4,
      RouteStatus: 0,
      ActLine: ''
    }).then((action) => {
      if (action.IsSuccessed) {
        createMessage.success(t('已暂停'));
        reload();
      } else {
        createMessage.success(t(action.Message));
      }
    });
  }
  /**
   * @description: 工单取消暂停方法
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handleStart(args, params: Recordable) {
    const reload = args[1];
    if (params['record'].STATUS != 4) {
      createErrorModal({
        title: t('警告'),
        content: t('工单不是暂停状态,不能取消暂停!'),
        getContainer: () => document.body,
      });
      return;
    }
     /* 更新工单批次状态 */
     UpdateWoBatchStatus({
       UserId: useUserStore().getUserInfo.userId as string,
       WorkOrder: params['record'].ORDER_NO,
       WoBatch: params['record'].BATCH_NO,
       Status: 3,
       RouteStatus: 0,
       ActLine: ''
     }).then((action) => {
      if (action.IsSuccessed) {
        createMessage.success(t('暂停已取消'));
        reload();
      } else {
        createMessage.success(t('取消暂停操作失败'));
      }
    });
  }
  /**
   * @description: 工单下发方法
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handleRelease(args, params: Recordable) {
    const openCustModal = args[7];
    if (params['record'].STATUS != 0) {
      createErrorModal({
        title: t('警告'),
        content: t('工单不是初始状态,不能下发!'),
        getContainer: () => document.body,
      });
      return;
    }
    openCustModal(true, {
      isUpdate: true, //是否更新操作
      ctype: 'BIZ_MES_WO_BATCH', //是哪个页面
      title: '工单下发', //标题
      width: '900px', //弹出框宽度
      formEl: params['useFormData'].value,
      formElName: ['forminfo'], //表单插槽名称
      RowKeys: { add: 'ROUTE_CODE', set: 'ROUTE_CODE' }, //插槽的弹出框选择的code
      fnName: 'SaveWoBatch', //保存方法名
      initFnName: {}, //初始化方法名,没有就留空{}
      values: params['record'], //表单记录
    });
  }
  /**
   * @description: 工单取消下发方法
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handleUnRelease(args, params: Recordable) {
    const reload = args[1];
    if (params['record'].STATUS != 2) {
      createErrorModal({
        title: t('警告'),
        content: t('工单不是下发状态,不能取消下发!'),
        getContainer: () => document.body,
      });
      return;
    }
    /* 更新工单批次状态 */
    UpdateWoBatchStatus({
      UserId: useUserStore().getUserInfo.userId as string,
      WorkOrder: params['record'].ORDER_NO,
      WoBatch: params['record'].BATCH_NO,
      Status: 0, //取消下发状态
      RouteStatus: 0,
      ActLine: ''
    }).then((action) => {
      if (action.IsSuccessed) {
        createMessage.success(t('下发已取消'));
        reload();
      } else {
        createErrorModal({
          title: t('警告'),
          content: t(action.Message),
          getContainer: () => document.body,
        });
      }
    });
  }
  const woformSchema: FormSchema[] = [
    {
      field: 'PLAN_QTY',
      label: '工单数量',
      component: 'Input',
      required: true,
      colProps: {
        span: 24,
      },
      dynamicDisabled: ({ values }) => {
        return true;
      },
    },
    // {
    //   field: 'RELEASE_QTY',
    //   label: '工单下发数量',
    //   component: 'Input',
    //   required: true,
    //   colProps: {
    //     span: 24,
    //   },
    // },
    {
      label: '实际产线',
      field: 'ACT_LINE',
      component: 'ApiSelect',
      required: true,
      colProps: {
        span: 24,
      },
      componentProps: {
        api: getEntity,
        params: { entityName: 'MES_LINE', sqlcmd: ' 1=1 ', order: '' },
        resultField: 'Data.Items',
        labelField: 'LINE_NAME',
        valueField: 'LINE_CODE',
      },
    },
    // {
    //   label: '工艺路线',
    //   field: 'ROUTE_CODE',
    //   component: 'Input',
    //   required: true,
    //   colProps: {
    //     span: 22,
    //   },
    // },
    // {
    //   field: 'add',
    //   component: 'Input',
    //   label: '1',
    //   colSlot: 'add',
    //   defaultValue: 'MES_ROUTE',
    //   colProps: {
    //     span: 1,
    //   },
    // },
    // {
    //   field: 'set',
    //   component: 'Input',
    //   label: '1',
    //   colSlot: 'set',
    //   defaultValue: 'MES_ROUTE',
    //   colProps: {
    //     span: 1,
    //   },
    // },
  ];
  return [methods, ActionColumn];
}