Ben Lin
2024-08-01 efcc2e97beb8c3b05f422fe7efafa059447473de
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-21 18:26:07
 * @LastEditTime: 2024-08-01 11:25:16
 */
import { Ref, h, ref, render, unref } from 'vue';
import { GetRoutePTree, RouteToCust, RouteToProd } 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';
@@ -20,6 +28,9 @@
import { initRoute } from '../data';
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';
const { t } = useI18n();
const { createErrorModal } = useMessage();
@@ -46,8 +57,8 @@
    CreateIcon: (params: Recordable<any>) => {
      let icon = '';
      switch (params['type']) {
        case 'Product':
          icon = 'similar-product|svg';
        case 'WorkOrder':
          icon = 'workorder|svg';
          break;
        case 'Route':
          icon = 'route|svg';
@@ -68,17 +79,17 @@
     * @description: 高级表单和详情页面返回主页面的url
     * @return {*}
     */
    GetHomeUrl: () => {
      return `/V_BAS_PROD/LC/${encodeURI(JSON.stringify({ ID: 'V_BAS_PROD', colSlots: [], crudColSlots: [] }))}`;
    GetHomeUrl: (params: {}) => {
      return `/BIZ_MES_WO/LC/${encodeURI(JSON.stringify({ ID: 'BIZ_MES_WO', colSlots: params['colSlots'], crudColSlots: [] }))}`;
    },
    /**
     * @description: 获取树形数据
     * @param {string} type
     * @return {*}
     */
    fetchTreeData: async (type: string, itemCode: string) => {
    fetchTreeData: async (type: string, wo: string) => {
      let data = { title: '', treeData: [] as any[], fieldNames: {} };
      let prodTreeData = await GetRoutePTree({prodCode: itemCode, orgCode: useUserStore().getUserInfo.orgCode});
      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);
@@ -86,7 +97,18 @@
      //   return acc;
      // }, [] as V_MES_ROUTE_PTREE[]);
      data.treeData = convertToTree(prodTreeData, 'pid', 'tid', 'root');
      data.title = '工艺路线';
      if (data.treeData.length == 0) {
        data.treeData.push({
          pid: 'root',
          tid: '',
          id: '',
          wo: wo,
          prod: '',
          name: wo,
          type: 'WorkOrder',
        });
      }
      data.title = '工单工艺路线';
      data.fieldNames = { key: 'tid', title: 'name' };
      return data;
    },
@@ -126,10 +148,7 @@
    }) => {
      let sqlcmd = ' 1=1 ';
      if (!isNullOrEmpty(params['objParams'].value['CODE'])) {
        sqlcmd += `And PROD_CODE = '${params['objParams'].value['CODE']}'`;
      }
      if (!isNullOrEmpty(params['selectedNodes'].value[0].cust)) {
        sqlcmd += `And CUST_CODE = '${params['selectedNodes'].value[0].cust}'`;
        sqlcmd += `And WORK_ORDER = '${params['objParams'].value['CODE']}'`;
      }
      if (!isNullOrEmpty(params['selectedNodes'].value[0].id)) {
        sqlcmd +=
@@ -140,7 +159,7 @@
      getEntity({
        sqlcmd: sqlcmd,
        entityName:
          params['selectedNodes'].value[0].type == 'Action' ? 'MES_PROD_ACTION' : 'MES_PROD_OPER',
          params['selectedNodes'].value[0].type == 'Action' ? 'MES_WO_ACTION' : 'MES_WO_OPER',
        order: '',
      }).then((res) => {
        params['resetFields']();
@@ -159,9 +178,10 @@
            PKG_CODE: res.Data.Items[0].PKG_CODE,
            ACT_CODE: res.Data.Items[0].ACT_CODE,
            REMARK: res.Data.Items[0].REMARK,
            PROD_CODE: params['objParams'].value['CODE'],
            WORK_ORDER: params['objParams'].value['CODE'],
            ACT_TYPE: res.Data.Items[0].ACT_TYPE,
            CUST_CODE: params['selectedNodes'].value[0].cust,
            PROD_CODE: params['selectedNodes'].value[0].prod,
          });
        }
        if (params['selectedNodes'].value[0].type == 'Node') {
@@ -176,9 +196,11 @@
            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,
            PROD_CODE: params['objParams'].value['CODE'],
            WORK_ORDER: params['objParams'].value['CODE'],
            CUST_CODE: params['selectedNodes'].value[0].cust,
            PROD_CODE: params['selectedNodes'].value[0].prod,
          });
        }
      });
