Ben Lin
2024-07-30 cc88111d61a350a4d24cf339b526d4357f934ddf
src/views/tigerprojects/system/lowcode/entityts/BIZ_MES_WO_BATCH.ts
@@ -4,18 +4,22 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-20 22:29:35
 * @LastEditTime: 2024-07-25 21:44:58
 */
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 { getEntity, GetEnum, 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';
const { getLocale } = useLocale();
const { createMessage, createErrorModal } = useMessage();
const { t } = useI18n();
function _default() {
@@ -36,7 +40,7 @@
     * @description: 获取新增按钮的行为,必需要有的方法
     * @return {*}
     */
    CreateAction: (fnName: string) => {
    CreateAction: (type: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
@@ -46,6 +50,16 @@
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      data.map((x) => {
        if (x.name == 'handlePause') {
          x.onClick = handlePause.bind(null, args, params);
          x.tooltip = '暂停';
        }
        if (x.name == 'handleRelease') {
          x.onClick = handleRelease.bind(null, args, params);
          x.tooltip = '下发';
        }
      });
      return data;
    },
    /**
@@ -173,10 +187,296 @@
      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'];
          wo.STATUS = 2;
          wo.ACT_LINE = param.values['forminfo'].ACT_LINE;
          SaveEntity(wo, true, 'BIZ_MES_WO_BATCH').then((action) => {
            if (action.IsSuccessed) {
              resolve(action);
            } else {
              reject(action);
            }
          });
        } catch {
          reject(false);
        }
      });
    },
  };
  /**
   * @description: 工单暂停方法
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handlePause(args, params: Recordable) {
    const reload = args[1];
    if (params['record'].STATUS == 0) {
      createErrorModal({
        title: t('警告'),
        content: t('工单是初始化状态,不能暂停!'),
        getContainer: () => document.body,
      });
      return;
    }
    if (params['record'].STATUS == 5) {
      createErrorModal({
        title: t('警告'),
        content: t('工单是完成状态,不能暂停!'),
        getContainer: () => document.body,
      });
      return;
    }
    params['record'].STATUS = 4;
    SaveEntity(params['record'], true, 'BIZ_MES_WO_BATCH').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];
    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'], //表单记录
    });
  }
  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];
}