From 888095418c902cc94693cba8b45f31bb79cdf818 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 28 二月 2020 01:31:46 +0800
Subject: [PATCH] 2020-02-28

---
 src/templates/modalconfig/index.jsx |   91 ++++++++++++++++++++++++++++-----------------
 1 files changed, 56 insertions(+), 35 deletions(-)

diff --git a/src/templates/modalconfig/index.jsx b/src/templates/modalconfig/index.jsx
index 36a5db4..bad80d3 100644
--- a/src/templates/modalconfig/index.jsx
+++ b/src/templates/modalconfig/index.jsx
@@ -48,6 +48,7 @@
     dict: CommonDict,      // 瀛楀吀
     config: null,          // 椤甸潰閰嶇疆锛屽寘鎷ā鏉跨被鍨嬨�佹ā鎬佹璁剧疆銆佹坊鍔犺〃鍚嶃�佽〃鍗曞垪琛�
     visible: false,        // 琛ㄥ崟缂栬緫妯℃�佹锛屾樉绀烘帶鍒�
+    modalType: null,       // 琛ㄥ崟缂栬緫绫诲瀷锛岀紪杈戞垨澶嶅埗
     tableVisible: false,   // 鏁版嵁琛ㄥ瓧娈靛垪琛ㄦā鎬佹锛屾樉绀烘帶鍒�
     tableColumns: [],      // 琛ㄦ牸瀛楁鍚嶅垪琛�
     fields: null,          // 琛ㄥ崟锛屽彲閫夊瓧娈碉紙鍘婚噸鍚庯級
@@ -372,8 +373,15 @@
    * 2銆佷繚瀛樼紪杈戦」-card
    * 3銆佽缃紪杈戝弬鏁伴」-formlist
    */
-  handleForm = (card) => {
+  handleForm = (_card, type) => {
     const {menu, tabConfig, subTabConfig} = this.props
+    let card = JSON.parse(JSON.stringify(_card))
+
+    if (type === 'copy') {
+      card.originUuid = card.uuid
+      card.uuid = Utils.getuuid()
+      card.focus = true
+    }
 
     const { config } = this.state
     let _inputfields = []
@@ -449,6 +457,7 @@
 
     this.setState({
       visible: true,
+      modalType: type,
       card: card,
       formlist: getModalForm(card, _inputfields, _linkableFields, !!this.props.editTab)
     })
@@ -462,6 +471,8 @@
    */
   handleSubmit = () => {
     const {editAction, optionLibs} = this.props
+    const { card, modalType } = this.state
+
     this.formRef.handleConfirm().then(res => {
       let _config = JSON.parse(JSON.stringify(this.state.config))
 
@@ -479,30 +490,60 @@
         })
       }
 
-      if (_config.groups.length > 0) {
-        _config.groups.forEach(group => {
-          group.sublist = group.sublist.map(item => {
+      if (modalType === 'copy' && card.originUuid) {
+        if (_config.groups.length > 0) {
+          _config.groups = _config.groups.map(group => {
+            let _index = null
+            group.sublist.forEach((item, index) => {
+              if (item.uuid === card.originUuid) {
+                _index = index
+              }
+            })
+
+            if (_index !== null) {
+              group.sublist.splice(_index + 1, 0, res)
+            }
+
+            return group
+          })
+        } else {
+          let _index = null
+          _config.fields.forEach((item, index) => {
+            if (item.uuid === card.originUuid) {
+              _index = index
+            }
+          })
+
+          _config.fields.splice(_index + 1, 0, res)
+        }
+      } else {
+        if (_config.groups.length > 0) {
+          _config.groups.forEach(group => {
+            group.sublist = group.sublist.map(item => {
+              if (item.uuid === res.uuid) {
+                return res
+              } else {
+                return item
+              }
+            })
+          })
+        } else {
+          _config.fields = _config.fields.map(item => {
             if (item.uuid === res.uuid) {
               return res
             } else {
               return item
             }
           })
-        })
-      } else {
-        _config.fields = _config.fields.map(item => {
-          if (item.uuid === res.uuid) {
-            return res
-          } else {
-            return item
-          }
-        })
+        }
       }
       
       _config.fields = _config.fields.filter(item => !item.origin)
 
       this.setState({
         config: _config,
+        modalType: null,
+        card: null,
         optionLibs: optionLibs,
         visible: false
       })
@@ -551,27 +592,6 @@
       return
     }
 
-    // if (config.setting.display === 'prompt') { // 鏈夐渶瑕佺疆绌虹殑鍦烘櫙
-    //   let _fields = []
-    //   if (config.groups.length > 0) {
-    //     config.groups.forEach(group => {
-    //       _fields = [..._fields, ...group.sublist]
-    //     })
-    //   } else {
-    //     _fields = config.fields
-    //   }
-  
-    //   let readfields = _fields.filter(item => item.initval || item.initval === 0)
-    //   if (readfields.length < _fields.length) {
-    //     notification.warning({
-    //       top: 92,
-    //       message: '浠ャ�婃槸鍚︽銆嬫樉绀虹殑寮规锛屾墍鏈夎〃鍗曞繀椤诲惈鏈夐粯璁ゅ�硷紒',
-    //       duration: 10
-    //     })
-    //     return
-    //   }
-    // }
-
     let _LongParam = ''
     let _config = {...config, tables: this.state.selectedTables}
 
@@ -612,6 +632,7 @@
         this.setState({
           menuloading: false,
           closeloading: false,
+          closeVisible: false,
           originConfig: _config,
           config: _config
         })
@@ -1181,7 +1202,7 @@
           </div>
         </DndProvider>
         <Modal
-          title={this.state.dict['header.edit']}
+          title={this.state.modalType !== 'copy' ? this.state.dict['header.edit'] : this.state.dict['header.modal.form.copy']}
           visible={this.state.visible}
           width={700}
           onCancel={this.editModalCancel}

--
Gitblit v1.8.0