Ben Lin
2024-07-04 68d75a540ec8b3168c3af956ea00b898036d92cd
src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts
@@ -4,10 +4,10 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-27 22:57:45
 * @LastEditTime: 2024-07-03 21:57:20
 */
import { Ref, ref, unref } from 'vue';
import { Ref, h, ref, render, unref } from 'vue';
import { GetRoutePTree, RouteToCust, RouteToProd } from '/@/api/tigerapi/mes/router';
import { GetEnum, SaveEntity, convertToTree, getEntity } from '/@/api/tigerapi/system';
import { useLocale } from '/@/locales/useLocale';
@@ -16,11 +16,14 @@
import { NavItem } from '/@/api/tigerapi/model/basModel';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
import { FormSchema } from '/@/components/Table';
import { initRoute } from '../data';
const { t } = useI18n();
const { createErrorModal } = useMessage();
const { getLocale } = useLocale();
function _default() {
  /* 定义变量 */
  const isNormal = (type: number) => type === 0;
  const isScan = (type: number) => type === 1;
  const isAssy = (type: number) => type === 2;
@@ -28,6 +31,10 @@
  const isAudit = (type: number) => type === 4;
  const isPrint = (type: number) => type === 5;
  const isPackage = (type: number) => type === 6;
  /**
   * @description: 产品绑定工艺路线的一些自定义方法
   * @return {*}
   */
  const methods = {
    /**
     * @description: 获取树形图标
@@ -81,368 +88,19 @@
      data.fieldNames = { key: 'tid', title: 'name' };
      return data;
    },
    /**
     * @description: 获取配置项表单字段,根据树形节点type不同而不同
     * @param {string} type
     * @return {*}
     */
    GetCrudForm: (type: string) => {
      let form: any[] = [];
      let form: FormSchema[] = [];
      switch (type) {
        case 'Action':
          form = [
            {
              field: 'PROD_CODE',
              label: '产品编码',
              component: 'Input',
              dynamicDisabled: ({ values }) => {
                return true;
              },
              colProps: { span: 12 },
            },
            {
              field: 'ID',
              label: 'ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'ACT_ID',
              label: 'ACT_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'ROT_ID',
              label: 'ROT_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'ACT_CODE',
              label: 'ACT_CODE',
              component: 'Input',
              show: false,
            },
            {
              field: 'NODE_ID',
              label: 'NODE_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'CUST_CODE',
              label: '客户编码',
              component: 'Input',
              dynamicDisabled: ({ values }) => {
                return true;
              },
              colProps: { span: 12 },
            },
            {
              field: 'ACT_TYPE',
              label: '行为类型',
              component: 'ApiSelect',
              colProps: { span: 12 },
              defaultValue: 0,
              componentProps: {
                api: GetEnum,
                params: { name: 'MES_PROD_ACTION+ACT_TYPEs' },
                resultField: 'Data',
                labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
                valueField: 'Value',
                // onChange: (e, v) => {
                //   alert(e)
                //   console.log('ApiSelect====>:', e, v);
                // },
              },
            },
            {
              field: 'IS_ACTIVE',
              label: '是否启用',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'RULE_CODE',
              label: '扫码验证',
              component: 'Input',
              colProps: { span: 10 },
              ifShow: ({ values }) => isScan(values.ACT_TYPE),
            },
            {
              field: '0',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isScan(values.ACT_TYPE),
              colSlot: 'scanadd',
            },
            {
              field: 'ITEM_CODE',
              label: '组装上料',
              colProps: { span: 10 },
              component: 'Input',
              ifShow: ({ values }) => isAssy(values.ACT_TYPE),
            },
            {
              field: '00',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isAssy(values.ACT_TYPE),
              colSlot: 'assyadd',
            },
            {
              field: 'TEST_CODE',
              label: '产品测试',
              colProps: { span: 10 },
              component: 'Input',
              ifShow: ({ values }) => isTest(values.ACT_TYPE),
            },
            {
              field: 'test0',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isTest(values.ACT_TYPE),
              colSlot: 'testadd',
            },
            {
              field: 'SAPL_CODE',
              label: '产品抽检',
              colProps: { span: 10 },
              component: 'Input',
              ifShow: ({ values }) => isAudit(values.ACT_TYPE),
            },
            {
              field: 'audit0',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isAudit(values.ACT_TYPE),
              colSlot: 'auditadd',
            },
            {
              field: 'LABEL_CODE',
              label: '标签打印',
              colProps: { span: 10 },
              component: 'Input',
              ifShow: ({ values }) => isPrint(values.ACT_TYPE),
            },
            {
              field: 'print0',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isPrint(values.ACT_TYPE),
              colSlot: 'printadd',
            },
            {
              field: 'pkgRULE_CODE',
              label: '包装规则',
              colProps: { span: 10 },
              component: 'Input',
              ifShow: ({ values }) => isPackage(values.ACT_TYPE),
            },
            {
              field: 'pkg0',
              label: '1',
              defaultValue: '',
              component: 'Input',
              colProps: { span: 2, pull: 1 },
              ifShow: ({ values }) => isPackage(values.ACT_TYPE),
              colSlot: 'pkgadd',
            },
            {
              field: 'REMARK',
              label: '备注',
              component: 'Input',
              colProps: { span: 12 },
            },
          ];
          form = actionFormShema;
          break;
        case 'Node':
          form = [
            {
              field: 'PROD_CODE',
              label: '产品编码',
              component: 'Input',
              dynamicDisabled: ({ values }) => {
                return true;
              },
              colProps: { span: 12 },
            },
            {
              field: 'ID',
              label: 'ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'ACT_ID',
              label: 'ACT_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'ROT_ID',
              label: 'ROT_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'NODE_ID',
              label: 'NODE_ID',
              component: 'Input',
              show: false,
            },
            {
              field: 'NODE_NAME',
              label: '工序节点名称',
              component: 'Input',
            },
            {
              field: 'CUST_CODE',
              label: '客户编码',
              component: 'Input',
              dynamicDisabled: ({ values }) => {
                return true;
              },
              colProps: { span: 12 },
            },
            {
              field: 'OPER_CODE',
              label: '工序编码',
              component: 'Input',
            },
            {
              field: 'IS_ACTIVE',
              label: '是否启用',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'IS_CALC_FPY',
              label: '是否计算直通率',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'CAN_SKIP',
              label: '是否允许跳站',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'IS_INPUT',
              label: '是否投入站',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'IS_OUTPUT',
              label: '是否产出站',
              required: true,
              component: 'Select',
              colProps: { span: 12 },
              componentProps: {
                options: [
                  {
                    label: '是',
                    value: 'Y',
                    key: 'Y',
                  },
                  {
                    label: '否',
                    value: 'N',
                    key: 'N',
                  },
                ],
              },
            },
            {
              field: 'REMARK',
              label: '备注',
              component: 'Input',
              colProps: { span: 12 },
            },
          ];
          form = nodeFormShema;
          break;
      }
      return form;
@@ -454,6 +112,10 @@
    GetCrudColSlots: () => {
      return ['scanadd', 'assyadd', 'testadd', 'auditadd', 'printadd', 'pkgadd'];
    },
    /**
     * @description: 切换节点时事件方法
     * @return {*}
     */
    nodeChange: (params: {
      resetFields: any;
      setFieldsValue: any;
@@ -477,6 +139,7 @@
        sqlcmd: sqlcmd,
        entityName:
          params['selectedNodes'].value[0].type == 'Action' ? 'MES_PROD_ACTION' : 'MES_PROD_OPER',
        order: '',
      }).then((res) => {
        params['resetFields']();
        if (params['selectedNodes'].value[0].type == 'Action') {
@@ -605,8 +268,6 @@
          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: '' });
            }
          }
@@ -639,6 +300,7 @@
      return {
        addRoute: useModal(),
        addCustomer: useModal(),
        editRoute: useModal(),
      };
    },
    /**
@@ -649,20 +311,25 @@
    GetTitle: (type: string) => {
      return {
        configTitle: type == 'Action' ? '行为配置' : '工序配置',
        navTitle: '添加工艺路线',
        navTitle: type == 'Product' ? '添加工艺路线' : '工艺路线维护',
      };
    },
    /**
     * @description: 根据选中的树节点判断要切换哪个组件
     * @description: 根据选中的树节点返回主页面,自定义方法,这里是判断要切换哪个组件
     * @param {Ref} selectedNodes
     * @return {*}
     */
    SelectNode: (selectedNodes: Ref<any[]>) => {
      let result = { showConfig: false, showNav: false, type: selectedNodes.value[0].type };
      let result = {
        showConfig: false,
        showNav: false,
        type: selectedNodes.value[0].type,
        nodes: selectedNodes.value,
      };
      if (isNullOrUnDef(selectedNodes)) {
        return result;
      }
      if (selectedNodes.value[0].type == 'Product') {
      if (selectedNodes.value[0].type == 'Product' || selectedNodes.value[0].type == 'Route') {
        result.showNav = true;
        result.showConfig = false;
      }
@@ -676,25 +343,43 @@
     * @description: 获取导航项
     * @return {*}
     */
    GetNavItems: () => {
      return [
        {
          title: '添加产品工艺路线',
          icon: 'add_green|svg',
          color: '#1fdaca',
          url: '/addRoute',
          action: 'addRoute',
          isStep: false,
        },
        {
          title: '添加客户工艺路线',
          icon: 'add_customer|svg',
          color: '#bf0c2c',
          url: '/addCustomer',
          action: 'addCustomer',
          isStep: true,
        },
      ] as NavItem[];
    GetNavItems: (type: string) => {
      let item: NavItem[] = [];
      switch (type) {
        case 'Product':
          item = [
            {
              title: '添加产品工艺路线',
              icon: 'add_green|svg',
              color: '#1fdaca',
              url: '/addRoute',
              action: 'addRoute',
              isStep: false,
            },
            {
              title: '添加客户工艺路线',
              icon: 'add_customer|svg',
              color: '#bf0c2c',
              url: '/addCustomer',
              action: 'addCustomer',
              isStep: true,
            },
          ];
          break;
        case 'Route':
          item = [
            {
              title: '编辑工艺路线',
              icon: 'clarity:note-edit-line',
              color: '#1fdaca',
              url: '/editRoute',
              action: 'editRoute',
              isStep: false,
            },
          ];
          break;
      }
      return item;
    },
    /**
     * @description: 导航页面切换按钮时调用方法
@@ -744,10 +429,75 @@
            title: '请完成以下步骤',
          });
          break;
        case 'editRoute':
          args[1](true, { rotId: args[2][0].id, slotName: '' });
          break;
      }
    },
    /**
     * @description: 获取卡片内配置列表,以循环显示多个卡片并配置多个插槽
     * @return {*}
     */
    GetBaseCards: (type: string) => {
      let reusts: any[] = [];
      switch (type) {
        case 'Product':
          reusts = [];
          break;
        case 'Route':
          reusts = [
            {
              name: 'RotInfo',
              slots: [],
              preIcons: {},
              title: '工艺路线图',
              entityName: '',
            },
          ];
          break;
      }
      return reusts;
    },
    /**
     * @description: 获取插槽列表
     * @return {*}
     */
    GetSlots: () => {
      return ['RotInfo'];
    },
    /**
     * @description: 生成html
     * @return {*}
     */
    GenerateHtml: (type: string | null) => {
      const newElement = document.createElement('div');
      // newElement.textContent = 'New Element =>'+type;
      // newElement.style.height = '250px';
      newElement.id = 'lfContainer';
      newElement.className = 'h-full';
      // newElement.style.color = 'blue';
      // newElement.style.fontSize = '16px';
      return newElement;
    },
    /**
     * @description: 自定义方法
     * @param {string} type
     * @param {array} args
     * @return {*}
     */
    CustFunc: (type: string | undefined, ...args) => {
      if (type == 'Route') {
        // initRoute(args[0], args[1]);
      }
    },
  };
  /* 以下是内部方法,不export,供上面的方法调用 */
  /**
   * @description: 弹出选择框-物料选择框配置
   * @return {*}
   */
  const itemCodeModalCfg = {
    title: '物料列表',
    schemas: [
@@ -781,6 +531,10 @@
    searchInfo: { TABLE_NAME: 'BAS_ITEM' },
  };
  /**
   * @description: 弹出选择框-规则选择框配置
   * @return {*}
   */
  const ruleModalCfg = {
    title: '规则列表',
    schemas: [
@@ -814,6 +568,10 @@
    searchInfo: { TABLE_NAME: 'BAS_CODE_RULE' },
  };
  /**
   * @description: 弹出选择框-打印模板选择框配置
   * @return {*}
   */
  const printModalCfg = {
    title: '打印模板列表',
    schemas: [
@@ -880,6 +638,372 @@
    searchInfo: { TABLE_NAME: 'BAS_PKG_RULE' },
  };
  /**
   * @description: 行为配置表单字段
   * @return {*}
   */
  const actionFormShema: FormSchema[] = [
    {
      field: 'PROD_CODE',
      label: '产品编码',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'ID',
      label: 'ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ACT_ID',
      label: 'ACT_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ROT_ID',
      label: 'ROT_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ACT_CODE',
      label: 'ACT_CODE',
      component: 'Input',
      show: false,
    },
    {
      field: 'NODE_ID',
      label: 'NODE_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'CUST_CODE',
      label: '客户编码',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'ACT_TYPE',
      label: '行为类型',
      component: 'ApiSelect',
      colProps: { span: 12 },
      defaultValue: 0,
      componentProps: {
        api: GetEnum,
        params: { name: 'MES_PROD_ACTION+ACT_TYPEs' },
        resultField: 'Data',
        labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
        valueField: 'Value',
        // onChange: (e, v) => {
        //   alert(e)
        //   console.log('ApiSelect====>:', e, v);
        // },
      },
    },
    {
      field: 'IS_ACTIVE',
      label: '是否启用',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'RULE_CODE',
      label: '扫码验证',
      component: 'Input',
      colProps: { span: 10 },
      ifShow: ({ values }) => isScan(values.ACT_TYPE),
    },
    {
      field: '0',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isScan(values.ACT_TYPE),
      colSlot: 'scanadd',
    },
    {
      field: 'ITEM_CODE',
      label: '组装上料',
      colProps: { span: 10 },
      component: 'Input',
      ifShow: ({ values }) => isAssy(values.ACT_TYPE),
    },
    {
      field: '00',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isAssy(values.ACT_TYPE),
      colSlot: 'assyadd',
    },
    {
      field: 'TEST_CODE',
      label: '产品测试',
      colProps: { span: 10 },
      component: 'Input',
      ifShow: ({ values }) => isTest(values.ACT_TYPE),
    },
    {
      field: 'test0',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isTest(values.ACT_TYPE),
      colSlot: 'testadd',
    },
    {
      field: 'SAPL_CODE',
      label: '产品抽检',
      colProps: { span: 10 },
      component: 'Input',
      ifShow: ({ values }) => isAudit(values.ACT_TYPE),
    },
    {
      field: 'audit0',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isAudit(values.ACT_TYPE),
      colSlot: 'auditadd',
    },
    {
      field: 'LABEL_CODE',
      label: '标签打印',
      colProps: { span: 10 },
      component: 'Input',
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
    },
    {
      field: 'print0',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'printadd',
    },
    {
      field: 'pkgRULE_CODE',
      label: '包装规则',
      colProps: { span: 10 },
      component: 'Input',
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
    },
    {
      field: 'pkg0',
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      colSlot: 'pkgadd',
    },
    {
      field: 'REMARK',
      label: '备注',
      component: 'Input',
      colProps: { span: 12 },
    },
  ];
  /**
   * @description: 工序配置表单字段
   * @return {*}
   */
  const nodeFormShema: FormSchema[] = [
    {
      field: 'PROD_CODE',
      label: '产品编码',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'ID',
      label: 'ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ACT_ID',
      label: 'ACT_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ROT_ID',
      label: 'ROT_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'NODE_ID',
      label: 'NODE_ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'NODE_NAME',
      label: '工序节点名称',
      component: 'Input',
    },
    {
      field: 'CUST_CODE',
      label: '客户编码',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'OPER_CODE',
      label: '工序编码',
      component: 'Input',
    },
    {
      field: 'IS_ACTIVE',
      label: '是否启用',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'IS_CALC_FPY',
      label: '是否计算直通率',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'CAN_SKIP',
      label: '是否允许跳站',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'IS_INPUT',
      label: '是否投入站',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'IS_OUTPUT',
      label: '是否产出站',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'REMARK',
      label: '备注',
      component: 'Input',
      colProps: { span: 12 },
    },
  ];
  return [methods];
}