From e36eb1999794bd71e76482b92a0b0b20f49d0032 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 05 三月 2021 19:37:03 +0800
Subject: [PATCH] 2021-03-05

---
 src/templates/sharecomponent/fieldscomponent/index.jsx |  236 +++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 191 insertions(+), 45 deletions(-)

diff --git a/src/templates/sharecomponent/fieldscomponent/index.jsx b/src/templates/sharecomponent/fieldscomponent/index.jsx
index 31db78f..a828bf7 100644
--- a/src/templates/sharecomponent/fieldscomponent/index.jsx
+++ b/src/templates/sharecomponent/fieldscomponent/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { fromJS } from 'immutable'
+import { is, fromJS } from 'immutable'
 import { Button, Modal, Empty, notification } from 'antd'
 
 import Utils from '@/utils/utils.js'
@@ -10,25 +10,23 @@
 
 import './index.scss'
 
-// **鎮茶鑰呭線寰�姝g‘锛屼箰瑙傝�呭線寰�鎴愬姛
 class FieldsComponent extends Component {
   static propTpyes = {
     type: PropTypes.string,          // 鎼滅储鏉′欢娣诲姞銆佹樉绀哄垪娣诲姞
     config: PropTypes.object,        // 瀹瑰櫒Id
-    tableFields: PropTypes.string,   // 宸查�夎〃瀛楁闆�
     updatefield: PropTypes.func
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     fields: [],          // 瀛楁闆�
     tableVisible: false,    // 妯℃�佹鎺у埗
   }
 
   queryField = () => {
-    const { type, config, tableFields } = this.props
+    const { type, config } = this.props
     // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕
-    if (!config.tables || config.tables.length === 0) {
+    if (!window.GLOB.tableFields || window.GLOB.tableFields.length === 0) {
       notification.warning({
         top: 92,
         message: '璇烽�夋嫨琛ㄥ悕锛�',
@@ -39,28 +37,53 @@
 
     // 琛ㄥ瓧娈甸泦杞负map鏁版嵁
     let columns = new Map()
-    tableFields.forEach(table => {
+    window.GLOB.tableFields.forEach(table => {
       table.columns.forEach(column => {
-        columns.set(column.field, column)
+        columns.set(column.field.toLowerCase(), column)
       })
     })
 
     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})
+        if (columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
         }
       })
     } else if (type === 'columns') {
       // 娣诲姞鏄剧ず鍒楋紝瀛楁闆嗕腑瀛樺湪鏄剧ず鍒楀瓧娈碉紝浣跨敤鏄剧ず鍒楀璞℃浛鎹㈠瓧娈甸泦锛岃缃暟鎹被鍨�
       config.columns.forEach(item => {
-        if (columns.has(item.field)) {
-          let _datatype = columns.get(item.field).datatype
-          columns.set(item.field, {...item, selected: true, datatype: _datatype})
+        if (columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
         }
       })
+    } else if (type === 'fields') {
+      config.columns.forEach(item => {
+        if (columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
+        }
+      })
+    } else if (type === 'form') {
+      if (config.groups.length > 1) {
+        config.groups.forEach(group => {
+          group.sublist.forEach(item => {
+            if (columns.has(item.field.toLowerCase())) {
+              let _datatype = columns.get(item.field.toLowerCase()).datatype
+              columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
+            }
+          })
+        })
+      } else {
+        config.fields.forEach(item => {
+          if (columns.has(item.field.toLowerCase())) {
+            let _datatype = columns.get(item.field.toLowerCase()).datatype
+            columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
+          }
+        })
+      }
     }
 
     // 鏄剧ず瀛楁闆嗗脊绐�
@@ -85,14 +108,14 @@
     let cards = this.refs.searchcard.state.selectCards
     let columnsMap = new Map()
     cards.forEach(card => {
-      columnsMap.set(card.field, card)
+      columnsMap.set(card.field.toLowerCase(), card)
     })
 
     let items = []
     if (type === 'search') {
       config.search.forEach(item => {
-        if (columnsMap.has(item.field)) {
-          let cell = columnsMap.get(item.field)
+        if (columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
 
           if (cell.selected && cell.type === item.type) { // 鏁版嵁鏈慨鏀�
             items.push(item)
@@ -110,7 +133,7 @@
             item.initval = ''
             items.push(item)
           }
-          columnsMap.delete(item.field)
+          columnsMap.delete(item.field.toLowerCase())
         } else if (!item.origin) {
           items.push(item)
         }
@@ -139,11 +162,6 @@
             resourceType: '0',
             setAll: 'false',
             options: [],
-            dataSource: '',
-            linkField: '',
-            valueField: '',
-            valueText: '',
-            orderBy: '',
             orderType: 'asc',
             match: _match,
             display: 'dropdown'
@@ -152,15 +170,16 @@
           items.push(newcard)
         }
       })
+      config.search = items
     } else if (type === 'columns') {
       config.columns.forEach(item => {
-        if (columnsMap.has(item.field)) {
-          let cell = columnsMap.get(item.field)
+        if (columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
 
           if (cell.selected) {
             items.push(item)
           }
-          columnsMap.delete(item.field)
+          columnsMap.delete(item.field.toLowerCase())
         } else if (!item.origin) {
           items.push(item)
         }
@@ -181,21 +200,143 @@
             Width: 120
           }
 
+          if (item.type === 'number') {
+            newcard.decimal = item.decimal
+          } else {
+            newcard.fieldlength = item.length || 50
+          }
+
           items.push(newcard)
         }
       })
+      config.columns = items
+    } else if (type === 'fields') {
+      config.columns.forEach(item => {
+        if (columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
+
+          if (cell.selected) {
+            items.push(item)
+          }
+          columnsMap.delete(item.field.toLowerCase())
+        } else {
+          items.push(item)
+        }
+      })
+
+      let _columns = [...columnsMap.values()]
+
+      _columns.forEach(item => {
+        if (item.selected) {
+          let newcard = {
+            uuid: Utils.getuuid(),
+            label: item.label,
+            field: item.field,
+            datatype: item.type === 'number' ? 'Decimal(18,0)' : 'Nvarchar(50)'
+          }
+
+          items.push(newcard)
+        }
+      })
+    } else if (type === 'form') {
+      if (config.groups.length > 1) {
+        config.groups.forEach(group => {
+          let _items = []
+          group.sublist.forEach(item => {
+            if (columnsMap.has(item.field.toLowerCase())) {
+              let cell = columnsMap.get(item.field.toLowerCase())
+      
+              if (cell.selected && cell.type === item.type) { // 鏁版嵁閫夋嫨鐘舵�佸強绫诲瀷鏈慨鏀规椂锛岀洿鎺ユ坊鍔�
+                _items.push(item)
+              } else if (cell.selected) {                     // 鏁版嵁绫诲瀷淇敼鏃讹紝閲嶇疆绫诲瀷鍙婂垵濮嬪��
+                item.type = cell.type
+                item.initval = ''
+                _items.push(item)
+              }
+              columnsMap.delete(item.field.toLowerCase())
+            } else if (!item.origin) {                        // 杩囨护绀轰緥椤�
+              _items.push(item)
+            }
+          })
+          group.sublist = _items
+        })
+        
+        let _columns = [...columnsMap.values()]
+    
+        let _additems = _columns.map(item => { // 寰幆娣诲姞鏂板瀛楁
+          return {
+            uuid: Utils.getuuid(),
+            label: item.label,
+            field: item.field,
+            initval: '',
+            type: item.type,
+            resourceType: '0',
+            setAll: 'false',
+            options: [],
+            dataSource: '',
+            orderType: 'asc',
+            decimal: item.decimal,
+            readonly: 'false',
+            required: 'true'
+          }
+        })
+        config.groups[config.groups.length - 1].sublist = [...config.groups.slice(-1)[0].sublist, ..._additems]
+      } else {
+        config.fields.forEach(item => {
+          if (columnsMap.has(item.field.toLowerCase())) {
+            let cell = columnsMap.get(item.field.toLowerCase())
+    
+            if (cell.selected && cell.type === item.type) { // 鏁版嵁閫夋嫨鐘舵�佸強绫诲瀷鏈慨鏀规椂锛岀洿鎺ユ坊鍔�
+              items.push(item)
+            } else if (cell.selected) {                     // 鏁版嵁绫诲瀷淇敼鏃讹紝閲嶇疆绫诲瀷鍙婂垵濮嬪��
+              item.type = cell.type
+              item.initval = ''
+              items.push(item)
+            }
+            columnsMap.delete(item.field.toLowerCase())
+          } else if (!item.origin) {                        // 杩囨护绀轰緥椤�
+            items.push(item)
+          }
+        })
+    
+        let _columns = [...columnsMap.values()]
+    
+        _columns.forEach(item => { // 寰幆娣诲姞鏂板瀛楁
+          if (item.selected) {
+            let newcard = {
+              uuid: Utils.getuuid(),
+              label: item.label,
+              field: item.field,
+              initval: '',
+              type: item.type,
+              resourceType: '0',
+              setAll: 'false',
+              options: [],
+              dataSource: '',
+              decimal: item.decimal,
+              orderType: 'asc',
+              readonly: 'false',
+              required: 'true'
+            }
+    
+            items.push(newcard)
+          }
+        })
+    
+        config.fields = items
+      }
     }
 
-    let _config = null
+    if (type === 'search' || type === 'columns' || type === 'form') {
+      this.props.updatefield(config)
 
-    if (type === 'search') {
-      _config = {...this.props.config, search: items}
-    } else if (type === 'columns') {
-      _config = {...this.props.config, columns: items}
-    }
-
-    if (_config) {
-      this.props.updatefield(_config)
+      notification.success({
+        top: 92,
+        message: '鎿嶄綔鎴愬姛',
+        duration: 2
+      })
+    } else if (type === 'fields') {
+      this.props.updatefield(items)
 
       notification.success({
         top: 92,
@@ -205,21 +346,26 @@
     }
   }
 
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+  }
 
   render() {
     const { type } = this.props
     const { dict, fields } = this.state
 
-    let label = ''
-    if (type === 'search') {
-      label = dict['header.menu.search.add']
-    } else if (type === 'columns') {
-      label = dict['header.menu.column.add']
-    }
-
     return (
-      <div>
-        <Button type="primary" block onClick={this.queryField}>{label}</Button>
+      <div className="quickly-add">
+        <Button type="primary" block onClick={this.queryField}>{dict['model.batchAdd']}</Button>
         {/* 鏍规嵁瀛楁鍚嶆坊鍔犳樉绀哄垪鍙婃悳绱㈡潯浠� */}
         <Modal
           wrapClassName="model-table-fieldmanage-modal"
@@ -228,7 +374,7 @@
           width={'65vw'}
           maskClosable={false}
           style={{minWidth: '900px', maxWidth: '1200px'}}
-          cancelText={dict['header.close']}
+          cancelText={dict['model.close']}
           onOk={this.addFieldSubmit}
           onCancel={() => { // 鍙栨秷娣诲姞
             this.setState({

--
Gitblit v1.8.0