Ben Lin
2024-09-24 3bf0e1e45acfb85fb6054dc55d1c1204a6750998
src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts
@@ -4,7 +4,7 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-08-21 01:51:03
 * @LastEditTime: 2024-09-24 09:28:56
 */
import { Ref, h, ref, render, unref } from 'vue';
@@ -21,13 +21,16 @@
import { NavItem } from '/@/api/tigerapi/model/basModel';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
import { BasicColumn, FormSchema, useTable } from '/@/components/Table';
import { ActionItem, BasicColumn, FormSchema, useTable } from '/@/components/Table';
import { CustModalParams } from '/@/api/tigerapi/model/systemModel';
import { useUserStore } from '/@/store/modules/user';
import { EventDataNode } from 'ant-design-vue/lib/tree';
import { ContextMenuItem } from '/@/components/TigerTree';
import { UpdateWoStatus } from '/@/api/tigerapi/mes/wo';
import { AddOrEditLabelVarByWorkOrder, UpdateWoStatus } from '/@/api/tigerapi/mes/wo';
import { useForm } from '/@/components/Form';
import { BAS_LABEL_VAR_WO } from '/@/api/tigerapi/model/mesModel';
import { buildUUID } from '/@/utils/uuid';
import { mesApi } from '/@/api/tigerapi/mes/mesApi';
const { t } = useI18n();
const { createErrorModal } = useMessage();
@@ -110,6 +113,19 @@
      return data;
    },
    /**
     * @description: 操作字段自定义按钮,必需要有的方法
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      data.push({
        icon: 'template|svg',
        tooltip: '模板维护',
        onClick: handleTemplate.bind(null, args, params),
        name: '模板维护',
      });
      return data;
    },
    /**
     * @description: 获取配置项表单字段,根据树形节点type不同而不同
     * @param {string} type
     * @return {*}
@@ -134,7 +150,15 @@
     * @return {*}
     */
    GetCrudColSlots: () => {
      return ['scanadd', 'assyadd', 'testadd', 'auditadd', 'printadd', 'pkgadd'];
      return [
        { name: 'scanadd', icon: 'search|svg' },
        { name: 'assyadd', icon: 'search|svg' },
        { name: 'testadd', icon: 'search|svg' },
        { name: 'auditadd', icon: 'search|svg' },
        { name: 'printadd', icon: 'search|svg' },
        { name: 'pkgadd', icon: 'search|svg' },
        { name: 'labeladd', icon: 'template|svg' },
      ];
    },
    /**
     * @description: 获取表格use列表
@@ -366,6 +390,9 @@
     */
    OpenSelectItem: (openItemModal: Fn, ...args) => {
      let config = {};
      const openCrudModal = args[1];
      const record = args[2];
      const OrderNo = args[3];
      switch (args[0]) {
        case 'scanadd':
          config = ruleModalCfg;
@@ -383,7 +410,35 @@
          config = pkgModalCfg;
          break;
      }
      openItemModal(true, config);
      if (args[0] == 'labeladd') {
        openCrudModal(true, {
          isUpdate: true, //是否更新操作
          entityName: 'WoRouteBinding', //是哪个页面
          ctype: 'BAS_LABEL_VAR_WO', //实体名称
          title: '模板维护', //标题
          width: '1024px', //弹出框宽度
          ItemColumns: TemplateBasColumn, //弹出框中表格字段结构
          schemas: [], //查询条件字段结构
          others: { WORK_ORDER: OrderNo }, //需要带到弹出窗口中的数据
          searchInfo: {
            TABLE_NAME: 'BAS_LABEL_VAR_WO', //实体名称
            LabelId: record.LABEL_CODE, //模板ID
            WorkOrder: OrderNo, //工单号
            apiUrl: mesApi.GetLabelVarByWorkOrder, //自定义获取数据分页的api,不用默认的基础方法
            // sqlcmd: ` (WORK_ORDER = '${OrderNo}' OR WORK_ORDER = '' OR WORK_ORDER IS NULL)`,
            // option:
            // {
            //   //根据据点查询,必需带这个参数
            //   UserId: useUserStore().getUserInfo.userId,
            //   ByOrg: true,
            //   CurOrg: useUserStore().getUserInfo.orgCode,
            // },
          },
          values: record, //表单记录
        });
      } else {
        openItemModal(true, config);
      }
    },
    /**
     * @description: 弹出选择框选择成功返回
@@ -432,6 +487,8 @@
            isShow: { BAS_PKG_DTL: false, ItemCode: false },
          };
          break;
        case 'labeladd':
          break;
        case 'pkgadd':
          const ents = await getEntity({
            sqlcmd: `RULE_CODE ='${d.values['val']}'`,
@@ -461,6 +518,7 @@
            WorkOrder: args[1]['CODE'],
            Status: -1,
            RouteStatus: 1,
            WoBatch: '',
          }).then((action) => {
            if (action.IsSuccessed) {
              SP_MES_PROD2WO({ rotId: d.values.id, wo: args[1]['CODE'] }).then((action) => {
@@ -472,6 +530,7 @@
                    WorkOrder: args[1]['CODE'],
                    Status: -1,
                    RouteStatus: 0,
                    WoBatch: '',
                  });
                  createErrorModal({
                    title: t('sys.api.errorTip'),
@@ -516,6 +575,25 @@
        testadd: useModal(),
        auditadd: useModal(),
        printadd: useModal(),
        labeladd: useModal(),
        pkgadd: useModal(),
      };
    },
    /**
     * @description: 获取模态框应用列表
     * @return {*}
     */
    GetUseCrudModals: () => {
      return {
        addRoute: useModal(),
        addCustomer: useModal(),
        editRoute: useModal(),
        scanadd: useModal(),
        assyadd: useModal(),
        testadd: useModal(),
        auditadd: useModal(),
        printadd: useModal(),
        labeladd: useModal(),
        pkgadd: useModal(),
      };
    },
