From 08f1b081e006f0f3b83bcbdf47f4ef494e18450b Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 11 九月 2024 00:50:18 +0800
Subject: [PATCH] 包装规则更新,保存修改,重量范围

---
 src/views/tigerprojects/system/lowcode/composition/Config.vue |  236 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 193 insertions(+), 43 deletions(-)

diff --git a/src/views/tigerprojects/system/lowcode/composition/Config.vue b/src/views/tigerprojects/system/lowcode/composition/Config.vue
index b517eca..15bbf82 100644
--- a/src/views/tigerprojects/system/lowcode/composition/Config.vue
+++ b/src/views/tigerprojects/system/lowcode/composition/Config.vue
@@ -1,46 +1,70 @@
 <!--
- * @Description: file content
+ * @Description: 缁勫悎椤甸潰涓殑璁剧疆椤甸潰
  * @Author: Ben Lin
  * @version: 
  * @Date: 2024-06-24 23:44:31
  * @LastEditors: Ben Lin
- * @LastEditTime: 2024-07-23 20:48:29
+ * @LastEditTime: 2024-08-09 16:49:10
 -->
 <template>
   <Card :title="GetTitle(props.configType)['configTitle']">
-    <BasicForm @register="registerForm">
+    <BasicForm
+      @register="useForms[d]"
+      @submit="customSubmitFunc"
+      v-for="d in Object.keys(useForms)"
+      :key="d"
+      v-show="d == props.configType"
+    >
       <template #[item]="{ field }" v-for="item in GetCrudColSlots()" :key="item">
         <a-button
           v-if="field"
           class="mt-1 ml-1"
           size="small"
-          @click="handleSelectItem(item)"
+          @click="SelectItemInForm(item)"
           preIcon="search|svg"
         />
         <GeneralModal
-          @register="registerItemAdd"
-          @success="(d, u) => handleItemSuccess(d, u, item)"
+          @register="useModalData[item][0]"
+          @success="(d, u) => SelectInFormSuccess(d, u, item)"
         />
       </template>
     </BasicForm>
   </Card>
+  <Card
+    :title="GetTitle(props.configType, item)['tableTitle']"
+    :bordered="false"
+    class="!mt-5"
+    v-for="item in OtherTables"
+    :key="item"
+    v-show="showOtherTable[item]">
+    <BasicTable @register="useTables[item][0]"
+    v-if="showOtherTable[item]">
+      <template #action="{ record }">
+        <TableAction :actions="createActions(record, item)" />
+      </template>
+    </BasicTable>
+    <normalDrawer @register="useDrawers[item][0]" @success="(d,u) => EditSuccess(d, u, item)" />
+  </Card>
 </template>
 <script lang="ts" setup>
   import { Ref, inject, nextTick, onMounted, ref, unref, watch } from 'vue';
-  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
+  import { BasicForm } from '/@/components/Form/index';
+  import { BasicTable, TableAction } from '/@/components/Table';
   import { Card } from 'ant-design-vue';
-  import { useModal } from '/@/components/Modal';
   import GeneralModal from '/@/views/components/GeneralModal.vue';
   import { useI18n } from '/@/hooks/web/useI18n';
-  import { isNullOrUnDef } from '/@/utils/is';
+  import { isFunction, isNullOrUnDef } from '/@/utils/is';
   import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
+  import { editRecord } from '../data';
+  import { useDrawer } from '/@/components/Drawer';
+  import normalDrawer from '../normalDrawer.vue';
 
   const { t } = useI18n();
   const emit = defineEmits(['success', 'register']);
   const props = defineProps({
     configType: { type: String },
   });
