From 977ce3d348f898d64ea240c8397b83d3e1cc5bb4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 18 十二月 2019 09:23:05 +0800
Subject: [PATCH] 2019-12-18

---
 src/tabviews/commontable/mutilform/index.jsx |  126 +++++++++++++++++++++++++++++++++++------
 1 files changed, 107 insertions(+), 19 deletions(-)

diff --git a/src/tabviews/commontable/mutilform/index.jsx b/src/tabviews/commontable/mutilform/index.jsx
index 9bf97eb..096534e 100644
--- a/src/tabviews/commontable/mutilform/index.jsx
+++ b/src/tabviews/commontable/mutilform/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, InputNumber, Select, DatePicker } from 'antd'
+import { Form, Row, Col, Input, InputNumber, Select, DatePicker, notification } from 'antd'
 import moment from 'moment'
 import Utils from '@/utils/utils.js'
 import './index.scss'
@@ -22,7 +22,8 @@
   }
 
   componentDidMount () {
-    const { action } = this.props
+    let action = JSON.parse(JSON.stringify(this.props.action))
+
     let datatype = {}
     let readtype = {}
     let formlist = []
@@ -49,22 +50,53 @@
         datatype[item.field] = item.type
         readtype[item.field] = item.readonly === 'true'
 
-        if (item.type === 'select' || item.type === 'link') {
-          if (item.setAll === 'true') {
-            item.options.unshift({
-              key: Utils.getuuid(),
-              Value: '',
-              Text: this.props.dict['main.all']
-            })
-          }
+        return item
+      })
+    }
 
-          if (item.resourceType === '1' && this.props.configMap.hasOwnProperty(item.uuid)) {
-            item.options = [...item.options, ...this.props.configMap[item.uuid]]
-          }
-          console.log(item)
+    formlist = formlist.map(item => {
+      if (item.type === 'select' || item.type === 'link') {
+        if (item.setAll === 'true') {
+          item.options.unshift({
+            key: Utils.getuuid(),
+            Value: '',
+            Text: this.props.dict['main.all']
+          })
         }
 
-        return item
+        if (item.resourceType === '1' && this.props.configMap.hasOwnProperty(item.uuid)) {
+          item.options = [...item.options, ...this.props.configMap[item.uuid]]
+        }
+
+        item.oriOptions = item.options
+      }
+
+      if (!/^date/.test(item.type) && this.props.data && this.props.data.hasOwnProperty(item.field)) {
+        item.initval = this.props.data[item.field]
+      }
+
+      return item
+    })
+
+    let error = false
+
+    formlist = formlist.map(item => {
+      if (item.type === 'link') {
+        let supItem = formlist.filter(form => form.field === item.linkField)[0]
+        if (!supItem) {
+          error = true
+        } else {
+          item.options = item.oriOptions.filter(option => option.parentId === supItem.initval)
+        }
+      }
+      return item
+    })
+
+    if (error) {
+      notification.warning({
+        top: 92,
+        message: '鍏宠仈鑿滃崟璁剧疆閿欒锛�',
+        duration: 10
       })
     }
 
@@ -72,6 +104,60 @@
       readtype: readtype,
       datatype: datatype,
       formlist: formlist
+    })
+  }
+
+  resetform = (formlist, supfields, index) => {
+    index++
+    let subfields = []
+
+    supfields.forEach(supfield => {
+      formlist = formlist.map(item => {
+        if (item.type === 'link' && item.linkField === supfield.field) {
+          item.options = item.oriOptions.filter(option => option.parentId === supfield.initval)
+          item.initval = item.options[0] ? item.options[0].Value : ''
+          item.hiden = true
+  
+          subfields.push(item)
+        }
+        return item
+      })
+    })
+
+    if (subfields.length === 0 || index > 6) {
+      return formlist
+    } else {
+      return this.resetform(formlist, subfields, index)
+    }
+  }
+
+  selectChange = (_field, value) => {
+    let formlist = JSON.parse(JSON.stringify(this.state.formlist))
+
+    let subfields = []
+    formlist = formlist.map(item => {
+      if (item.type === 'link' && item.linkField === _field.field) {
+        item.options = item.oriOptions.filter(option => option.parentId === value)
+        item.initval = item.options[0] ? item.options[0].Value : ''
+        item.hiden = true
+
+        subfields.push(item)
+      }
+      return item
+    })
+
+    if (subfields.length === 0) return
+
+    formlist = this.resetform(formlist, subfields, 0)
+    this.setState({
+      formlist: formlist
+    }, () => {
+      this.setState({
+        formlist: formlist.map(item => {
+          item.hiden = false
+          return item
+        })
+      })
     })
   }
 
@@ -88,7 +174,7 @@
     }
 
     this.state.formlist.forEach((item, index) => {
-      if (!item.field && item.type !== 'title') return
+      if ((!item.field && item.type !== 'title') || item.hiden) return
 
       if (item.type === 'title') {
         fields.push(
@@ -101,7 +187,7 @@
           <Col span={24 / cols} key={index}>
             <Form.Item label={item.label}>
               {getFieldDecorator(item.field, {
-                initialValue: this.props.data ? this.props.data[item.field] : item.initval,
+                initialValue: item.initval,
                 rules: [
                   {
                     required: item.required === 'true',
@@ -115,7 +201,7 @@
       } else if (item.type === 'number') { // 鏁板瓧
         let min = (item.min || item.min === 0) ? item.min : -Infinity
         let max = (item.max || item.max === 0) ? item.max : Infinity
-        let _initval = this.props.data ? this.props.data[item.field] : item.initval
+        let _initval = item.initval
         let precision = (item.decimal || item.decimal === 0) ? item.decimal : null
         
         fields.push(
@@ -142,7 +228,7 @@
           <Col span={24 / cols} key={index}>
             <Form.Item label={item.label}>
               {getFieldDecorator(item.field, {
-                initialValue: this.props.data ? this.props.data[item.field] : item.initval,
+                initialValue: item.initval,
                 rules: [
                   {
                     required: item.required === 'true',
@@ -153,6 +239,7 @@
                 <Select
                   showSearch
                   filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
+                  onChange={(value) => {this.selectChange(item, value)}}
                   // getPopupContainer={() => document.getElementById('form-box')}
                 >
                   {item.options.map(option =>
@@ -295,6 +382,7 @@
                 readonly: this.state.readtype[key],
                 key: key,
                 value: values[key].replace(/(^\s*|\s*$)/ig, '')
+                // value: values[key].replace(/[\x00-\xff]+/ig, '')
               })
             }
           })

--
Gitblit v1.8.0