From 88f02c2c018fb1e5c171bd4975dac534c584c3ba Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 十二月 2019 09:31:37 +0800
Subject: [PATCH] 2019-12-10

---
 src/templates/modalconfig/index.jsx |  310 +++++++++++++++++++++++----------------------------
 1 files changed, 142 insertions(+), 168 deletions(-)

diff --git a/src/templates/modalconfig/index.jsx b/src/templates/modalconfig/index.jsx
index c064448..98df789 100644
--- a/src/templates/modalconfig/index.jsx
+++ b/src/templates/modalconfig/index.jsx
@@ -43,11 +43,12 @@
     card: null,            // 缂栬緫鍏冪礌
     loading: false,        // 琛ㄥ崟鍒锋柊鏃朵娇鐢�
     menuloading: false,    // 鑿滃崟淇濆瓨涓�
+    closeloading: false,   // 鑿滃崟淇濆瓨涓�
     settingVisible: false, // 鍏ㄥ眬閰嶇疆妯℃�佹
     closeVisible: false,   // 鍏抽棴妯℃�佹
     tables: [],            // 鍙敤琛ㄥ悕
     selectedTables: [],    // 宸查�夎〃鍚�
-    originMenu: null,      // 鍘熷鑿滃崟
+    originConfig: null,      // 鍘熷鑿滃崟
     groupVisible: false,   // 鍏ㄥ眬閰嶇疆妯℃�佹
     curgroup: null         // 褰撳墠缁勶紝鏂板缓鎴栫紪杈�
   }
@@ -63,6 +64,7 @@
     const {menu, editAction} = this.props
 
     let _config = ''