-  const [registerItemAdd, { openModal: openItemModal }] = useModal();
+  const showOtherTable = ref<any>({}); //鏄剧ず琛ㄦ牸甯冨皵瀵硅薄
   const objParams = inject('objParams') as Ref<any>;
   const custImport = ref<any[]>([]);
   const EntityCustFunction = ref([
@@ -49,6 +73,8 @@
       GetCrudColSlots(val, id) {},
       OpenSelectItem(openItemModal: Fn, ...args) {},
       GetSelectSuccess(d, u, ...args) {},
+      GetUseModals() {},
+      GetUseTables(data: Ref<Recordable[]>, ...args) {},
       GetTitle(type: string | undefined) {},
       nodeChange(params: {
         resetFields: any;
@@ -72,27 +98,25 @@
       GetSelectSuccess,
       GetTitle,
       SubmitFunc,
+      GetUseModals,
+      GetUseTables,
+      GetUseForm,
+      CustFunc,
     },
   ] = isNullOrUnDef(custImport.value['default'])
     ? EntityCustFunction.value
     : custImport.value['default']();
 
-  let formSchema: FormSchema[] = GetCrudForm(props.configType);
-  const [registerForm, { resetFields, setFieldsValue, validate, setProps }] = useForm({
-    labelWidth: 120,
-    schemas: formSchema,
-    actionColOptions: {
-      offset: 8,
-      span: 24,
-    },
-    wrapperCol: {
-      span: 15,
-    },
-    showActionButtonGroup: true,
-    submitButtonOptions: {
-      text: '淇濆瓨',
-    },
-    submitFunc: customSubmitFunc,
+  const useModalData = ref(GetUseModals());
+  const data = ref({});
+  const useTables = ref(GetUseTables(data, emit));
+  const useForms = ref(GetUseForm());
+  const useDrawers = ref({});
+  const OtherTables = ref(objParams.value['OtherTableName']);
+  /* 寰幆鑷畾涔夎〃鏍煎悕鍒楄〃锛屽垵濮嬪寲鏄剧ず琛ㄦ牸甯冨皵瀵硅薄 */
+  objParams.value['OtherTableName'].forEach((x) => {
+    showOtherTable.value[x] = false;
+    useDrawers.value[x] = useDrawer();
   });
 
   /* 娉ㄥ叆閫変腑鑺傜偣鏁版嵁 */
@@ -101,15 +125,41 @@
     () => selectedNodes.value,
     (newVal, oldVal) => {
       nextTick(() => {
-        /* 鑺傜偣鍒囨崲浜嬩欢 */
-        nodeChange({ resetFields, setFieldsValue, objParams, selectedNodes });
-        formSchema = GetCrudForm(selectedNodes.value[0].type);
-        setProps({
-          schemas: []
-        });
-        setProps({
-          schemas: formSchema
-        });
+        if (newVal != oldVal) {
+          /* 鑺傜偣鍒囨崲浜嬩欢 */
+          nodeChange({ useForms, objParams, selectedNodes: newVal }).then((result) => {
+            const setProps = useForms.value[newVal[0].type][1].setProps;
+            showOtherTable.value = result.isShow;
+            setProps({
+              schemas: [],
+            });
+            setProps({
+              schemas: GetCrudForm(newVal[0].type),
+            });
+            /* 鏄剧ず鍏朵粬琛ㄦ牸 */
+            const name = result['name'];
+            if (showOtherTable.value[name]) {
+              showOtherTable.value[name] = false;
+              data.value[name] = result[name];
+              data.value['Action'] = result['Action'];
+              useTables.value = GetUseTables(data, emit);
+              setTimeout(() => {
+                showOtherTable.value[name] = true;
+              }, 10);
+              setTimeout(() => {
+                if (!isNullOrUnDef(name)) {
+                // useTables.value[name][1].setProps({
+                //   dataSource: [],
+                // });
+                // useTables.value[name][1].setProps({
+                //   dataSource: data.value[name],
+                // });
+                  useTables.value[name][1].reload();
+                }
+              }, 1000);
+            }
+          });
+        }
       });
     },
     { deep: true, immediate: true },
@@ -117,13 +167,34 @@
 
   onMounted(() => {
     /* 鑺傜偣鍒囨崲浜嬩欢 */
-    nodeChange({ resetFields, setFieldsValue, objParams, selectedNodes });
+    const nodes = selectedNodes.value;
+    nodeChange({ useForms, objParams, selectedNodes: nodes }).then((result) => {
+      showOtherTable.value = result.isShow;
+      data.value['Action'] = result['Action'];
+      useTables.value = GetUseTables(data, emit);
+      if (showOtherTable.value[result['name']]) {
+        data.value[result['name']] = result[result['name']];
+        // useTables.value[result['name']][1].setProps({
+        //   dataSource: [],
+        // });
+        // useTables.value[result['name']][1].setProps({
+        //   dataSource: result[result['name']],
+        // });
+        if (!isNullOrUnDef(result['name'])) {
+          useTables.value[result['name']][1].reload();
+        }
+      }
+    });
   });
 
-  async function customSubmitFunc() {
+  /**
+   * @description: 鑷畾涔夋彁浜ゆ柟娉�
+   * @param {*} values
+   * @return {*}
+   */
+  async function customSubmitFunc(values) {
     try {
-      const values = await validate();
-      SubmitFunc(values,props.configType, emit);
+      SubmitFunc(values, props.configType, emit);
       // values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
       // values.FACTORY = useUserStore().getUserInfo.prodCode;
       // const apiAction = SaveEntity(values, true, 'MES_PROD_ACTION');
@@ -136,12 +207,73 @@
   }
 
   /**
+   * @description: 鐢熸垚鍒楄〃涓搷浣滈」鐨勬寜閽�
+   * @param {*} record
+   * @return {*}
+   */
+  function createActions(record, name) {
+    const params = {
+      record,
+      isUpdate: true,
+      entityName: name,
+      formJson: GetCrudForm(name),
+      ifSave: objParams.value['ifSave'],
+      // cType,
+      // dtlSlots,
+      // formSchemas,
+      // useModalData,
+      // useFormData,
+      crudColSlots: objParams.value['crudColSlots'][name],
+    };
+
+    const actionItem = [
+      {
+        icon: 'clarity:note-edit-line',
+        onClick: editRecord.bind(null, useDrawers.value[name][1].openDrawer, params),
+        name: undefined,
+      },
+    ];
+    return actionItem;
+  }
+
+  /**
+   * @description: 鏂板缂栬緫杩斿洖鎴愬姛鏂规硶
+   * @param {*} d
+   * @param {*} u
+   * @return {*}
+   */
+  function EditSuccess(d, u, item) {
+    if (CustFunc && isFunction(CustFunc)) {
+      CustFunc({
+        ctype: item,
+        values: d,
+        data: data,
+      }).then(() => {
+        /* 鏄剧ず鍏朵粬琛ㄦ牸 */
+        if (showOtherTable.value[item]) {
+          showOtherTable.value[item] = false;
+          setTimeout(() => {
+            showOtherTable.value[item] = true;
+          }, 10);
+          useTables.value = GetUseTables(data, emit);
+          setTimeout(() => {
+            useTables.value[item][1].reload();
+            useForms.value['Action'][1].resetFields();
+            useForms.value['Action'][1].setFieldsValue(data.value['Action'][0]);
+          }, 10);
+        }
+      });
+    }
+    useTables.value[item][1].reload();
+  }
+
+  /**
    * @description: 鐐瑰嚮鎵撳紑寮瑰嚭閫夋嫨鍒楄〃妗�
    * @param {*} item
    * @return {*}
    */
-  function handleSelectItem(item) {
-    OpenSelectItem(openItemModal, item);
+  function SelectItemInForm(item) {
+    OpenSelectItem(useModalData.value[item][1].openModal, item);
   }
 
   /**
@@ -151,7 +283,25 @@
    * @param {*} item
    * @return {*}
    */
-  function handleItemSuccess(d, u, item) {
-    setFieldsValue(GetSelectSuccess(d, u, item));
+  function SelectInFormSuccess(d, u, item) {
+    GetSelectSuccess(d, u, item).then((result) => {
+      useForms.value[props.configType][1].setFieldsValue(result['value']);
+      data.value[props.configType as string].map((x) => {
+        Object.getOwnPropertyNames(result['value']).forEach(key => {
+            x[key] = result['value'][key];
+         });
+      });
+      showOtherTable.value = result['isShow'];
+      data.value[result.name] = result['data']
+      /* 閲嶆柊useTable锛屽惁鍒欐暟鎹笉鍒锋柊 */
+      useTables.value = GetUseTables(data, emit);
+      if (showOtherTable.value[result.name]) {
+          showOtherTable.value[result.name] = false;
+          setTimeout(() => {
+            showOtherTable.value[result.name] = true;
+          }, 10);
+        useTables.value[result.name][1].reload();
+      }
+    });
   }
 </script>

--
Gitblit v1.9.3