From b4496ad2462843c575a3902c94a87694426f29a3 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期四, 27 六月 2024 16:03:37 +0800
Subject: [PATCH] 产品工艺路线更新

---
 src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts |  144 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 105 insertions(+), 39 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts b/src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts
index d142b78..7119887 100644
--- a/src/views/tigerprojects/system/lowcode/entityts/ProdRouteBinding.ts
+++ b/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,41 +448,50 @@
      * @param {any} action
      * @return {*}
      */
-    naveChangeItem: (action: any, ...args) => {
-      args[0](true, {
-        title: '宸ヨ壓璺嚎鍒楄〃',
-        schemas: [
-          {
-            field: 'ROT_CODE',
-            component: 'Input',
-            label: '宸ヨ壓璺嚎缂栫爜',
-            colProps: {
-              span: 12,
-            },
-          },
-        ],
-        ItemColumns: [
-          {
-            title: t('宸ヨ壓璺嚎缂栫爜'),
-            dataIndex: 'ROT_CODE',
-            resizable: true,
-            sorter: true,
-            width: 200,
-          },
-          {
-            title: t('宸ヨ壓璺嚎鍚嶇О'),
-            dataIndex: 'ROT_NAME',
-            resizable: true,
-            sorter: true,
-            width: 180,
-          },
-        ],
-        tableName: 'MES_ROUTE',
-        rowKey: 'ROT_CODE',
-        returnFieldName: 'ROUTE_CODE', //杩斿洖鍊艰璧嬪�肩殑瀛楁鍚嶇О
-        searchInfo: { TABLE_NAME: 'MES_ROUTE' },
-        which: action,
-      });
+    navChangeItem: (action: any, ...args) => {
+      switch (action) {
+        case 'addRoute':
+          args[0](true, {
+            title: '宸ヨ壓璺嚎鍒楄〃',
+            schemas: [
+              {
+                field: 'ROT_CODE',
+                component: 'Input',
+                label: '宸ヨ壓璺嚎缂栫爜',
+                colProps: {
+                  span: 12,
+                },
+              },
+            ],
+            ItemColumns: [
+              {
+                title: t('宸ヨ壓璺嚎缂栫爜'),
+                dataIndex: 'ROT_CODE',
+                resizable: true,
+                sorter: true,
+                width: 200,
+              },
+              {
+                title: t('宸ヨ壓璺嚎鍚嶇О'),
+                dataIndex: 'ROT_NAME',
+                resizable: true,
+                sorter: true,
+                width: 180,
+              },
+            ],
+            tableName: 'MES_ROUTE',
+            rowKey: 'ROT_CODE',
+            returnFieldName: 'ROUTE_CODE', //杩斿洖鍊艰璧嬪�肩殑瀛楁鍚嶇О
+            searchInfo: { TABLE_NAME: 'MES_ROUTE' },
+            which: action,
+          });
+          break;
+        case 'addCustomer':
+          args[0](true, {
+            title: '璇峰畬鎴愪互涓嬫楠�',
+          });
+          break;
+      }
     },
   };
 

--
Gitblit v1.9.3