@@ -191,12 +213,14 @@
      let entityName = '';
      switch (type) {
        case 'Action':
          entityName = 'MES_PROD_ACTION';
          entityName = 'MES_WO_ACTION';
          break;
        case 'Node':
          entityName = 'MES_PROD_OPER';
          entityName = 'MES_WO_OPER';
          break;
      }
      values.AUTH_ORG = useUserStore().getUserInfo.orgCode;
      values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
      SaveEntity(values, true, entityName).then((action) => {
        if (action.IsSuccessed) {
          emit('success');
@@ -265,29 +289,47 @@
            });
            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'] });
          /* 更新工单状态并生成工单的工艺路线 */
          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'])) {
            createErrorModal({
              title: t('sys.api.errorTip'),
              content: '产品为空,不能添加工艺路线,请点击左侧选择产品',
              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 });
          }
          SP_MES_WO2CUST({ wo: args[1]['CODE'] });
          args[2]();
          break;
@@ -331,7 +373,7 @@
      if (isNullOrUnDef(selectedNodes)) {
        return result;
      }
      if (selectedNodes.value[0].type == 'Product' || selectedNodes.value[0].type == 'Route') {
      if (selectedNodes.value[0].type == 'WorkOrder' || selectedNodes.value[0].type == 'Route') {
        result.showNav = true;
        result.showConfig = false;
      }
@@ -348,7 +390,7 @@
    GetNavItems: (type: string) => {
      let item: NavItem[] = [];
      switch (type) {
        case 'Product':
        case 'WorkOrder':
          item = [
            {
              title: '添加产品工艺路线',
@@ -358,14 +400,14 @@
              action: 'addRoute',
              isStep: false,
            },
            {
              title: '添加客户工艺路线',
              icon: 'add_customer|svg',
              color: '#bf0c2c',
              url: '/addCustomer',
              action: 'addCustomer',
              isStep: true,
            },
            // {
            //   title: '添加客户工艺路线',
            //   icon: 'add_customer|svg',
            //   color: '#bf0c2c',
            //   url: '/addCustomer',
            //   action: 'addCustomer',
            //   isStep: true,
            // },
          ];
          break;
        case 'Route':
@@ -427,12 +469,17 @@
          });
          break;
        case 'addCustomer':
          args[0](true, {
            title: '请完成以下步骤',
          });
          if (isNullOrEmpty(args[2][0]['wo'])) {
            createErrorModal({
              title: t('sys.api.errorTip'),
              content: '工单为空,不能添加工艺路线,请点击左侧选择工单',
            });
            return;
          }
          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;
      }
    },
@@ -443,7 +490,7 @@
    GetBaseCards: (type: string) => {
      let reusts: any[] = [];
      switch (type) {
        case 'Product':
        case 'WorkOrder':
          reusts = [];
          break;
        case 'Route':
@@ -494,6 +541,41 @@
    },
    GetUseForm: () => {
      return {};
    },
    /**
     * @description: 获取右键菜单列表
     * @param {EventDataNode} node
     * @return {*}
     */
    GetRightMenuList: (node: EventDataNode, ...args): ContextMenuItem[] => {
      const emit = args[0];
      const menu = [
        // {
        //   label: '新增',
        //   handler: () => {
        //     console.log('点击了新增', node);
        //   },
        //   icon: 'bi:plus',
        // },
        {
          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),
                });
              }
            });
          },
          icon: 'bx:bxs-folder-open',
        },
      ];
      return node.type == 'Route' ? menu : [];
    },
  };
@@ -649,13 +731,19 @@
   */
  const actionFormShema: FormSchema[] = [
    {
      field: 'PROD_CODE',
      label: '产品编码',
      field: 'WORK_ORDER',
      label: '工单号',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'PROD_CODE',
      label: 'PROD_CODE',
      component: 'Input',
      show: false,
    },
    {
      field: 'ID',
@@ -704,7 +792,7 @@
      defaultValue: 0,
      componentProps: {
        api: GetEnum,
        params: { name: 'MES_PROD_ACTION+ACT_TYPEs' },
        params: { name: 'MES_WO_ACTION+ACT_TYPEs' },
        resultField: 'Data',
        labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
        valueField: 'Value',
@@ -845,13 +933,19 @@
   */
  const nodeFormShema: FormSchema[] = [
    {
      field: 'PROD_CODE',
      label: '产品编码',
      field: 'WORK_ORDER',
      label: '工单号',
      component: 'Input',
      dynamicDisabled: ({ values }) => {
        return true;
      },
      colProps: { span: 12 },
    },
    {
      field: 'PROD_CODE',
      label: 'PROD_CODE',
      component: 'Input',
      show: false,
    },
    {
      field: 'ID',
@@ -1002,6 +1096,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',