From 697d8416feb8919f1371ea4a32988ed63dac24c0 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 14 一月 2020 15:31:03 +0800
Subject: [PATCH] 2020-01-14

---
 src/templates/formtabconfig/index.jsx |  263 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 152 insertions(+), 111 deletions(-)

diff --git a/src/templates/formtabconfig/index.jsx b/src/templates/formtabconfig/index.jsx
index e8a15df..c09e724 100644
--- a/src/templates/formtabconfig/index.jsx
+++ b/src/templates/formtabconfig/index.jsx
@@ -13,6 +13,7 @@
 import Api from '@/api'
 import SearchForm from './modalform'
 import DragElement from './dragelement'
+import GroupForm from './groupform'
 import EditCard from '@/templates/tableshare/editcard'
 import VerifyCard from '@/templates/tableshare/verifycard'
 import MenuForm from '@/templates/tableshare/menuform'
@@ -43,7 +44,6 @@
     visible: false,          // 鎼滅储鏉′欢銆佹寜閽�佹樉绀哄垪锛屾ā鎬佹鏄剧ず鎺у埗
     modalTitle: '',          // 妯℃�佹鐨勬爣棰�
     tableVisible: false,     // 鏁版嵁琛ㄥ瓧娈垫ā鎬佹
-    addType: '',             // 娣诲姞绫诲瀷-鎼滅储鏉′欢鎴栨樉绀哄垪
     tableColumns: [],        // 琛ㄦ牸鏄剧ず鍒�
     fields: null,            // 鎼滅储鏉′欢鍙婃樉绀哄垪锛屽彲閫夊瓧娈�
     menuformlist: null,      // 鍩烘湰淇℃伅琛ㄥ崟瀛楁
@@ -64,7 +64,9 @@
     delActions: [],          // 鍒犻櫎鎸夐挳鍒楄〃
     funcLoading: false,      // 瀛樺偍杩囩▼鍒涘缓涓�
     tabviews: [],            // 鎵�鏈夋爣绛鹃〉
