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

---
 src/templates/modalconfig/modalform/index.jsx |  132 +++++++++++++++++++++++++++++--------------
 1 files changed, 88 insertions(+), 44 deletions(-)

diff --git a/src/templates/modalconfig/modalform/index.jsx b/src/templates/modalconfig/modalform/index.jsx
index 2583990..6a105dd 100644
--- a/src/templates/modalconfig/modalform/index.jsx
+++ b/src/templates/modalconfig/modalform/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, Select, Icon, Radio, notification } from 'antd'
+import { Form, Row, Col, Input, Select, Icon, Radio, notification, InputNumber } from 'antd'
 import EditTable from '../editable'
 import './index.scss'
 
@@ -19,17 +19,57 @@
     formlist: null,
     dateoptions: {
       date: [{value: '', text: '绌�'}, {value: '0', text: '褰撳ぉ'}, {value: 1, text: '鍓嶄竴澶�'}, {value: 3, text: '鍓嶄笁澶�'}, {value: 7, text: '鍓嶄竷澶�'}, {value: 30, text: '鍓�30澶�'}],
-      dateweek: [{value: '', text: '绌�'}, {value: '0', text: '鏈懆'}, {value: 1, text: '涓婂懆'}, {value: 3, text: '鍓嶄笁鍛�'}, {value: 7, text: '鍓嶄竷鍛�'}],
-      datemonth: [{value: '', text: '绌�'}, {value: '0', text: '鏈湀'}, {value: 1, text: '涓婃湀'}, {value: 3, text: '鍓嶄笁鏈�'}, {value: 7, text: '鍓嶄竷鏈�'}],
-      daterange: [{value: '', text: '绌�'}, {value: '0', text: '浠婂ぉ'}, {value: 1, text: '鏄ㄥぉ'}, {value: 3, text: '鍓嶄笁澶�'}, {value: 7, text: '鍓嶄竷澶�'}, {value: 30, text: '鍓�30澶�'}],
+      datemonth: [{value: '', text: '绌�'}, {value: '0', text: '鏈湀'}, {value: 1, text: '涓婃湀'}, {value: 3, text: '鍓嶄笁鏈�'}, {value: 6, text: '鍓嶅叚鏈�'}],
+      datetime: [{value: '', text: '绌�'}, {value: '0', text: '鐜板湪'}, {value: 1, text: '鏄ㄥぉ'}, {value: 3, text: '鍓嶄笁澶�'}, {value: 7, text: '鍓嶄竷澶�'}, {value: 30, text: '鍓�30澶�'}],
     }
