From bc4ee6130db80f8f2020bb3bb7248b6e55ae90cc Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 20 三月 2020 17:47:01 +0800
Subject: [PATCH] 2020-03-20

---
 src/tabviews/zshare/topSearch/index.jsx |  139 +++++++++++++++++++++++++++++-----------------
 1 files changed, 87 insertions(+), 52 deletions(-)

diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index 3107b87..8c1adb4 100644
--- a/src/tabviews/zshare/topSearch/index.jsx
+++ b/src/tabviews/zshare/topSearch/index.jsx
@@ -15,15 +15,19 @@
 
   state = {
     match: null,            // 鎼滅储鏉′欢鍖归厤瑙勫垯
-    style: null,
-    searchlist: null,
-    formId: Utils.getuuid()
+    style: null,            // 鎼滅储鏉′欢绫诲瀷
+    label: null,            // 鎻愮ず鏂囧瓧
+    required: null,         // 鏄惁蹇呭~
+    searchlist: null,       // 鎼滅储椤�
+    formId: Utils.getuuid() // 鎼滅储琛ㄥ崟Id
   }
 
   UNSAFE_componentWillMount () {
     let searchlist = JSON.parse(JSON.stringify(this.props.searchlist))
     let match = {}
+    let label = {}
     let style = {}
+    let required = {}
     let _list = []
     let fieldMap = new Map()
 
@@ -34,7 +38,9 @@
       fieldMap.set(item.field, true)
 
       match[item.field] = item.match
+      label[item.field] = item.label
       style[item.field] = item.type
+      required[item.field] = item.required === 'true'
 
       if (item.type === 'select' || item.type === 'link') {
         item.oriOptions = JSON.parse(JSON.stringify(item.options))
@@ -63,7 +69,9 @@
 
     this.setState({
       match: match,
+      label: label,
       style: style,
+      required: required,
       searchlist: _list
     })
   }
@@ -174,7 +182,15 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: item.initval })(<Input placeholder="" autoComplete="off" />)}
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.input'] + item.label + '!'
+                  }
+                ]
+              })(<Input placeholder="" autoComplete="off" />)}
             </Form.Item>
           </Col>
         )
@@ -182,7 +198,15 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: item.initval })(
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.select'] + item.label + '!'
+                  }
+                ]
+              })(
                 <Select
                   showSearch
                   onChange={(value) => {this.selectChange(item, value)}}
@@ -202,11 +226,18 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: _initval })(
+              {getFieldDecorator(item.field, {
+                initialValue: _initval,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.select'] + item.label + '!'
+                  }
+                ]
+              })(
                 <Select
                   showSearch
                   mode="multiple"
-                  // onChange={(value) => {this.selectChange(item, value)}}
                   filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                   getPopupContainer={() => document.getElementById(this.state.formId)}
                 >
@@ -222,7 +253,15 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval, 'days') : null })(
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval ? moment().subtract(item.initval, 'days') : null,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.select'] + item.label + '!'
+                  }
+                ]
+              })(
                 <DatePicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
               )}
             </Form.Item>
@@ -232,7 +271,15 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval, 'month') : null })(
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval ? moment().subtract(item.initval, 'month') : null,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.select'] + item.label + '!'
+                  }
+                ]
+              })(
                 <MonthPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
               )}
             </Form.Item>
@@ -242,7 +289,15 @@
         fields.push(
           <Col span={item.ratio || 6} key={index}>
             <Form.Item label={item.label}>
-              {getFieldDecorator(item.field, {initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null })(
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval ? moment().subtract(item.initval * 7, 'days') : null,
+                rules: [
+                  {
+                    required: item.required === 'true',
+                    message: this.props.dict['form.required.select'] + item.label + '!'
+                  }
+                ]
+              })(
                 <WeekPicker onChange={this.searchChange} getCalendarContainer={() => document.getElementById(this.state.formId)} />
               )}
             </Form.Item>
@@ -265,7 +320,13 @@
             <Form.Item label={item.label}>
               {getFieldDecorator(item.field,
                 {
-                  initialValue: _defaultValue
+                  initialValue: _defaultValue,
+                  rules: [
+                    {
+                      required: item.required === 'true',
+                      message: this.props.dict['form.required.select'] + item.label + '!'
+                    }
+                  ]
                 })(
                 <RangePicker
                   placeholder={['寮�濮嬫棩鏈�', '缁撴潫鏃ユ湡']}
@@ -282,7 +343,7 @@
 
     fields.push(
       <Col span={6} style={{ whiteSpace: 'nowrap' }} key="actions">
-        <Form.Item label={' '} colon={false}>
+        <Form.Item label={' '} colon={false} style={{ minHeight: '40px' }}>
           <Button type="primary" htmlType="submit">
             {this.props.dict['main.search']}
           </Button>
@@ -327,65 +388,39 @@
     // 鑾峰彇鎼滅储鏉′欢鍊�
     let search = []
     Object.keys(values).forEach(key => {
+      let _value = ''
       if (this.state.style[key] === 'daterange') {
-        let _value = ''
         if (values[key].length > 0) {
           _value = [moment(values[key][0]).format('YYYY-MM-DD'), moment(values[key][1]).format('YYYY-MM-DD')]
         }
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: _value,
-          match: this.state.match[key]
-        })
       } else if (this.state.style[key] === 'dateweek') {
-        let _value = ''
         if (values[key]) {
           _value = [moment(values[key]).startOf('week').format('YYYY-MM-DD'), moment(values[key]).endOf('week').format('YYYY-MM-DD')]
         }
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: _value,
-          match: this.state.match[key]
-        })
       } else if (this.state.style[key] === 'date') {
-        let _value = ''
         if (values[key]) {
           _value = moment(values[key]).format('YYYY-MM-DD')
         }
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: _value,
-          match: this.state.match[key]
-        })
       } else if (this.state.style[key] === 'datemonth') {
-        let _value = ''
         if (values[key]) {
           _value = moment(values[key]).format('YYYY-MM')
         }
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: _value,
-          match: this.state.match[key]
-        })
       } else if (this.state.style[key] === 'multiselect') {
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: values[key],
-          match: this.state.match[key]
-        })
+        _value = values[key]
+
       } else {
-        search.push({
-          type: this.state.style[key],
-          key: key.replace(/@tail@$/, ''),
-          value: values[key].replace(/(^\s*|\s*$)/ig, ''),
-          match: this.state.match[key]
-        })
+        _value = values[key].replace(/(^\s*|\s*$)/ig, '')
+
       }
+
+      search.push({
+        type: this.state.style[key],
+        key: key.replace(/@tail@$/, ''),
+        value: _value,
+        label: this.state.label[key],
+        match: this.state.match[key],
+        required: this.state.required[key]
+      })
     })
     return search
   }

--
Gitblit v1.8.0