-    profileVisible: false    // 楠岃瘉淇℃伅妯℃�佹
+    profileVisible: false,   // 楠岃瘉淇℃伅妯℃�佹
+    editgroup: null,
+    groupVisible: null
   }
 
   /**
@@ -74,7 +76,7 @@
    */
   UNSAFE_componentWillMount () {
     const { menu, editAction, config } = this.props
-
+    console.log(menu)
     let _config = ''
 
     if (!config) {
@@ -276,13 +278,13 @@
       }
     } else if (type === 'search') {
       let _group = config.groups.filter(group => group.uuid === groupId)[0]
-      let isChange = list.length > _group.length
-      let isAdd = !elementId && list.length > _group.length
+      let isChange = elementId && list.length > _group.sublist.length
+      let isAdd = !elementId && list.length > _group.sublist.length
 
       if (isAdd) {
         _group.sublist = list.filter(item => !item.origin)
         this.handleSearch(card)
-      } else if (elementId) {
+      } else if (isChange) {
         // 淇敼宸叉湁鍏冪礌鐨勫垎缁�
         let element = null
         config.groups.forEach(item => {
@@ -1595,6 +1597,7 @@
 
       let btnParam = { // 娣诲姞鑿滃崟鎸夐挳
         func: 'sPC_Button_AddUpt',
+        Type: 60, // 娣诲姞鎸夐挳琛ㄥ崟椤典笅鐨勬寜閽�
         ParentID: menu.MenuID,
         MenuNo: res.menuNo,
         Template: menu.PageParam.Template || '',
@@ -1863,49 +1866,30 @@
 
     if (type === 'search') {
       // 娣诲姞鎼滅储鏉′欢锛屽瓧娈甸泦涓瓨鍦ㄦ悳绱㈡潯浠跺瓧娈碉紝浣跨敤鎼滅储鏉′欢瀵硅薄鏇挎崲瀛楁闆嗭紝璁剧疆鏁版嵁绫诲瀷
-      config.search.forEach(item => {
-        if (columns.has(item.field)) {
-          let _datatype = columns.get(item.field).datatype
-          columns.set(item.field, {...item, selected: true, datatype: _datatype})
-        }
+      config.groups.forEach(group => {
+        group.sublist.forEach(item => {
+          if (columns.has(item.field)) {
+            let _datatype = columns.get(item.field).datatype
+            columns.set(item.field, {...item, selected: true, datatype: _datatype})
+          }
+        })
       })
     }
 
     // 鏄剧ず瀛楁闆嗗脊绐�
     this.setState({
-      addType: type,
       tableVisible: true,
       fields: [...columns.values()]
     })
   }
 
   addFieldSubmit = () => {
+    const {config} = this.state
     // 瀛楁闆嗕负绌猴紝鍏抽棴寮圭獥
     if (!this.state.fields || this.state.fields.length === 0) {
       this.setState({
         tableVisible: false,
-        addType: ''
       })
-    }
-
-    const {addType, config} = this.state
-    const textmatch = { // 閫夋嫨text鏃跺尮閰嶈鍒�
-      text: 'like',
-      number: 'like',
-      datetime: 'like',
-      date: 'like'
-    }
-    const selectmatch = { // 閫夋嫨select鏃跺尮閰嶈鍒�
-      text: '=',
-      number: '=',
-      datetime: '=',
-      date: '='
-    }
-    const datematch = { // 閫夋嫨dateRange鏃跺尮閰嶈鍒�
-      text: 'between',
-      number: 'between',
-      datetime: 'between',
-      date: 'between'
     }
 
     // 鑾峰彇宸查�夊瓧娈甸泦鍚�
@@ -1915,77 +1899,50 @@
       columnsMap.set(card.field, card)
     })
 
-    let items = []
-    config.search.forEach(item => {
-      if (columnsMap.has(item.field)) {
-        let cell = columnsMap.get(item.field)
-
-        if (cell.selected && cell.type === item.type) { // 鏁版嵁鏈慨鏀�
-          items.push(item)
-        } else if (cell.selected) { // 鏁版嵁绫诲瀷淇敼
-          if (cell.type === 'text') {
-            item.match = textmatch[cell.datatype]
-          } else if (cell.type === 'select') {
-            item.match = selectmatch[cell.datatype]
-          } else if (cell.type === 'daterange') {
-            item.match = datematch[cell.datatype]
-          } else {
-            cell.type = 'text'
-            item.match = textmatch[cell.datatype]
+    console.log(cards)
+    let groups = config.groups.map(group => {
+      group.sublist = group.sublist.map(item => {
+        if (columnsMap.has(item.field)) {
+          let cell = columnsMap.get(item.field)
+  
+          if (cell.selected && cell.type !== item.type) { // 鏁版嵁绫诲瀷淇敼
+            item.type = cell.type
+            item.initval = ''
           }
-          
-          item.type = cell.type
-          item.initval = ''
-          items.push(item)
+          columnsMap.delete(item.field)
         }
-        columnsMap.delete(item.field)
-      } else if (!item.origin) {
-        items.push(item)
-      }
+        return item
+      })
+      return group
     })
 
-    let _columns = [...columnsMap.values()]
-
-    _columns.forEach(item => {
-      if (item.selected) {
-        let _match = ''
-        if (item.type === 'text') {
-          _match = textmatch[item.datatype]
-        } else if (item.type === 'select') {
-          _match = selectmatch[item.datatype]
-        } else if (item.type === 'daterange') {
-          _match = datematch[item.datatype]
-        } else {
-          item.type = 'text'
-          _match = textmatch[item.datatype]
-        }
-
-        let newcard = {
-          uuid: Utils.getuuid(),
-          label: item.label,
-          field: item.field,
-          initval: '',
-          type: item.type,
-          resourceType: '0',
-          setAll: 'false',
-          options: [],
-          dataSource: '',
-          linkField: '',
-          valueField: '',
-          valueText: '',
-          orderBy: '',
-          orderType: 'asc',
-          match: _match,
-          display: 'dropdown'
-        }
-
-        items.push(newcard)
+    let items =  [...columnsMap.values()].map(item => {
+      let newcard = {
+        uuid: Utils.getuuid(),
+        label: item.label,
+        field: item.field,
+        initval: '',
+        type: item.type,
+        resourceType: '0',
+        setAll: 'false',
+        options: [],
+        orderType: 'asc'
       }
+
+      return newcard
+    })
+
+    groups = groups.map(group => {
+      if (group.isDefault) {
+        group.sublist = [...group.sublist, ...items]
+        group.sublist = group.sublist.filter(item => !item.origin)
+      }
+      return group
     })
 
     this.setState({
-      [addType + 'loading']: true,
-      config: {...config, [addType]: items}
+      searchloading: true,
+      config: {...config, groups: groups}
     }, () => {
       notification.success({
         top: 92,
@@ -1993,7 +1950,7 @@
         duration: 2
       })
       this.setState({
-        [addType + 'loading']: false
+        searchloading: false
       })
     })
   }
@@ -2296,6 +2253,83 @@
     })
   }
 
+  handleGroup = (group) => {
+    let editgroup = {
+      label: '',
+      sort: 0,
+      uuid: Utils.getuuid(),
+      sublist: []
+    }
+
+    if (group) {
+      editgroup = group
+    }
+
+    this.setState({
+      groupVisible: true,
+      editgroup: editgroup
+    })
+  }
+
+  closeGroup = (group) => {
+    const { config } = this.state
+    let _this = this
+
+    confirm({
+      content: `纭畾鍒犻櫎鍒嗙粍<<${group.label}>>鍚楋紵`,
+      okText: this.state.dict['header.confirm'],
+      cancelText: this.state.dict['header.cancel'],
+      onOk() {
+        let groups = config.groups.filter(item => !(item.uuid === group.uuid))
+        groups = groups.map(item => {
+          if (item.isDefault) {
+            item.sublist = [...item.sublist, ...group.sublist]
+          }
+
+          return item
+        })
+
+        _this.setState({
+          config: {...config, groups: groups},
+          searchloading: true
+        }, () => {
+          _this.setState({
+            searchloading: false
+          })
+        })
+      },
+      onCancel() {}
+    })
+  }
+
+  handleGroupSave = () => {
+    const { editgroup, config } = this.state
+    let groups = config.groups.filter(item => !item.isDefault && item.uuid !== editgroup.uuid)
+
+    this.groupRef.handleConfirm().then(res => {
+      if (editgroup.isDefault) {
+        groups.push(res)
+      } else {
+        groups.push(res.default, res.target)
+      }
+
+      groups = groups.sort((a, b) => {
+        return a.sort - b.sort
+      })
+      
+      this.setState({
+        config: {...config, groups: groups},
+        editgroup: '',
+        groupVisible: false,
+        searchloading: true
+      }, () => {
+        this.setState({
+          searchloading: false
+        })
+      })
+    })
+  }
+
   render () {
     const { config } = this.state
     let _length = config.groups.length
@@ -2425,21 +2459,15 @@
                     <span>
                       {index === _length - 1 ? <Icon
                         type="plus"
-                        onClick={event => {
-                          event.stopPropagation()
-                        }}
+                        onClick={() => { this.handleGroup()}}
                       /> : null}
                       {_length > 1 && index !== _length - 1 ? <Icon
                         type="delete"
-                        onClick={event => {
-                          event.stopPropagation()
-                        }}
+                        onClick={() => { this.closeGroup(group) }}
                       /> : null}
                       <Icon
                         type="edit"
-                        onClick={event => {
-                          event.stopPropagation()
-                        }}
+                        onClick={() => { this.handleGroup(group) }}
                       />
                     </span>
                   )}>
@@ -2549,14 +2577,13 @@
           onOk={this.addFieldSubmit}
           onCancel={() => { // 鍙栨秷娣诲姞
             this.setState({
-              tableVisible: false,
-              addType: ''
+              tableVisible: false
             })
           }}
           destroyOnClose
         >
-          {this.state.addType && this.state.fields.length > 0 ?
-            <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} dict={this.state.dict} /> : null
+          {this.state.fields && this.state.fields.length > 0 ?
+            <EditCard data={this.state.fields} ref="searchcard" type={'form'} dict={this.state.dict} /> : null
           }
           {(!this.state.fields || this.state.fields.length === 0) &&
             <Empty />
@@ -2597,7 +2624,6 @@
             dict={this.state.dict}
             menu={this.props.menu}
             config={this.state.config}
-            data={this.state.config.setting}
             columns={this.state.config.columns}
             usefulFields={this.props.permFuncField}
             wrappedComponentRef={(inst) => this.settingRef = inst}
@@ -2617,6 +2643,21 @@
         >
           {this.state.dict['header.menu.config.placeholder']}
         </Modal>
+        <Modal
+          title={this.state.dict['header.menu.group.manage']}
+          visible={this.state.groupVisible}
+          width={700}
+          onOk={this.handleGroupSave}
+          onCancel={() => { this.setState({ groupVisible: false }) }}
+          destroyOnClose
+        >
+          <GroupForm
+            groups={config.groups}
+            group={this.state.editgroup}
+            dict={this.state.dict}
+            wrappedComponentRef={(inst) => this.groupRef = inst}
+          />
+        </Modal>
         {this.state.loading && <Spin size="large" />}
       </div>
     )

--
Gitblit v1.8.0