From a8ed3be8ef5cee0d3b0486fb6412c2d352df4af0 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 28 一月 2022 17:00:12 +0800
Subject: [PATCH] 2022-01-28

---
 src/tabviews/zshare/mutilform/index.jsx |  119 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 86 insertions(+), 33 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx
index 9c61db0..afb7b41 100644
--- a/src/tabviews/zshare/mutilform/index.jsx
+++ b/src/tabviews/zshare/mutilform/index.jsx
@@ -314,6 +314,8 @@
       fieldMap.set(key, supItem)
     })
 
+    let reFieldsVal = null
+
     formlist = formlist.map(cell => {
       if (cell.labelwidth) {
         cell.labelCol = {style: {width: cell.labelwidth + '%'}}
@@ -321,6 +323,34 @@
       }
       if (!cell.field || !fieldMap.has(cell.field)) return cell
       let item = fieldMap.get(cell.field)
+
+      // 涓嬬骇琛ㄥ崟鎺у埗-瀛楁鍐欏叆
+      if ((['select', 'radio', 'link'].includes(item.type) || (item.type === 'checkcard' && item.multiple !== 'true')) && item.linkSubField) {
+        item.subFields = []
+        item.linkSubField.forEach(m => {
+          let n = fieldMap.get(m)
+          if (n && ['text', 'number', 'textarea'].includes(n.type)) {
+            item.subFields.push({
+              uuid: n.uuid,
+              field: m
+            })
+          }
+        })
+
+        if (item.subFields.length === 0) {
+          item.subFields = null
+        } else if (item.oriOptions.length > 0) {
+          item.oriOptions = item.oriOptions.map(cell => {
+            item.subFields.forEach(m => {
+              cell[m.field] = cell[m.field] === undefined ? '' : cell[m.field]
+            })
+            return cell
+          })
+          
+          item.options = fromJS(item.oriOptions).toJS()
+        }
+        item.linkSubField = null
+      }
 
       // if (item.type === 'link') {
       if (item.linkField) {
@@ -350,35 +380,7 @@
       if (linkFields[item.field]) {
         item.linkFields = linkFields[item.field]
       }
-
-      // 涓嬬骇琛ㄥ崟鎺у埗-瀛楁鍐欏叆
-      if ((['select', 'radio', 'link'].includes(item.type) || (item.type === 'checkcard' && item.multiple !== 'true')) && item.linkSubField) {
-        item.subFields = []
-        item.linkSubField.forEach(m => {
-          let n = fieldMap.get(m)
-          if (n && ['text', 'number', 'textarea'].includes(n.type)) {
-            item.subFields.push({
-              uuid: n.uuid,
-              field: m
-            })
-          }
-        })
-
-        if (item.subFields.length === 0) {
-          item.subFields = null
-        } else if (item.options.length > 0) {
-          item.options = item.options.map(cell => {
-            item.subFields.forEach(m => {
-              cell[m.field] = cell[m.field] === undefined ? '' : cell[m.field]
-            })
-            return cell
-          })
-          
-          item.oriOptions = fromJS(item.options).toJS()
-        }
-        item.linkSubField = null
-      }
-
+      
       if (item.enter === 'tab' || item.enter === 'sub') {
         if (fieldMap.has(item.tabField)) {
           item.tabUuid = fieldMap.get(item.tabField).uuid
@@ -388,9 +390,32 @@
           item.tabUuid = item.uuid
         }
       }
+
+      if (item.subFields && item.options.length > 0) {
+        // eslint-disable-next-line
+        let option = item.options.filter(cell => item.initval == cell.value)[0]
+
+        if (option) {
+          reFieldsVal = reFieldsVal || {}
+          item.subFields.forEach(n => {
+            reFieldsVal[n.field] = option[n.field]
+          })
+        }
+      }
       
       return item
     })
+
+    if (reFieldsVal) {
+      formlist = formlist.map(cell => {
+        if (reFieldsVal[cell.field] === undefined) return cell
+
+        cell.initval = reFieldsVal[cell.field]
+        record[cell.field] = reFieldsVal[cell.field]
+
+        return cell
+      })
+    }
 
     this.record = record
 
@@ -576,6 +601,7 @@
   }
 
   resetFormList = (result) => {
+    let reFieldsVal = null
     let _formlist = fromJS(this.state.formlist).toJS().map(item => {
       if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
         let options = []
@@ -616,16 +642,43 @@
         } else {
           item.options = item.oriOptions
         }
-      }
 
-      if (['select', 'link', 'radio'].includes(item.type) && typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { // 閫変腑绗竴椤�
-        item.initval = item.options[0] ? item.options[0].value : ''
-        this.record[item.field] = item.initval
+        if (['select', 'link', 'radio'].includes(item.type) && typeof(item.initval) === 'string' && item.initval.indexOf('$first') > -1) { // 閫変腑绗竴椤�
+          item.initval = item.options[0] ? item.options[0].value : ''
+          this.record[item.field] = item.initval
+        }
+
+        if (item.subFields && item.options.length > 0) {
+          // eslint-disable-next-line
+          let option = item.options.filter(cell => item.initval == cell.value)[0]
+  
+          if (option) {
+            reFieldsVal = reFieldsVal || {}
+            item.subFields.forEach(n => {
+              reFieldsVal[n.field] = option[n.field]
+            })
+          }
+        }
       }
       
       return item
     })
 
+    if (reFieldsVal) {
+      _formlist = _formlist.map((cell, i) => {
+        if (reFieldsVal[cell.field] === undefined) return cell
+
+        cell.initval = reFieldsVal[cell.field]
+        this.record[cell.field] = reFieldsVal[cell.field]
+
+        setTimeout(() => {
+          MKEmitter.emit('mkFC', 'input', cell.uuid, reFieldsVal[cell.field])
+        }, i * 5)
+
+        return cell
+      })
+    }
+
     this.setState({
       formlist: _formlist
     })

--
Gitblit v1.8.0