From 9ee3d1f9a09a865188baffdffb85f6ad329c7b09 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 19 十二月 2021 01:09:20 +0800
Subject: [PATCH] 2021-12-19

---
 src/menu/components/table/edit-table/columns/editColumn/index.jsx |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 102 insertions(+), 13 deletions(-)

diff --git a/src/menu/components/table/edit-table/columns/editColumn/index.jsx b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
index 34d33ea..d664236 100644
--- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx
+++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
@@ -1,18 +1,21 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Modal } from 'antd'
+import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Modal, notification } from 'antd'
+import { QuestionCircleOutlined } from '@ant-design/icons'
 
 import { getColumnForm } from './formconfig'
 import { formRule } from '@/utils/option.js'
 import './index.scss'
 
+const { TextArea } = Input
 const columnTypeOptions = {
-  text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'editable', 'blacklist'],
-  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'blacklist'],
-  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'blacklist'],
+  text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'editable', 'initval', 'blacklist'],
+  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'initval', 'sum', 'blacklist'],
+  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'initval', 'postfix', 'blacklist'],
   custom: ['label', 'type', 'Align', 'Hide', 'Width', 'blacklist'],
   action: ['label', 'type', 'Align', 'Width'],
+  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'],
   index: ['label', 'type', 'Align', 'Width']
 }
 
@@ -21,6 +24,7 @@
     dict: PropTypes.object,     // 瀛楀吀椤�
     visible: PropTypes.bool,
     column: PropTypes.object,
+    columns: PropTypes.array,
     fields: PropTypes.array,
     submitCol: PropTypes.func,  // 鎻愪氦浜嬩欢
     cancelCol: PropTypes.func   // 鍙栨秷鏃跺垹闄や簨浠�
@@ -38,36 +42,58 @@
   }
 
   editColumn = (column) => {
-    let formlist = getColumnForm(column, this.props.fields)
+    let formlist = getColumnForm(column, this.props.fields, this.props.columns)
     let _options = fromJS(columnTypeOptions[column.type]).toJS()
+
+    if (column.editable === 'true') {
+      if (column.type === 'text') {
+        _options.push('required', 'enter', 'footEnter')
+      } else if (column.type === 'number') {
+        _options.push('max', 'min', 'enter', 'footEnter')
+      }
+    }
 
     this.setState({
       visible: true,
+      editable: column.editable || 'false',
       type: column.type,
       formlist: formlist.map(item => {
         item.hidden = !_options.includes(item.key)
 
         return item
       })
-    }, () => {
-      if (column.focus) {
+    })
+    if (column.focus) {
+      setTimeout(() => {
         try {
           let _form = document.getElementById('label')
           _form && _form.select()
         } catch (e) {
           console.warn('琛ㄥ崟focus澶辫触锛�')
         }
-      }
-    })
+      }, 200)
+    }
   }
 
   typeChange = (key, value, option) => {
+    const { editable, type } = this.state
     if (key === 'type') {
       let _options = fromJS(columnTypeOptions[value]).toJS()
+
+      if (editable === 'true') {
+        if (value === 'text') {
+          _options.push('required', 'enter', 'footEnter')
+        } else if (value === 'number') {
+          _options.push('max', 'min', 'enter', 'footEnter')
+        }
+      }
 
       this.setState({
         type: value,
         formlist: this.state.formlist.map(item => {
+          if (item.key === 'editable') {
+            item.initVal = editable
+          }
           item.hidden = !_options.includes(item.key)
 
           return item
@@ -93,9 +119,20 @@
       if (values.type !== this.state.type) {
         let _options = fromJS(columnTypeOptions[values.type]).toJS()
 
+        if (editable === 'true') {
+          if (values.type === 'text') {
+            _options.push('required', 'enter', 'footEnter')
+          } else if (values.type === 'number') {
+            _options.push('max', 'min', 'enter', 'footEnter')
+          }
+        }
+
         this.setState({
           type: values.type,
           formlist: this.state.formlist.map(item => {
+            if (item.key === 'editable') {
+              item.initVal = editable
+            }
             item.hidden = !_options.includes(item.key)
 
             return item
@@ -108,6 +145,25 @@
       }
     } else if (key === 'format' && value === 'percent') {
       this.props.form.setFieldsValue({postfix: '%'})
+    } else if (key === 'editable') {
+      let _options = fromJS(columnTypeOptions[type]).toJS()
+
+      if (value === 'true') {
+        if (type === 'text') {
+          _options.push('required', 'enter', 'footEnter')
+        } else if (type === 'number') {
+          _options.push('max', 'min', 'enter', 'footEnter')
+        }
+      }
+
+      this.setState({
+        editable: value,
+        formlist: this.state.formlist.map(item => {
+          item.hidden = !_options.includes(item.key)
+
+          return item
+        })
+      })
     }
   }
 
@@ -133,7 +189,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -155,7 +211,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -206,7 +262,7 @@
           <Col span={12} key={index}>
             <Form.Item label={item.tooltip ?
               <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {item.label}
               </Tooltip> : item.label
             }>
@@ -219,7 +275,7 @@
                   }
                 ]
               })(
-                <Radio.Group>
+                <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}>
                   {
                     item.options.map(option => {
                       return (
@@ -252,15 +308,48 @@
             </Form.Item>
           </Col>
         )
+      } else if (item.type === 'textarea') { // 鏂囨湰鎼滅储
+        fields.push(
+          <Col span={24} key={index} className="textarea">
+            <Form.Item label={item.tooltip ?
+              <Tooltip placement="topLeft" title={item.tooltip}>
+                <QuestionCircleOutlined className="mk-form-tip" />
+                {item.label}
+              </Tooltip> : item.label
+            }>
+              {getFieldDecorator(item.key, {
+                initialValue: item.initVal || '',
+                rules: [
+                  {
+                    required: !!item.required,
+                    message: this.props.dict['form.required.input'] + item.label + '!'
+                  }
+                ]
+              })(<TextArea rows={2} disabled={item.readonly} placeholder={item.placeholder || ''} />)}
+            </Form.Item>
+          </Col>
+        )
       }
     })
     return fields
   }
 
   handleSubmit = () => {
+    const { columns, column } = this.props
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
+        values.uuid = column.uuid
+        values.marks = column.marks || []
+        
+        if (values.field && columns.filter(col => col.field && col.uuid !== values.uuid && col.field === values.field).length > 0) {
+          notification.warning({
+            top: 92,
+            message: '瀛楁宸叉坊鍔狅紒',
+            duration: 5
+          })
+          return
+        }
         this.setState({visible: false, formlist: null})
         this.props.submitCol(values)
       }

--
Gitblit v1.8.0