+  }
+
+  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 _options = ['label', 'field', 'initval', 'type', 'readonly'] // 榛樿鏄剧ず椤�
+
+    if ((type === 'select' || type === 'link') && resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
+      _options = [..._options, 'resourceType', 'setAll', 'options']
+    } else if ((type === 'select' || type === 'link') && resourceType === '1') { // 閫夋嫨绫诲瀷銆佹暟鎹簮
+      _options = [..._options, 'resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType']
+    } else if (type === 'number') {
+      _options = [..._options, 'decimal']
+    }
+
+    if (type === 'link') { // 鍏宠仈绫诲瀷銆佸鍔犲叧鑱斿瓧娈�
+      _options = [..._options, 'linkField']
+    }
+    
+    this.setState({
+      openType: type,
+      resourceType: resourceType,
+      formlist: formlist.map(form => {
+        if (this.state.dateoptions.hasOwnProperty(type) && form.key === 'initval') {
+          form.options = this.state.dateoptions[type]
+          form.type = 'select'
+        } else if (type === 'number' && form.key === 'initval') {
+          form.type = 'number'
+          form.initVal = 0
+        }
+        form.hidden = !_options.includes(form.key)
+        return form
+      })
+    })
   }
 
   openTypeChange = (key, value) => {
     if (key === 'type') {
-      let _options = ['label', 'field', 'initval', 'type']
-      if (value === 'select' || value === 'link') { // 鍒囨崲绫诲瀷涓洪�夋嫨鎴栧叧鑱旀椂锛屾潵婧愰粯璁や负鑷畾涔�
+      let _options = ['label', 'field', 'initval', 'type', 'readonly']
+
+      if ((value === 'select' || value === 'link') && this.state.resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
         _options = [..._options, 'resourceType', 'setAll', 'options']
+      } else if ((value === 'select' || value === 'link') && this.state.resourceType === '1') { // 閫夋嫨绫诲瀷銆佹暟鎹簮
+        _options = [..._options, 'resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType']
+      } else if (value === 'number') {
+        _options = [..._options, 'decimal']
       }
       
       if (value === 'link') {
@@ -38,17 +78,20 @@
       
       this.setState({
         openType: value,
-        resourceType: '0',
         formlist: this.state.formlist.map(form => {
           form.hidden = !_options.includes(form.key)
           if (form.key === 'initval') {
             if (this.state.dateoptions.hasOwnProperty(value)) {
               form.options = this.state.dateoptions[value]
               form.type = 'select'
+              form.initVal = ''
+            } else if (value === 'number') {
+              form.type = 'number'
+              form.initVal = 0
             } else {
               form.type = 'text'
+              form.initVal = ''
             }
-            form.initVal = ''
             form.hidden = true
           }
           return form
@@ -70,7 +113,7 @@
     const { openType } = this.state
     let value = e.target.value
     if (key === 'resourceType') {
-      let _options = ['label', 'field', 'initval', 'type', 'resourceType', 'setAll']
+      let _options = ['label', 'field', 'initval', 'type', 'resourceType', 'setAll', 'readonly']
       if (value === '0') {
         _options = [..._options, 'options']
       } else if (value === '1') {
@@ -113,6 +156,40 @@
             </Form.Item>
           </Col>
         )
+      } else if (item.type === 'number') {
+        if (item.key === 'decimal') {
+          fields.push(
+            <Col span={12} key={index}>
+              <Form.Item label={item.label}>
+                {getFieldDecorator(item.key, {
+                  initialValue: item.initVal || 0,
+                  rules: [
+                    {
+                      required: !!item.required,
+                      message: this.props.dict['form.required.input'] + item.label + '!'
+                    }
+                  ]
+                })(<InputNumber min={0} max={18} precision={0} />)}
+              </Form.Item>
+            </Col>
+          )
+        } else {
+          fields.push(
+            <Col span={12} key={index}>
+              <Form.Item label={item.label}>
+                {getFieldDecorator(item.key, {
+                  initialValue: item.initVal || 0,
+                  rules: [
+                    {
+                      required: !!item.required,
+                      message: this.props.dict['form.required.input'] + item.label + '!'
+                    }
+                  ]
+                })(<InputNumber />)}
+              </Form.Item>
+            </Col>
+          )
+        }
       } else if (item.type === 'select') { // 涓嬫媺鎼滅储
         fields.push(
           <Col span={12} key={index}>
@@ -130,7 +207,7 @@
                   showSearch
                   filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0}
                   onChange={(value) => {this.openTypeChange(item.key, value)}}
-                  getPopupContainer={() => document.getElementById('commontable-search-form-box')}
+                  getPopupContainer={() => document.getElementById('modal-fields-form-box')}
                 >
                   {item.options.map(option =>
                     <Select.Option id={option.value} title={option.text} key={option.value} value={option.value}>
@@ -237,39 +314,6 @@
     })
   }
 
-  resetForm = (formlist) => {
-    if (!formlist) return
-    let type = formlist.filter(cell => cell.key === 'type')[0].initVal
-    let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal
-    let _options = ['label', 'field', 'initval', 'type'] // 榛樿鏄剧ず椤�
-    if ((type === 'select' || type === 'link') && resourceType === '0') { // 閫夋嫨绫诲瀷銆佽嚜瀹氫箟璧勬簮
-      _options = [..._options, 'resourceType', 'setAll', 'options']
-    } else if ((type === 'select' || type === 'link') && resourceType === '1') { // 閫夋嫨绫诲瀷銆佹暟鎹簮
-      _options = [..._options, 'resourceType', 'setAll', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType']
-    }
-
-    if (type === 'link') { // 鍏宠仈绫诲瀷銆佸鍔犲叧鑱斿瓧娈�
-      _options = [..._options, 'linkField']
-    }
-    
-    this.setState({
-      openType: type,
-      resourceType: resourceType,
-      formlist: formlist.map(form => {
-        if (this.state.dateoptions.hasOwnProperty(type) && form.key === 'initval') {
-          form.options = this.state.dateoptions[type]
-          form.type = 'select'
-        }
-        form.hidden = !_options.includes(form.key)
-        return form
-      })
-    })
-  }
-
-  UNSAFE_componentWillMount () {
-    this.resetForm(this.props.formlist)
-  }
-
   render() {
     const formItemLayout = {
       labelCol: {
@@ -282,7 +326,7 @@
       }
     }
     return (
-      <Form {...formItemLayout} className="ant-advanced-search-form commontable-search-form" id="commontable-search-form-box">
+      <Form {...formItemLayout} className="ant-advanced-search-form modal-fields-form" id="modal-fields-form-box">
         <Row gutter={24}>{this.getFields()}</Row>
       </Form>
     )

--
Gitblit v1.8.0