From efcc2e97beb8c3b05f422fe7efafa059447473de Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期四, 01 八月 2024 17:23:58 +0800
Subject: [PATCH] 产品绑定工艺路线更新

---
 src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts |  219 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 167 insertions(+), 52 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts b/src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts
index e4f26ae..71679d6 100644
--- a/src/views/tigerprojects/system/lowcode/entityts/WoRouteBinding.ts
+++ b/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: 楂樼骇琛ㄥ崟鍜岃鎯呴〉闈㈣繑鍥炰富椤甸潰鐨剈rl
      * @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',

--
Gitblit v1.9.3