From b70376bd370f83e0087e629b664243f3a4bf191c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 10 二月 2020 02:35:33 +0800
Subject: [PATCH] 2020-02-10

---
 src/templates/ushare/modalform/index.jsx |   47 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/templates/ushare/modalform/index.jsx b/src/templates/ushare/modalform/index.jsx
index eeafd26..7eb8e38 100644
--- a/src/templates/ushare/modalform/index.jsx
+++ b/src/templates/ushare/modalform/index.jsx
@@ -18,14 +18,35 @@
   state = {
     openType: null,
     resourceType: null,
-    formlist: null
+    formlist: null,
+    linkSubFields: null
   }
 
   UNSAFE_componentWillMount () {
     let formlist = JSON.parse(JSON.stringify(this.props.formlist))
 
-    let type = formlist.filter(cell => cell.key === 'type')[0].initVal
-    let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal
+    let type = ''
+    let resourceType = ''
+    let linkSubFields = []
+
+    formlist.forEach(cell => {
+      if (cell.key === 'type') {
+        type = cell.initVal
+      } else if (cell.key === 'resourceType') {
+        resourceType = cell.initVal
+      } else if (cell.key === 'linkSubField') {
+        let arr = []
+        linkSubFields = cell.options.filter(option => {
+          if (!['Value', 'Text'].includes(option.field) && cell.initVal.includes(option.field) && !arr.includes(option.field)) {
+            arr.push(option.field)
+            return true
+          } else {
+            return false
+          }
+        })
+      }
+    })
+    
     let _options = ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin'] // 榛樿鏄剧ず椤�
 
     if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
@@ -51,10 +72,11 @@
     } else if (type === 'linkMain') {
       _options = ['label', 'field', 'type', 'readonly', 'required', 'hidden', 'fieldlength']
     }
-    
+
     this.setState({
       openType: type,
       resourceType: resourceType,
+      linkSubFields: linkSubFields,
       formlist: formlist.map(form => {
         if (dateOptions.hasOwnProperty(type) && form.key === 'initval') {
           form.options = dateOptions[type]
@@ -137,6 +159,8 @@
             form.show = false
           } else if (form.key === 'resourceType') {
             form.initVal = this.state.resourceType
+          } else if (form.key === 'linkSubField') {
+            form.initVal = this.state.linkSubFields.map(_field => _field.field)
           }
           return form
         })
@@ -157,11 +181,18 @@
 
   multiselectChange = (key, value, options) => {
     if (key === 'linkSubField') {
+      let arr = []
+      let linkSubFields = options.filter(option => {
+        if (!['Value', 'Text'].includes(option.field) && value.includes(option.field) && !arr.includes(option.field)) {
+          arr.push(option.field)
+          return true
+        } else {
+          return false
+        }
+      })
 
+      this.setState({linkSubFields: linkSubFields})
     }
-    console.log(key)
-    console.log(value)
-    console.log(options)
   }
 
   onChange = (e, key) => {
@@ -384,7 +415,7 @@
       } else if (item.type === 'options') {
         fields.push(
           <Col span={20} offset={4} key={index}>
-            <EditTable data={item.initVal} type={this.state.openType} ref="editTable"/>
+            <EditTable data={item.initVal} type={this.state.openType} linkSubFields={this.state.linkSubFields} ref="editTable"/>
           </Col>
         )
       }

--
Gitblit v1.8.0