From cf804e19634ff953bb132af1b2f46905d80c1e3a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 12 五月 2021 15:08:34 +0800
Subject: [PATCH] 2021-05-12

---
 src/templates/sharecomponent/searchcomponent/searchform/index.jsx |   77 ++++++++++++++------------------------
 1 files changed, 28 insertions(+), 49 deletions(-)

diff --git a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
index 843331c..9918283 100644
--- a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
+++ b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx
@@ -1,5 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
+import { fromJS } from 'immutable'
 import { Form, Row, Col, Input, Select, Icon, Radio, notification, Tooltip, InputNumber, Checkbox, Cascader } from 'antd'
 import { dateOptions, matchReg, formRule } from '@/utils/option.js'
 import EditTable from '../searcheditable'
@@ -80,6 +81,18 @@
   },
 ]
 
+const searchTypeOptions = {
+  text: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  select: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll'],
+  multiselect: ['label', 'field', 'resourceType', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  link: ['label', 'field', 'resourceType', 'initval', 'type', 'linkField', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced', 'setAll'],
+  date: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  dateweek: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  datemonth: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  daterange: ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow', 'advanced'],
+  group: ['label', 'type', 'field', 'datefield', 'initval', 'blacklist', 'ratio', 'items', 'required', 'transfer', 'labelShow']
+}
+
 class MainSearch extends Component {
   static propTpyes = {
     dict: PropTypes.object,     // 瀛楀吀椤�
@@ -106,23 +119,8 @@
     let type = formlist.filter(cell => cell.key === 'type')[0].initVal
     let _items = formlist.filter(cell => cell.key === 'items')[0].initVal
     let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal
-    let _options = ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow']                // 榛樿鏄剧ず椤�
 
-    if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '0') {        // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓鸿嚜瀹氫箟璧勬簮
-      _options = [..._options, 'resourceType', 'options', 'display']
-    } else if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '1') { // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓哄悗鍙版暟鎹簮涓幏鍙�
-      _options = [..._options, 'resourceType', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display', 'database']
-    } else if (type === 'group') {
-      _options = ['label', 'type', 'field', 'datefield', 'initval', 'blacklist', 'ratio', 'items', 'required', 'transfer', 'labelShow']
-    }
-
-    if (type === 'select' || type === 'link') {
-      _options.push('setAll')
-    }
-
-    if (type === 'link') { // 鍏宠仈绫诲瀷銆佸鍔犲叧鑱斾笂绾х殑瀛楁鍚�
-      _options = [..._options, 'linkField']
-    }
+    let _options = this.getOptions(type, resourceType)
     
     this.setState({
       openType: type,
@@ -174,6 +172,18 @@
     }
   }
 
+  getOptions = (type, resourceType) => {
+    let _options = fromJS(searchTypeOptions[type]).toJS() // 閫夐」鍒楄〃
+    
+    if (['multiselect', 'select', 'link'].includes(type) && resourceType === '0') {        // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓鸿嚜瀹氫箟璧勬簮
+      _options.push('options')
+    } else if (['multiselect', 'select', 'link'].includes(type) && resourceType === '1') { // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓哄悗鍙版暟鎹簮涓幏鍙�
+      _options.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database')
+    }
+
+    return _options
+  }
+
   /**
    * @description 鎼滅储鏉′欢绫诲瀷鍒囨崲
    */
@@ -182,24 +192,7 @@
     const { resourceType, items } = this.state
 
     if (key === 'type') {
-      let _options = ['label', 'field', 'initval', 'type', 'match', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow']
-
-      if ((value === 'multiselect' || value === 'select' || value === 'link') && resourceType === '0') {        // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓鸿嚜瀹氫箟璧勬簮
-        _options = [..._options, 'resourceType', 'options', 'display']
-      } else if ((value === 'multiselect' || value === 'select' || value === 'link') && resourceType === '1') { // 涓嬫媺閫夋嫨绫诲瀷銆侀�夐」涓哄悗鍙版暟鎹簮涓幏鍙�
-        _options = [..._options, 'resourceType', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'display', 'database']
-      } else if (value === 'group') {
-        _options = ['label', 'type', 'field', 'datefield', 'initval', 'items', 'ratio', 'blacklist', 'required', 'transfer', 'labelShow']
-      }
-
-      if (value === 'select' || value === 'link') {
-        _options.push('setAll')
-      }
-      
-      if (value === 'link') {
-        _options = [..._options, 'linkField']
-      }
-
+      let _options = this.getOptions(value, resourceType)
       let matchs = []
 
       this.setState({
@@ -263,22 +256,8 @@
     let value = e.target.value
 
     if (key === 'resourceType') {
-      let _options = ['label', 'field', 'initval', 'type', 'match', 'resourceType', 'display', 'ratio', 'blacklist', 'required', 'Hide', 'labelShow']
+      let _options = this.getOptions(openType, value)
 
-      if (value === '0') {
-        _options = [..._options, 'options']
-      } else if (value === '1') {
-        _options = [..._options, 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database']
-      }
-
-      if (openType === 'select' || openType === 'link') {
-        _options.push('setAll')
-      }
-      
-      if (openType === 'link') {
-        _options = [..._options, 'linkField']
-      }
-      
       this.setState({
         resourceType: value,
         formlist: this.state.formlist.map(form => {

--
Gitblit v1.8.0