From f9697383bc9097be8a444558e09ae21b27f1e831 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 31 十二月 2019 09:27:21 +0800
Subject: [PATCH] 2019-12-31

---
 src/tabviews/tableshare/topSearch/index.jsx |  131 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 128 insertions(+), 3 deletions(-)

diff --git a/src/tabviews/tableshare/topSearch/index.jsx b/src/tabviews/tableshare/topSearch/index.jsx
index 5a9c3e2..9c59994 100644
--- a/src/tabviews/tableshare/topSearch/index.jsx
+++ b/src/tabviews/tableshare/topSearch/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, Button, Select, DatePicker } from 'antd'
+import { Form, Row, Col, Input, Button, Select, DatePicker, notification } from 'antd'
 import moment from 'moment'
 import './index.scss'
 
@@ -19,12 +19,13 @@
   }
 
   UNSAFE_componentWillMount () {
+    let searchlist = JSON.parse(JSON.stringify(this.props.searchlist))
     let match = {}
     let style = {}
     let _list = []
     let fieldMap = new Map()
 
-    this.props.searchlist.forEach(item => {
+    searchlist.forEach(item => {
       if (fieldMap.has(item.field)) {
         item.field = item.field + '@tail@'
       }
@@ -33,13 +34,136 @@
       match[item.field] = item.match
       style[item.field] = item.type
 
+      if (item.type === 'select' || item.type === 'link') {
+        item.oriOptions = JSON.parse(JSON.stringify(item.options))
+      }
+
       _list.push(item)
     })
+
+    let error = false
+
+    _list = _list.map(item => {
+      if (item.type === 'link') {
+        let supItem = _list.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
+      })
+    }
 
     this.setState({
       match: match,
       style: style,
       searchlist: _list
+    })
+  }
+
+  UNSAFE_componentWillReceiveProps() {
+    let searchlist = JSON.parse(JSON.stringify(this.props.searchlist))
+    let _list = []
+    let fieldMap = new Map()
+
+    searchlist.forEach(item => {
+      if (fieldMap.has(item.field)) {
+        item.field = item.field + '@tail@'
+      }
+      fieldMap.set(item.field, true)
+
+      if (item.type === 'select' || item.type === 'link') {
+        item.oriOptions = JSON.parse(JSON.stringify(item.options))
+      }
+
+      _list.push(item)
+    })
+
+    _list = _list.map(item => {
+      if (item.type === 'link') {
+        let supItem = _list.filter(form => form.field === item.linkField)[0]
+        
+        if (supItem) {
+          item.options = item.oriOptions.filter(option => option.parentId === supItem.initval)
+        }
+      }
+
+      return item
+    })
+
+    this.setState({
+      searchlist: _list
+    })
+  }
+
+  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.searchlist))
+
+    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) {
+      this.searchChange()
+      return
+    }
+
+    formlist = this.resetform(formlist, subfields, 0)
+
+    this.setState({
+      searchlist: formlist
+    }, () => {
+      this.setState({
+        searchlist: formlist.map(item => {
+          item.hiden = false
+          return item
+        })
+      }, () => {
+        this.searchChange()
+      })
     })
   }
 
@@ -62,7 +186,8 @@
               {getFieldDecorator(item.field, {initialValue: item.initval })(
                 <Select
                   showSearch
-                  onChange={this.searchChange}
+                  // onChange={this.searchChange}
+                  onChange={(value) => {this.selectChange(item, value)}}
                   filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                 >
                   {item.options.map(option =>

--
Gitblit v1.8.0