Ben Lin
2024-08-01 d972fbb5bb3a82fff82d965a29041461c090e715
src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts
@@ -4,11 +4,19 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-24 00:05:00
 * @LastEditTime: 2024-08-01 19:46:42
 */
import { Ref, h, ref, render, unref } from 'vue';
import { DeleteWoRoute, GetRoutePTree, GetWoPTree, RouteToCust, RouteToProd, SP_MES_PROD2WO, SP_MES_WO2CUST } from '/@/api/tigerapi/mes/router';
import {
  DeleteWoRoute,
  GetRoutePTree,
  GetWoPTree,
  RouteToCust,
  RouteToProd,
  SP_MES_PROD2WO,
  SP_MES_WO2CUST,
} from '/@/api/tigerapi/mes/router';
import { GetEnum, SaveEntity, convertToTree, getEntity } from '/@/api/tigerapi/system';
import { useLocale } from '/@/locales/useLocale';
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
@@ -22,6 +30,7 @@
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';
const { t } = useI18n();
const { createErrorModal } = useMessage();
@@ -80,7 +89,7 @@
     */
    fetchTreeData: async (type: string, wo: string) => {
      let data = { title: '', treeData: [] as any[], fieldNames: {} };
      let prodTreeData = await GetWoPTree({wo: wo});
      let prodTreeData = await GetWoPTree({ wo: wo });
      // 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);
@@ -88,7 +97,7 @@
      //   return acc;
      // }, [] as V_MES_ROUTE_PTREE[]);
      data.treeData = convertToTree(prodTreeData, 'pid', 'tid', 'root');
      if(data.treeData.length == 0){
      if (data.treeData.length == 0) {
        data.treeData.push({
          pid: 'root',
          tid: '',
@@ -96,7 +105,7 @@
          wo: wo,
          prod: '',
          name: wo,
          type: 'WorkOrder'
          type: 'WorkOrder',
        });
      }
      data.title = '工单工艺路线';
@@ -187,6 +196,7 @@
            CAN_SKIP: res.Data.Items[0].CAN_SKIP,
            IS_INPUT: res.Data.Items[0].IS_INPUT,
            IS_OUTPUT: res.Data.Items[0].IS_OUTPUT,
            ALLOW_DFT_IN: res.Data.Items[0].ALLOW_DFT_IN,
            REMARK: res.Data.Items[0].REMARK,
            WORK_ORDER: params['objParams'].value['CODE'],
            CUST_CODE: params['selectedNodes'].value[0].cust,
@@ -269,8 +279,9 @@
          break;
        case 'pkgadd':
          value = {
            pkgRULE_CODE: d.values['val'],
            PKG_CODE: d.values['val'],
          };
          break;
        case 'addRoute':
          if (isNullOrEmpty(args[1]['CODE'])) {
            createErrorModal({
@@ -279,15 +290,37 @@
            });
            return;
          }
          let codes = d.values.id.split(',');
          var i;
          for (i = 0; i < codes.length; i++) {
            if (d.which == 'addRoute') {
              SP_MES_PROD2WO({ rotId: codes[i], wo: args[1]['CODE'] });
          /* 更新工单状态并生成工单的工艺路线 */
          UpdateWoStatus({
            UserId: useUserStore().getUserInfo.userId as string,
            WorkOrder: args[1]['CODE'],
            Status: -1,
            RouteStatus: 1,
          }).then((action) => {
            if (action.IsSuccessed) {
              SP_MES_PROD2WO({ rotId: d.values.id, wo: args[1]['CODE'] }).then((action) => {
                if (action.IsSuccessed) {
                  args[2]();
                } else {
                  UpdateWoStatus({
                    UserId: useUserStore().getUserInfo.userId as string,
                    WorkOrder: args[1]['CODE'],
                    Status: -1,
                    RouteStatus: 0,
                  });
                  createErrorModal({
                    title: t('sys.api.errorTip'),
                    content: t(action.LocaleMsg),
                  });
                }
              });
            } else {
              createErrorModal({
                title: t('sys.api.errorTip'),
                content: t(action.LocaleMsg),
              });
            }
          }
          args[2]();
          });
          break;
        case 'addCustomer':
          if (isNullOrEmpty(args[1]['CODE'])) {
@@ -297,7 +330,7 @@
            });
            return;
          }
          SP_MES_WO2CUST({ wo: args[1]['CODE']});
          SP_MES_WO2CUST({ wo: args[1]['CODE'] });
          args[2]();
          break;
@@ -313,6 +346,12 @@
        addRoute: useModal(),
        addCustomer: useModal(),
        editRoute: useModal(),
        scanadd: useModal(),
        assyadd: useModal(),
        testadd: useModal(),
        auditadd: useModal(),
        printadd: useModal(),
        pkgadd: useModal(),
      };
    },
    /**
@@ -444,10 +483,10 @@
            });
            return;
          }
          SP_MES_WO2CUST({ wo: args[2][0]['wo']});
          SP_MES_WO2CUST({ wo: args[2][0]['wo'] });
          break;
        case 'editRoute':
          args[1](true, { rotId: args[2][0].id, slotName: '' });
          args[1](true, { rotId: args[2][0].code, slotName: '' });
          break;
      }
    },
@@ -514,7 +553,7 @@
     * @description: 获取右键菜单列表
     * @param {EventDataNode} node
     * @return {*}
     */
     */
    GetRightMenuList: (node: EventDataNode, ...args): ContextMenuItem[] => {
      const emit = args[0];
      const menu = [
@@ -529,21 +568,21 @@
          label: '删除',
          handler: () => {
            console.log('点击了删除', node);
            DeleteWoRoute({rotId:'',rotCode: node.code, wo: node.wo}).then((action) => {
                if(action.IsSuccessed){
                  emit('deletenode', node);
                }else{
                  createErrorModal({
                    title: t('sys.api.errorTip'),
                    content: t(action.LocaleMsg),
                  });
                }
            DeleteWoRoute({ rotId: '', rotCode: node.code, wo: node.wo }).then((action) => {
              if (action.IsSuccessed) {
                emit('deletenode', node);
              } else {
                createErrorModal({
                  title: t('sys.api.errorTip'),
                  content: t(action.LocaleMsg),
                });
              }
            });
          },
          icon: 'bx:bxs-folder-open',
        },
      ];
      return node.type == 'Route'? menu: [];
      return node.type == 'Route' ? menu : [];
    },
  };
