From 7449eee8fa9f8a251e9c4e9162030f1e004bae0f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 15 十月 2020 09:17:04 +0800
Subject: [PATCH] 2020-10-15

---
 src/templates/zshare/modalform/index.jsx |  191 ++++++++++++++++++++++-------------------------
 1 files changed, 88 insertions(+), 103 deletions(-)

diff --git a/src/templates/zshare/modalform/index.jsx b/src/templates/zshare/modalform/index.jsx
index bcc8328..689c1f2 100644
--- a/src/templates/zshare/modalform/index.jsx
+++ b/src/templates/zshare/modalform/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, InputNumber, Tooltip } from 'antd'
 import { formRule } from '@/utils/option.js'
 import { dateOptions } from '@/utils/option.js'
@@ -9,25 +10,28 @@
 import './index.scss'
 
 const modalTypeOptions = {
-  text: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'fieldlength', 'regular', 'interception', 'writein'],
-  number: ['label', 'field', 'initval', 'type', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'blacklist', 'writein'],
-  select: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'resourceType', 'setAll', 'linkSubField', 'writein'],
-  multiselect: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'resourceType', 'fieldlength', 'writein'],
-  link: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'resourceType', 'setAll', 'linkField', 'writein'],
-  fileupload: ['label', 'field', 'type', 'readonly', 'required', 'readin', 'fieldlength', 'blacklist', 'maxfile', 'fileType', 'writein'],
-  date: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'writein'],
-  datemonth: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'writein'],
-  datetime: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'writein'],
-  textarea: ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin', 'blacklist', 'fieldlength', 'maxRows', 'encryption', 'interception', 'writein'],
-  color: ['label', 'field', 'type', 'blacklist', 'readonly', 'required', 'hidden', 'readin', 'writein'],
-  funcvar: ['label', 'field', 'type', 'blacklist', 'hidden', 'writein'],
-  linkMain: ['label', 'field', 'type', 'readonly', 'required', 'hidden', 'fieldlength', 'blacklist', 'writein']
+  text: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'regular', 'interception', 'entireLine'],
+  number: ['initval', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin', 'entireLine'],
+  select: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkSubField', 'entireLine'],
+  checkbox: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'entireLine'],
+  radio: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'entireLine'],
+  checkcard: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'linkSubField', 'display'],
+  multiselect: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'fieldlength', 'entireLine'],
+  link: ['initval', 'readonly', 'required', 'hidden', 'readin', 'resourceType', 'setAll', 'linkField', 'entireLine'],
+  fileupload: ['readonly', 'required', 'readin', 'fieldlength', 'maxfile', 'fileType', 'entireLine'],
+  switch: ['initval', 'openVal', 'closeVal', 'readonly', 'required', 'hidden', 'readin', 'entireLine'],
+  date: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine'],
+  datemonth: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine'],
+  datetime: ['initval', 'readonly', 'required', 'hidden', 'readin', 'entireLine'],
+  textarea: ['initval', 'readonly', 'required', 'hidden', 'readin', 'fieldlength', 'maxRows', 'encryption', 'interception'],
+  color: ['readonly', 'required', 'hidden', 'readin', 'entireLine'],
+  funcvar: ['hidden'],
+  linkMain: ['readonly', 'required', 'hidden', 'fieldlength', 'entireLine']
 }
 
 class MainSearch extends Component {
   static propTpyes = {
     dict: PropTypes.object,    // 瀛楀吀椤�
-    optionLibs: PropTypes.any, // 鑷畾涔変笅鎷夐泦
     formlist: PropTypes.any,
     card: PropTypes.object,
     inputSubmit: PropTypes.any
@@ -42,8 +46,7 @@
   }
 
   UNSAFE_componentWillMount () {
-    const { optionLibs } = this.props
-    let formlist = JSON.parse(JSON.stringify(this.props.formlist))
+    let formlist = fromJS(this.props.formlist).toJS()
 
     let type = ''
     let resourceType = ''
@@ -70,21 +73,7 @@
       }
     })
     
