Ben Lin
2024-06-27 b4496ad2462843c575a3902c94a87694426f29a3
src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts
@@ -4,18 +4,22 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-26 21:49:44
 * @LastEditTime: 2024-06-27 15:49:17
 */
import { Ref, ref, unref } from 'vue';
import { GetRoutePTree } from '/@/api/tigerapi/mes/router';
import { GetRoutePTree, RouteToCust, RouteToProd } from '/@/api/tigerapi/mes/router';
import { GetEnum, convertToTree, getEntity } from '/@/api/tigerapi/system';
import { useLocale } from '/@/locales/useLocale';
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
import { useI18n } from '/@/hooks/web/useI18n';
import { NavItem } from '/@/api/tigerapi/model/basModel';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
import { V_MES_ROUTE_PTREE } from '/@/api/tigerapi/model/router';
const { t } = useI18n();
const { createErrorModal } = useMessage();
const { getLocale } = useLocale();
function _default() {
  const isNormal = (type: number) => type === 0;
@@ -67,9 +71,15 @@
    fetchTreeData: async (type: string, itemCode: string) => {
      let data = { title: '', treeData: [] as any[], fieldNames: {} };
      let prodTreeData = await GetRoutePTree(itemCode);
      data.treeData = convertToTree(prodTreeData, 'pid', 'id', 'root');
      // let uniqueArr = prodTreeData.reduce((acc, current) => {
      //   if (!acc.some((x) => x.pid == current.pid && x.id == current.id && x.seq == current.seq && x.type == current.type)) {
      //     acc.push(current);
      //   }
      //   return acc;
      // }, [] as V_MES_ROUTE_PTREE[]);
      data.treeData = convertToTree(prodTreeData, 'pid', 'tid', 'root');
      data.title = '工艺路线';
      data.fieldNames = { key: 'id', title: 'name' };
      data.fieldNames = { key: 'tid', title: 'name' };
      return data;
    },
    GetCrudForm: () => {
@@ -329,9 +339,54 @@
          value = {
            pkgRULE_CODE: d.values['val'],
          };
        case 'addRoute':
          if (isNullOrEmpty(args[1]['CODE'])) {
            createErrorModal({
              title: t('sys.api.errorTip'),
              content: '产品为空,不能添加工艺路线,请点击左侧选择产品',
            });
            return;
          }
          let codes = d.values.id.split(',');
          var i;
          for (i = 0; i < codes.length; i++) {
            if (d.which == 'addRoute') {
              RouteToProd({ rotId: codes[i], prodCode: args[1]['CODE'] });
            } else {
              RouteToCust({ rotId: codes[i], prodCode: args[1]['CODE'], custCode: '' });
            }
          }
          args[2]();
          break;
          case 'addCustomer':
            if (isNullOrEmpty(args[1]['CODE'])) {
              createErrorModal({
                title: t('sys.api.errorTip'),
                content: '产品为空,不能添加工艺路线,请点击左侧选择产品',
              });
              return;
            }
            let rotIds = d.ROT_ID.split(',');
            var i;
            for (i = 0; i < rotIds.length; i++) {
              RouteToCust({ rotId: rotIds[i], prodCode: args[1]['CODE'], custCode: d.CUST_CODE });
            }
            args[2]();
          break;
      }
      return value;
    },
    /**
     * @description: 获取模态框应用列表
     * @return {*}
     */
    GetUseModals: () => {
      return {
        addRoute: useModal(),
        addCustomer: useModal(),
      };
    },
    /**
     * @description: 获取标题信息
@@ -376,6 +431,7 @@
          color: '#1fdaca',
          url: '/addRoute',
          action: 'addRoute',
          isStep: false,
        },
        {
          title: '添加客户工艺路线',
@@ -383,6 +439,7 @@
          color: '#bf0c2c',
          url: '/addCustomer',
          action: 'addCustomer',
          isStep: true,
        },
      ] as NavItem[];
    },
@@ -391,7 +448,9 @@
     * @param {any} action
     * @return {*}
     */
    naveChangeItem: (action: any, ...args) => {
    navChangeItem: (action: any, ...args) => {
      switch (action) {
        case 'addRoute':
      args[0](true, {
        title: '工艺路线列表',
        schemas: [
@@ -426,6 +485,13 @@
        searchInfo: { TABLE_NAME: 'MES_ROUTE' },
        which: action,
      });
          break;
        case 'addCustomer':
          args[0](true, {
            title: '请完成以下步骤',
          });
          break;
      }
    },
  };