+
     if (editAction.pageParam) {
       _config = editAction.pageParam
     } else {
@@ -76,6 +78,7 @@
     this.setState({
       config: _config,
       selectedTables: _config.tables || [],
+      originConfig: JSON.parse(JSON.stringify(_config)),
       modalformlist: [
         {
           type: 'text',
@@ -191,11 +194,13 @@
    * @description 琛ㄥ崟鍙樺寲
    * 1銆佽〃鍗曟嫋鎷芥坊鍔犳椂锛屾鏌ユ槸鍚﹀瓨鍦ㄧず渚嬭〃鍗曪紝濡傚瓨鍦ㄥ垯鍘婚櫎绀轰緥
    * 2銆佽〃鍗曠Щ鍔ㄥ悗锛屼繚瀛樼Щ鍔ㄥ悗鐨勯『搴�
+   * 3銆佹柊澧炶〃鍗曟椂锛岀洿鎺ユ墦寮�缂栬緫妗�
    */
-  handleList = (list, group, elementId) => {
+  handleList = (list, group, elementId, newcard) => {
     let _config = JSON.parse(JSON.stringify(this.state.config))
 
     if (!group && !elementId) {
+      // 娌℃湁鍒嗙粍鏃讹紙鎷栨嫿娣诲姞锛�
       if (list.length > _config.fields.length) {
         _config.fields = list.filter(item => !item.origin)
   
@@ -206,12 +211,14 @@
           this.setState({
             loading: false
           })
+          this.handleForm(newcard)
         })
       } else {
         _config.fields = list
         this.setState({config: _config})
       }
     } else if (group && !elementId) {
+      // 瀛樺湪鍒嗙粍鏃讹紝鎷栨嫿娣诲姞
       if (list.length > group.sublist.length) {
         group.sublist = list
         _config.groups = _config.groups.map(item => {
@@ -229,6 +236,7 @@
           this.setState({
             loading: false
           })
+          this.handleForm(newcard)
         })
       } else {
         group.sublist = list
@@ -242,6 +250,7 @@
         this.setState({config: _config})
       }
     } else if (group && elementId) {
+      // 淇敼宸叉湁鍏冪礌鐨勫垎缁�
       let element = null
       _config.groups.forEach(item => {
         item.sublist = item.sublist.filter(cell => {
@@ -277,9 +286,9 @@
 
   /**
    * @description 琛ㄥ崟缂栬緫
-   * 1銆佹樉绀虹紪杈戝脊绐�
-   * 2銆佷繚瀛樼紪杈戦」
-   * 3銆佽缃紪杈戝弬鏁伴」
+   * 1銆佹樉绀虹紪杈戝脊绐�-visible
+   * 2銆佷繚瀛樼紪杈戦」-card
+   * 3銆佽缃紪杈戝弬鏁伴」-formlist
    */
   handleForm = (card) => {
     this.setState({
@@ -312,6 +321,9 @@
             value: 'text',
             text: this.state.dict['header.form.text']
           }, {
+            value: 'number',
+            text: this.state.dict['header.form.number']
+          }, {
             value: 'select',
             text: this.state.dict['header.form.select']
           }, {
@@ -321,14 +333,11 @@
             value: 'date',
             text: this.state.dict['header.form.dateday']
           }, {
-            value: 'dateweek',
-            text: this.state.dict['header.form.dateweek']
-          }, {
             value: 'datemonth',
             text: this.state.dict['header.form.datemonth']
           }, {
-            value: 'daterange',
-            text: this.state.dict['header.form.daterange']
+            value: 'datetime',
+            text: this.state.dict['header.form.datetime']
           }]
         },
         {
@@ -425,6 +434,26 @@
             value: 'desc',
             text: this.state.dict['header.form.desc']
           }]
+        },
+        {
+          type: 'number',
+          key: 'decimal',
+          label: this.state.dict['header.form.decimal'],
+          initVal: card.decimal || 0,
+          required: false
+        },
+        {
+          type: 'radio',
+          key: 'readonly',
+          label: this.state.dict['header.form.readonly'],
+          initVal: card.readonly || 'false',
+          options: [{
+            value: 'true',
+            text: this.state.dict['header.form.true']
+          }, {
+            value: 'false',
+            text: this.state.dict['header.form.false']
+          }]
         }
       ]
     })
@@ -439,6 +468,14 @@
   handleSubmit = () => {
     this.formRef.handleConfirm().then(res => {
       let _config = JSON.parse(JSON.stringify(this.state.config))
+
+      if ((res.type === 'select' || res.type === 'link') && res.resourceType === '1') {
+        let sql = 'select ' + res.valueField + ',' + res.valueText + ' from (' + res.dataSource + ')'
+        if (res.orderBy) {
+          sql = sql + ' ld order by ' + res.orderBy + ' ' + res.orderType
+        }
+        res.dataSourceSql = Utils.formatOptions(sql)
+      }
 
       _config.fields = _config.fields.map(item => {
         if (item.uuid === res.uuid) {
@@ -494,175 +531,105 @@
   }
 
   submitConfig = () => {
-    const { menu } = this.props
-    const { config, originMenu } = this.state
-    this.menuformRef.handleConfirm().then(res => {
+    const { menu, editAction } = this.props
+    const { config } = this.state
       
-      if (!config.fields[0] && config.fields[0].origin) {
-        notification.warning({
-          top: 92,
-          message: '璇锋坊鍔犺〃鍗�',
-          duration: 10
-        })
-        return
-      }
-
-      let _LongParam = ''
-      let _config = {...config, tables: this.state.selectedTables}
-      let _pageParam = {...menu.PageParam, OpenType: res.opentype}
-
-      try {
-        _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
-      } catch (e) {
-        notification.warning({
-          top: 92,
-          message: '缂栬瘧閿欒',
-          duration: 10
-        })
-        return
-      }
-
-      let param = {
-        func: 'sPC_ButtonParam_AddUpt',
-        ParentID: res.parentId,
-        MenuID: menu.MenuID,
-        MenuNo: res.menuNo,
-        Template: menu.PageParam.Template || '',
-        MenuName: res.menuName,
-        PageParam: JSON.stringify(_pageParam),
-        LongParam: _LongParam
-      }
-      this.setState({
-        menuloading: true
-      })
-
-      Api.getSystemConfig(param).then(response => {
-        if (response.status) {
-          this.setState({
-            menuloading: false,
-            originMenu: {
-              ...originMenu,
-              LongParam: _config,
-              PageParam: _pageParam,
-              MenuName: res.menuName,
-              MenuNo: res.menuNo,
-              ParentID: res.parentId
-            }
-          })
-          notification.success({
-            top: 92,
-            message: '淇濆瓨鎴愬姛',
-            duration: 10
-          })
-        } else {
-          this.setState({
-            menuloading: false
-          })
-          notification.warning({
-            top: 92,
-            message: response.message,
-            duration: 10
-          })
-        }
-      })
-
-      // let param = {
-      //   func: 'sPC_TrdMenu_Upt',
-      //   ParentID: res.parentId,
-      //   MenuID: menu.MenuID,
-      //   MenuNo: res.menuNo,
-      //   Template: menu.PageParam.Template || '',
-      //   MenuName: res.menuName,
-      //   PageParam: JSON.stringify(_pageParam),
-      //   LongParam: _LongParam
-      // }
-      this.setState({
-        menuloading: true
-      })
-
-      Api.getSystemConfig(param).then(response => {
-        if (response.status) {
-          notification.success({
-            top: 92,
-            message: '淇濆瓨鎴愬姛',
-            duration: 10
-          })
-          if (this.state.closeVisible) {
-            this.props.handleConfig('')
-          } else {
-            this.setState({
-              menuloading: false,
-              originMenu: {
-                ...originMenu,
-                LongParam: _config,
-                PageParam: _pageParam,
-                MenuName: res.menuName,
-                MenuNo: res.menuNo,
-                ParentID: res.parentId
-              }
-            })
-          }
-        } else {
-          this.setState({
-            menuloading: false
-          })
-          notification.warning({
-            top: 92,
-            message: response.message,
-            duration: 10
-          })
-        }
-      })
-    }, () => {
+    if ((!config.groups[0] && !config.fields[0]) || (config.fields[0] && config.fields[0].origin)) {
       notification.warning({
         top: 92,
-        message: this.state.dict['header.menu.basemsg'],
+        message: '璇锋坊鍔犺〃鍗�',
         duration: 10
       })
+      return
+    }
+
+    let _LongParam = ''
+    let _config = {...config, tables: this.state.selectedTables}
+
+    try {
+      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
+    } catch (e) {
+      notification.warning({
+        top: 92,
+        message: '缂栬瘧閿欒',
+        duration: 10
+      })
+      return
+    }
+
+    let param = {
+      func: 'sPC_ButtonParam_AddUpt',
+      ParentID: menu.MenuID,
+      MenuID: editAction.uuid,
+      MenuNo: menu.MenuNo,
+      Template: 'Modal',
+      MenuName: editAction.label,
+      PageParam: JSON.stringify({Template: 'Modal'}),
+      LongParam: _LongParam
+    }
+
+    if (this.state.closeVisible) {
+      this.setState({
+        closeloading: true
+      })
+    } else {
+      this.setState({
+        menuloading: true
+      })
+    }
+
+    Api.getSystemConfig(param).then(response => {
+      if (response.status) {
+        this.setState({
+          menuloading: false,
+          closeloading: false,
+          originConfig: _config,
+          config: _config
+        })
+        notification.success({
+          top: 92,
+          message: '淇濆瓨鎴愬姛',
+          duration: 10
+        })
+      } else {
+        this.setState({
+          closeloading: false,
+          menuloading: false
+        })
+        notification.warning({
+          top: 92,
+          message: response.message,
+          duration: 10
+        })
+      }
     })
   }
 
   cancelConfig = () => {
     const { menu } = this.props
-    const { config, originMenu } = this.state
+    const { config, originConfig } = this.state
     let _this = this
 
     let isOrigin = config.fields.filter(item => item.origin).length > 0
     if (isOrigin) {
       confirm({
-        content: '鑿滃崟灏氭湭鎻愪氦锛岀‘瀹氭斁寮冧繚瀛樺悧锛�',
+        content: '灏氭湭鎻愪氦锛岀‘瀹氭斁寮冧繚瀛樺悧锛�',
         okText: this.state.dict['header.confirm'],
         cancelText: this.state.dict['header.cancel'],
         onOk() {
-          _this.props.handleConfig('')
+          _this.props.handleConfig(menu.type)
         },
         onCancel() {}
       })
     } else {
-      this.menuformRef.handleConfirm().then(res => {
-        let _config = {...config, tables: this.state.selectedTables}
-        let _pageParam = {...menu.PageParam, OpenType: res.opentype}
-        let _originMenu = {
-          ...originMenu,
-          LongParam: _config,
-          PageParam: _pageParam,
-          MenuName: res.menuName,
-          MenuNo: res.menuNo,
-          ParentID: res.parentId
-        }
 
-        if (!is(fromJS(originMenu), fromJS(_originMenu))) {
-          this.setState({
-            closeVisible: true
-          })
-        } else {
-          this.props.handleConfig('')
-        }
-      }, () => {
+      if (!is(fromJS(config), fromJS(originConfig))) {
         this.setState({
           closeVisible: true
         })
-      })
+      } else {
+        this.props.handleConfig(menu.type)
+      }
     }
   }
 
@@ -775,6 +742,7 @@
           valueText: '',
           orderBy: '',
           orderType: 'asc',
+          readonly: 'false'
         }
       })
       _config.groups[_config.groups.length - 1].sublist = [..._config.groups[_config.groups.length - 1].sublist, ..._additems]
@@ -818,6 +786,7 @@
             valueText: '',
             orderBy: '',
             orderType: 'asc',
+            readonly: 'false'
           }
   
           items.push(newcard)
@@ -906,8 +875,8 @@
     const {selectedTables, tableColumns} = this.state
 
     this.setState({
-      selectedTables: selectedTables.filter(item => item.name !== table.name),
-      tableColumns: tableColumns.filter(item => item.tableName !== table.name)
+      selectedTables: selectedTables.filter(item => item.TbName !== table.TbName),
+      tableColumns: tableColumns.filter(item => item.tableName !== table.TbName)
     })
   }
 
@@ -968,7 +937,7 @@
         
         if (_length === 1) {
           _config.fields = [...group.sublist, ..._config.groups[0].sublist]
-          _config.groups[0].sublist = []
+          _config.groups = []
         } else {
           _config.groups[_length - 1].sublist = [...group.sublist, ..._config.groups[_length - 1].sublist]
         }
@@ -996,13 +965,18 @@
       if (_group.isnew) {
         delete _group.isnew
         config.groups.unshift(_group)
-        config.groups = config.groups.map(item => {
-          if (item.default) {
-            return res.default
-          } else {
-            return item
-          }
-        })
+
+        if (config.groups.length > 1) {
+          config.groups = config.groups.map(item => {
+            if (item.default) {
+              return res.default
+            } else {
+              return item
+            }
+          })
+        } else {
+          config.groups.push(res.default)
+        }
       } else {
         config.groups = config.groups.map(item => {
           if (item.uuid === _group.uuid) {
@@ -1035,6 +1009,7 @@
   }
 
   render () {
+    const { menu } = this.props
     const { config } = this.state
 
     return (
@@ -1046,7 +1021,6 @@
                 <MenuForm
                   dict={this.state.dict}
                   formlist={this.state.modalformlist}
-                  wrappedComponentRef={(inst) => this.menuformRef = inst}
                 />
                 <div className="ant-col ant-form-item-label">
                   <label title={this.state.dict['header.menu.table.add']}>
@@ -1109,7 +1083,7 @@
                 </div>
                 <div className="ant-modal-body">
                   <div className="modal-form">
-                    {!this.state.loading && config.groups.length > 1 &&
+                    {!this.state.loading && config.groups.length > 0 &&
                       config.groups.map(group => {
                         return (
                           <div key={group.uuid}>
@@ -1131,7 +1105,7 @@
                         )
                       })
                     }
-                    {!this.state.loading && config.groups.length === 1?
+                    {!this.state.loading && config.groups.length === 0 ?
                       <DragElement
                         list={config.fields}
                         setting={config.setting}
@@ -1210,8 +1184,8 @@
           visible={this.state.closeVisible}
           onCancel={() => { this.setState({closeVisible: false}) }}
           footer={[
-            <Button key="save" className="mk-btn mk-green" onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>,
-            <Button key="confirm" className="mk-btn mk-yellow" onClick={() => {this.props.handleConfig('')}}>{this.state.dict['header.notsave']}</Button>,
+            <Button key="save" className="mk-btn mk-green" loading={this.state.closeloading} onClick={this.submitConfig}>{this.state.dict['header.save']}</Button>,
+            <Button key="confirm" className="mk-btn mk-yellow" onClick={() => {this.props.handleConfig(menu.type)}}>{this.state.dict['header.notsave']}</Button>,
             <Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>{this.state.dict['header.cancel']}</Button>
           ]}
           destroyOnClose

--
Gitblit v1.8.0