-    let _options = JSON.parse(JSON.stringify(modalTypeOptions[type]))
-
-    if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
-      _options = [..._options, 'options', 'quick']
-    } else if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '1') { // 閫夋嫨绫诲瀷銆佹暟鎹簮
-      _options = [..._options, 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database']
-    }
-
-    if (type !== 'funcvar' && type !== 'linkMain') {
-      if (supField) {
-        _options.push('supField', 'supvalue')
-      } else {
-        _options.push('supField')
-      }
-    }
+    let _options = this.getOptions(type, resourceType, supField)
 
     this.setState({
       openType: type,
@@ -95,17 +84,17 @@
         if (dateOptions.hasOwnProperty(type) && form.key === 'initval') {
           form.options = dateOptions[type]
           form.type = 'select'
+        } else if (type === 'switch' && form.key === 'initval') {
+          form.initVal = !!form.initVal
+          form.options = [
+            {value: true, text: '寮�'},
+            {value: false, text: '鍏�'}
+          ]
+          form.type = 'radio'
         } else if (type === 'number' && form.key === 'initval') {
           form.type = 'number'
           form.initVal = form.initVal || 0
           form.required = true
-        } else if (form.key === 'quick') {
-          form.options = [...optionLibs.values()].map(cell => {
-            return {
-              value: cell.uuid,
-              text: cell.label + '(' + cell.parname + ')'
-            }
-          })
         }
 
         form.show = _options.includes(form.key)
@@ -127,24 +116,31 @@
     }
   }
 
-  openTypeChange = (key, value) => {
-    if (key === 'type') {
-      let _options = JSON.parse(JSON.stringify(modalTypeOptions[value]))
+  getOptions = (type, resourceType, supField) => {
+    let _options = ['label', 'field', 'type', 'blacklist', 'writein', ...fromJS(modalTypeOptions[type]).toJS()]
 
-      if ((value === 'multiselect' || value === 'select' || value === 'link') && this.state.resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
-        _options = [..._options, 'options', 'quick']
-      } else if ((value === 'multiselect' || value === 'select' || value === 'link') && this.state.resourceType === '1') { // 閫夋嫨绫诲瀷銆佹暟鎹簮
+    if (['multiselect', 'select', 'link', 'radio', 'checkbox', 'checkcard'].includes(type)) {
+      if (resourceType === '0') {        // 鑷畾涔夎祫婧�
+        _options = [..._options, 'options']
+      } else if (resourceType === '1') { // 鏁版嵁婧�
         _options = [..._options, 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database']
       }
+    }
 
-      if (value !== 'funcvar' && value !== 'linkMain') {
-        if (this.state.supField) {
-          _options.push('supField', 'supvalue')
-        } else {
-          _options.push('supField')
-        }
+    if (type !== 'funcvar' && type !== 'linkMain') {
+      if (supField) {
+        _options.push('supField', 'supvalue')
+      } else {
+        _options.push('supField')
       }
+    }
 
+    return _options
+  }
+
+  openTypeChange = (key, value) => {
+    if (key === 'type') {
+      let _options = this.getOptions(value, this.state.resourceType, this.state.supField)
       let fieldValue = {}
       
       this.setState({
@@ -157,6 +153,13 @@
             if (dateOptions.hasOwnProperty(value)) {
               form.options = dateOptions[value]
               form.type = 'select'
+            } else if (value === 'switch') {
+              form.initVal = false
+              form.options = [
+                {value: true, text: '寮�'},
+                {value: false, text: '鍏�'}
+              ]
+              form.type = 'radio'
             } else if (value === 'number') {
               form.type = 'number'
               form.required = true
@@ -170,7 +173,7 @@
             }
           } else if (form.key === 'fieldlength') {
             form.initVal = 50
-            if (value === 'textarea' || value === 'fileupload' || value === 'multiselect') {
+            if (value === 'textarea' || value === 'fileupload' || value === 'multiselect' || value === 'checkbox') {
               form.initVal = 512
             }
 
@@ -194,18 +197,6 @@
         })
       }, () => {
         this.props.form.setFieldsValue(fieldValue)
-      })
-    } else if (key === 'quick') {
-      let option = this.props.optionLibs.get(value)
-
-      this.setState({
-        formlist: this.state.formlist.map(form => {
-          if (form.key === 'options') {
-            form.initVal = option.options
-          }
-
-          return form
-        })
       })
     } else if (key === 'supField') {
       this.setState({
@@ -249,22 +240,8 @@
     const { openType } = this.state
     let value = e.target.value
     if (key === 'resourceType') {
-      let _options = JSON.parse(JSON.stringify(modalTypeOptions[openType]))
-
-      if (value === '0') {
-        _options = [..._options, 'options', 'quick']
-      } else if (value === '1') {
-        _options = [..._options, 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database']
-      }
-
-      if (openType !== 'funcvar' && openType !== 'linkMain') {
-        if (this.state.supField) {
-          _options.push('supField', 'supvalue')
-        } else {
-          _options.push('supField')
-        }
-      }
-
+      let _options = this.getOptions(openType, value, this.state.supField)
+      
       this.setState({
         resourceType: value,
         formlist: this.state.formlist.map(form => {
@@ -500,7 +477,12 @@
       } else if (item.type === 'options') {
         fields.push(
           <Col span={20} offset={4} key={index}>
-            <EditTable data={item.initVal} dict={this.props.dict} type={this.state.openType} linkSubFields={this.state.linkSubFields} ref="editTable"/>
+            <Form.Item className="text-area">
+              {getFieldDecorator(item.key, {
+                initialValue: item.initVal
+              })(<EditTable dict={this.props.dict} type={this.state.openType} linkSubFields={this.state.linkSubFields}/>)}
+            </Form.Item>
+            {/* <EditTable data={item.initVal} dict={this.props.dict} type={this.state.openType} linkSubFields={this.state.linkSubFields} ref="editTable"/> */}
           </Col>
         )
       }
@@ -514,38 +496,43 @@
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
-          let isvalid = true
           values.uuid = this.props.card.uuid
           // 涓嬫媺鑿滃崟鎴栬仈鍔ㄨ彍鍗�
-          if ((values.type === 'multiselect' || values.type === 'select' || values.type === 'link') && values.resourceType === '0') {
-            values.options = this.refs.editTable.state.dataSource
-            values.dataSource = ''
-            let emptys = []
-            if (values.type === 'multiselect' || values.type === 'select') {
-              emptys = values.options.filter(op => !((op.Value || op.Value === 0) && (op.Text || op.Text === 0)))
-            } else {
-              emptys = values.options.filter(op => !((op.Value || op.Value === 0) && (op.Text || op.Text === 0) && (op.ParentID || op.ParentID === 0)))
-            }
-            if (emptys.length > 0) {
-              isvalid = false
-              notification.warning({
-                top: 92,
-                message: this.props.dict['model.form.selectItem.error'],
-                duration: 5
+          if (['multiselect', 'select', 'link', 'radio', 'checkbox'].includes(values.type)) {
+            if (values.resourceType === '0') {
+              values.options = values.options || []
+              values.dataSource = ''
+              let empty = false
+
+              values.options.forEach(op => {
+                if (!((op.Value || op.Value === 0) && (op.Text || op.Text === 0))) {
+                  empty = true
+                } else if (values.type === 'link' && !(op.ParentID || op.ParentID === 0)) {
+                  empty = true
+                }
               })
+
+              if (empty) {
+                notification.warning({
+                  top: 92,
+                  message: this.props.dict['model.form.selectItem.error'],
+                  duration: 5
+                })
+                return
+              }
+            } else {
+              values.options = []
             }
-          } else if ((values.type === 'multiselect' || values.type === 'select' || values.type === 'link') && values.resourceType === '1') {
-            values.options = []
           } else if (values.type === 'funcvar') { // 鍑芥暟鍙橀噺涓哄彧璇诲厓绱�
             values.readonly = 'true'
           } else if (values.type === 'number' && (values.min || values.min === 0) && (values.max || values.max === 0)) { // 鏁板�煎瀷楠岃瘉鏈�灏忔渶澶у��
             if (values.min > values.max) {
-              isvalid = false
               notification.warning({
                 top: 92,
                 message: '鏈�灏忓�间笉鍙ぇ浜庢渶澶у�硷紒',
                 duration: 5
               })
+              return
             }
           } else if (values.type === 'linkMain') {
             values.initval = ''
@@ -553,7 +540,7 @@
 
           ['linkField', 'valueField', 'valueText', 'orderBy'].forEach(item => {
             if (values[item]) {
-              values[item] = values[item].replace(/\s* | \t* | \v* | \r*/ig, '')
+              values[item] = values[item].replace(/\s*|\t*|\v*|\r*/ig, '')
             }
           })
 
@@ -568,9 +555,7 @@
             return
           }
 
-          if (isvalid) {
-            resolve(values)
-          }
+          resolve(values)
         } else {
           reject(err)
         }

--
Gitblit v1.8.0