From 46c3d28c5633baaddad0da441185310b9360a45b Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 03 七月 2024 14:56:21 +0800
Subject: [PATCH] 高级表单优化

---
 src/views/tigerprojects/system/lowcode/high/index.vue |   74 ++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/high/index.vue b/src/views/tigerprojects/system/lowcode/high/index.vue
index 2fc2b7a..a45dc38 100644
--- a/src/views/tigerprojects/system/lowcode/high/index.vue
+++ b/src/views/tigerprojects/system/lowcode/high/index.vue
@@ -4,7 +4,7 @@
  * @version: 
  * @Date: 2024-06-18 15:09:48
  * @LastEditors: Ben Lin
- * @LastEditTime: 2024-07-02 22:51:31
+ * @LastEditTime: 2024-07-03 14:36:19
 -->
 <!--
  *                        _oo0oo_
@@ -125,6 +125,7 @@
   import { buildUUID } from '/@/utils/uuid';
   import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
   import { useI18n } from '/@/hooks/web/useI18n';
+  import { isFunction } from 'xe-utils';
 
   const { t } = useI18n();
 
@@ -159,7 +160,7 @@
   const otherCards = ref([] as any[]);
   const isMounted = ref(false);
   const custImport = ref<any[]>([]);
-  const others = ref<any>(null);
+  const keyFieldValues = ref<any>(null);
   const data = ref<any>({});
   const useTables = ref<any>({});
   for (const i in objParams.value['drawers']) {
@@ -167,7 +168,7 @@
   }
   provide<Ref<any>>('objParams', objParams);
   provide<Ref<any>>('data', data);
-  provide<Ref<any>>('others', others);
+  provide<Ref<any>>('keyFieldValues', keyFieldValues);
   provide<Ref<{}>>('useFormData', useFormData);
   provide<Ref<any>>('baseCards', baseCards);
   provide<Ref<any>>('useTables', useTables);
@@ -200,38 +201,35 @@
    * @description: 寮傛鍏ㄩ儴鎻愪氦鏂规硶
    * @return {*}
    */
-  function submitAll() {
+  async function submitAll() {
     try {
-      validate().then((res) => {
-        const Keys = Object.getOwnPropertyNames(useFormData.value);
-        let i;
-        let p = [] as Promise<any>[];
-        for (i = 0; i < Keys.length; i++) {
-          p.push(SaveEntity(res[Keys[i]], unref(isAllUpdate), baseCards.value[i]['entityName']));
-        }
-        Promise.all(p).then((action) => {
-          // DeleteWhere(
-          //   ` ${objParams.value.pCode} = '${others.value[objParams.value.pCode]}'`,
-          //   entityName.value,
-          // ).then((res) => {
-          //   if (res.IsSuccessed) {
-          //     data.value.forEach((item) => {
-          //       item.ID = buildUUID();
-          //     });
-          //     AddListEntity(data.value, entityName.value).then((action) => {
-          //       if (action.IsSuccessed) {
-          //         cancel();
-          //       }
-          //     });
-          //   }
-          // });
-          let where = `${objParams.value['drawers'][0]['code']} = '${others.value[objParams.value['drawers'][0]['code']]}'`;
-          data.value[objParams.value['drawers'][0]['name']].forEach((item) => {
+      const validates = await validate();
+      const Keys = Object.getOwnPropertyNames(useFormData.value);
+      let i;
+      let p = [] as Promise<any>[];
+      for (i = 0; i < Keys.length; i++) {
+        p.push(
+          SaveEntity(validates[Keys[i]], unref(isAllUpdate), baseCards.value[i]['entityName']),
+        );
+      }
+      await Promise.all(p);
+      if (
+        !custImport.value['default']()[0].SubmitAll &&
+        !isFunction(custImport.value['default']()[0].SubmitAll)
+      ) {
+        /* 榛樿鎻愪氦 */
+        objParams.value['drawers'].forEach((d) => {
+          let where = `${d['code']} = '${keyFieldValues.value[d['code']]}'`;
+          /* type: all-琛ㄧず闇�瑕乧ode鐨勬墍鏈夌殑鍊� */
+          if(d['type'] == 'all'){
+            where = `${d['code']} in (${data.value[d['keyName']].map(value => `'${value[d['code']]}'`).join(',')})`;
+          }
+          data.value[d['name']].map((item) => {
             item.ID = buildUUID();
           });
           AddAfterDelete(
-            objParams.value['drawers'][0]['name'],
-            data.value[objParams.value['drawers'][0]['name']],
+            d['name'],
+            data.value[d['name']],
             where,
           ).then((action) => {
             if (action.IsSuccessed) {
@@ -239,16 +237,10 @@
             }
           });
         });
-      });
-      // values.ID = params.RULE_ID;
-      // const action = await SaveRule({ ...values, ...testValues });
-      // if (action.IsSuccessed) {
-      //   await DeleteRuleDtl(params.RULE_ID);
-      //   const dtlAction = await SaveRuleDtl(data.value);
-      //   if (dtlAction.IsSuccessed) {
-      //     cancel();
-      //   }
-      // }
+      } else {
+        /* 濡傛灉鑷畾涔夋彁浜ゆ柟娉曞瓨鍦ㄥ氨鐢ㄨ嚜瀹氫箟鎻愪氦 */
+        custImport.value['default']()[0].SubmitAll(data);
+      }
     } catch (error) {}
   }
   async function cancel() {

--
Gitblit v1.9.3