@@ -659,7 +737,13 @@
          SP_MES_WO2CUST({ wo: args[2][0]['wo'] });
          break;
        case 'editRoute':
          args[1](true, { rotId: args[2][0].wo, slotName: '', rotType: 'Wo', prodCode:args[3],custCode:args[2][0].cust });
          args[1](true, {
            rotId: args[2][0].wo,
            slotName: '',
            rotType: 'Wo',
            prodCode: args[3],
            custCode: args[2][0].cust,
          });
          break;
      }
    },
@@ -715,35 +799,47 @@
     * @return {*}
     */
    CustFunc: async (param: CustModalParams) => {
      switch (param['ctype']) {
        case 'BAS_PKG_DTL':
          // const ents = await getEntity({
          //   sqlcmd: `PKG_RULE_ID ='${param.values['PKG_RULE_ID']}'`,
          //   entityName: 'V_BAS_PKG_DTL',
          //   order: '',
          // });
          // param.data.value['Table'] = ents.Data.Items;
          param.data.value['BAS_PKG_DTL'].map((x) => {
            if (x.PKG_CODE == param.values['PKG_CODE']) {
              x.LABEL_CODE = param.values['LABEL_CODE'];
            }
          });
          param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
            param.data.value['BAS_PKG_DTL'],
          );
          break;
        case 'ItemCode':
          param.data.value['ItemCode'].map((x) => {
            if (x.ITEM_CODE == param.values['ITEM_CODE']) {
              x.IsBatchItem = param.values['IsBatchItem'];
              x.RULE_CODE = param.values['RULE_CODE'];
            }
          });
          param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
            param.data.value['ItemCode'],
          );
          break;
      }
      return new Promise<any>(async (resolve, reject) => {
        try {
          switch (param['ctype']) {
            case 'BAS_PKG_DTL':
              // const ents = await getEntity({
              //   sqlcmd: `PKG_RULE_ID ='${param.values['PKG_RULE_ID']}'`,
              //   entityName: 'V_BAS_PKG_DTL',
              //   order: '',
              // });
              // param.data.value['Table'] = ents.Data.Items;
              param.data.value['BAS_PKG_DTL'].map((x) => {
                if (x.PKG_CODE == param.values['PKG_CODE']) {
                  x.LABEL_CODE = param.values['LABEL_CODE'];
                  x.LABEL_ID =  param.values['LABEL_CODE'];
                }
              });
              param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
                param.data.value['BAS_PKG_DTL'],
              );
              break;
            case 'ItemCode':
              param.data.value['ItemCode'].map((x) => {
                if (x.ITEM_CODE == param.values['ITEM_CODE']) {
                  x.IsBatchItem = param.values['IsBatchItem'];
                  x.RULE_CODE = param.values['RULE_CODE'];
                }
              });
              param.data.value['Action'][0]['OPTION_1'] = JSON.stringify(
                param.data.value['ItemCode'],
              );
              break;
            case 'BAS_LABEL_VAR_WO':
              param.values['WORK_ORDER'] = param.others['WORK_ORDER'];
              param.values['ID'] = buildUUID();
              await AddOrEditLabelVarByWorkOrder(param.values as unknown as BAS_LABEL_VAR_WO);
          }
          resolve('OK');
        } catch (e) {
          reject(e);
        }
      });
    },
    /**
     * @description: 获取右键菜单列表
@@ -857,6 +953,12 @@
            //   };
            // },
          },
          {
            dataIndex: 'LABEL_ID',
            title: '标签模板ID',
            ifShow: false,
            customRender: () => {},
          },
        ] as BasicColumn[];
        break;
      case 'ItemCode':
@@ -933,6 +1035,7 @@
    }
    return columns;
  }
  /**
   * @description: 弹出选择框-物料选择框配置
   * @return {*}
@@ -1187,7 +1290,7 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isScan(values.ACT_TYPE),
      colSlot: 'scanadd',
    },
@@ -1203,7 +1306,7 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isAssy(values.ACT_TYPE),
      colSlot: 'assyadd',
    },
@@ -1219,7 +1322,7 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isTest(values.ACT_TYPE),
      colSlot: 'testadd',
    },
@@ -1235,14 +1338,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isAudit(values.ACT_TYPE),
      colSlot: 'auditadd',
    },
    {
      field: 'LABEL_CODE',
      label: '标签打印',
      colProps: { span: 11 },
      colProps: { span: 9 },
      component: 'Input',
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
    },
@@ -1251,9 +1354,18 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 2 }, //{ span: 2, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'printadd',
    },
    {
      field: 'print1',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'labeladd',
    },
    {
      field: 'PKG_CODE',
@@ -1267,7 +1379,7 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 1, pull: 1 },
      colProps: { span: 1, pull: window.screen.width == 1366 ? -1 : 1 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      colSlot: 'pkgadd',
    },
@@ -1277,6 +1389,7 @@
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      componentProps: {
        options: [
          {
@@ -1665,6 +1778,77 @@
    ] as FormSchema[],
  };
  /**
   * @description: 模板维护
   * @param {*} args
   * @param {Recordable} params
   * @return {*}
   */
  function handleTemplate(args, params: Recordable) {
    const openCrudModal = args[0];
    const OrderNo = args[2];
    openCrudModal(true, {
      isUpdate: true, //是否更新操作
      entityName: 'WoRouteBinding', //是哪个页面
      ctype: 'BAS_LABEL_VAR_WO', //实体名称
      title: '模板维护', //标题
      width: '1024px', //弹出框宽度
      ItemColumns: TemplateBasColumn, //弹出框中表格字段结构
      schemas: [], //查询条件字段结构
      others: { WORK_ORDER: OrderNo }, //需要带到弹出窗口中的数据
      searchInfo: {
        TABLE_NAME: 'BAS_LABEL_VAR_WO', //实体名称
        LabelId: params['record'].LABEL_ID, //模板ID
        WorkOrder: OrderNo, //工单号
        apiUrl: mesApi.GetLabelVarByWorkOrder, //自定义获取数据分页的api,不用默认的基础方法
        // sqlcmd: ` (WORK_ORDER = '${OrderNo}' OR WORK_ORDER = '' OR WORK_ORDER IS NULL)`,
        // option:
        // {
        //   //根据据点查询,必需带这个参数
        //   UserId: useUserStore().getUserInfo.userId,
        //   ByOrg: true,
        //   CurOrg: useUserStore().getUserInfo.orgCode,
        // },
      },
      values: params['record'], //表单记录
    });
  }
  /* 下发界面中的表单列表 */
  const TemplateBasColumn = [
    {
      dataIndex: 'LABEL_ID',
      title: '标签模板ID',
      ifShow: false,
      sorter: true,
      resizable: true,
    },
    {
      title: '工单号',
      dataIndex: 'WORK_ORDER',
      width: 280,
      editRow: true,
      // editable: true,
      ifShow: false,
    },
    {
      title: '变量名',
      dataIndex: 'VAR_NAME',
    },
    {
      title: '变量值',
      dataIndex: 'VAR_VALUE',
      editRow: true,
      editRule: true,
    },
    {
      title: '默认值',
      dataIndex: 'DEFAULT_VALUE',
      editRow: true,
      editRule: true,
    },
  ] as BasicColumn[];
  return [methods];
}