@@ -795,7 +834,7 @@
      field: 'RULE_CODE',
      label: '扫码验证',
      component: 'Input',
      colProps: { span: 10 },
      colProps: { span: 11 },
      ifShow: ({ values }) => isScan(values.ACT_TYPE),
    },
    {
@@ -803,14 +842,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isScan(values.ACT_TYPE),
      colSlot: 'scanadd',
    },
    {
      field: 'ITEM_CODE',
      label: '组装上料',
      colProps: { span: 10 },
      colProps: { span: 11 },
      component: 'Input',
      ifShow: ({ values }) => isAssy(values.ACT_TYPE),
    },
@@ -819,14 +858,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isAssy(values.ACT_TYPE),
      colSlot: 'assyadd',
    },
    {
      field: 'TEST_CODE',
      label: '产品测试',
      colProps: { span: 10 },
      colProps: { span: 11 },
      component: 'Input',
      ifShow: ({ values }) => isTest(values.ACT_TYPE),
    },
@@ -835,14 +874,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isTest(values.ACT_TYPE),
      colSlot: 'testadd',
    },
    {
      field: 'SAPL_CODE',
      label: '产品抽检',
      colProps: { span: 10 },
      colProps: { span: 11 },
      component: 'Input',
      ifShow: ({ values }) => isAudit(values.ACT_TYPE),
    },
@@ -851,14 +890,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isAudit(values.ACT_TYPE),
      colSlot: 'auditadd',
    },
    {
      field: 'LABEL_CODE',
      label: '标签打印',
      colProps: { span: 10 },
      colProps: { span: 11 },
      component: 'Input',
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
    },
@@ -867,14 +906,14 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isPrint(values.ACT_TYPE),
      colSlot: 'printadd',
    },
    {
      field: 'pkgRULE_CODE',
      field: 'PKG_CODE',
      label: '包装规则',
      colProps: { span: 10 },
      colProps: { span: 11 },
      component: 'Input',
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
    },
@@ -883,7 +922,7 @@
      label: '1',
      defaultValue: '',
      component: 'Input',
      colProps: { span: 2, pull: 1 },
      colProps: { span: 1, pull: 1 },
      ifShow: ({ values }) => isPackage(values.ACT_TYPE),
      colSlot: 'pkgadd',
    },
@@ -1064,6 +1103,27 @@
      },
    },
    {
      field: 'ALLOW_DFT_IN',
      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',