From e9e8b1c7b481415714fff9a0d83099fd5a7d6ff0 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 18 五月 2023 17:25:11 +0800
Subject: [PATCH] 2023-05-18

---
 src/menu/components/table/edit-table/columns/editColumn/index.jsx |   79 +++++++++++++++++++++++++--------------
 1 files changed, 50 insertions(+), 29 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 0f479c0..9a0143c 100644
--- a/src/menu/components/table/edit-table/columns/editColumn/index.jsx
+++ b/src/menu/components/table/edit-table/columns/editColumn/index.jsx
@@ -17,18 +17,17 @@
 const { TextArea } = Input
 const columnTypeOptions = {
   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', 'noValue'],
+  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', 'Width', 'blacklist'],
   colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'],
   action: ['label', 'type', 'Align', 'Width'],
-  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist', 'noValue'],
+  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'],
   index: ['label', 'type', 'Align', 'Width']
 }
 
 class EdiTableColumn extends Component {
   static propTpyes = {
-    visible: PropTypes.bool,
     column: PropTypes.object,
     columns: PropTypes.array,
     fields: PropTypes.array,
@@ -43,7 +42,7 @@
     transfield: {}
   }
 
-  column = null
+  record = null
 
   UNSAFE_componentWillMount() {
     let transfield = {}
@@ -61,22 +60,22 @@
   }
 
   getOptions = () => {
-    let _options = fromJS(columnTypeOptions[this.column.type]).toJS()
+    let _options = fromJS(columnTypeOptions[this.record.type]).toJS()
 
-    if (this.column.editable === 'true') {
+    if (['number', 'text'].includes(this.record.type) && this.record.editable === 'true') {
       _options.push('ctrlField')
-      if (this.column.ctrlField) {
+      if (this.record.ctrlField) {
         _options.push('ctrlValue')
       }
-      if (this.column.type === 'text') {
+      if (this.record.type === 'text') {
         _options.push('editType')
 
-        if (this.column.editType === 'switch') {
+        if (this.record.editType === 'switch') {
           _options.push('enter', 'openVal', 'closeVal', 'openText', 'closeText', 'editField')
-        } else if (this.column.editType === 'select') {
+        } else if (this.record.editType === 'select') {
           _options.push('required', 'enter', 'resourceType', 'linkSubField', 'editField', 'dropdown')
 
-          if (this.column.resourceType === '0') {
+          if (this.record.resourceType === '0') {
             _options.push('options')
           } else {
             _options.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'disableField', 'database')
@@ -84,9 +83,15 @@
         } else {
           _options.push('required', 'enter')
         }
-      } else if (this.column.type === 'number') {
+      } else if (this.record.type === 'number') {
         _options.push('max', 'min', 'enter')
       }
+    }
+    if (this.record.type === 'formula' && this.record.eval === 'true') {
+      _options.push('decimal')
+    }
+    if (['number', 'formula'].includes(this.record.type) && this.record.Hide !== 'true') {
+      _options.push('noValue')
     }
 
     return _options
@@ -99,10 +104,11 @@
     })
 
     let formlist = getColumnForm(column, fields, this.props.columns)
+    this.record = {}
 
-    this.column = fromJS(column).toJS()
-    this.column.editType = this.column.editType || 'text'
-    this.column.resourceType = this.column.resourceType || '0'
+    formlist.forEach(item => {
+      this.record[item.key] = item.initVal
+    })
     
     let _options = this.getOptions()
 
@@ -132,7 +138,7 @@
   }
 
   typeChange = (key, value, option) => {
-    this.column[key] = value
+    this.record[key] = value
 
     if (key === 'type') {
       let _options = this.getOptions()
@@ -144,7 +150,11 @@
 
       this.setState({
         formlist: this.state.formlist.map(item => {
-          item.initVal = this.column[item.key] || item.initVal
+          if (item.key === 'decimal' && value === 'formula') {
+            this.record.decimal = ''
+          }
+
+          item.initVal = this.record[item.key]
           item.hidden = !_options.includes(item.key)
 
           return item
@@ -154,8 +164,6 @@
           this.props.form.setFieldsValue({Align: 'center'})
         } else if (value === 'formula' && _field) {
           this.props.form.setFieldsValue({formula: '@' + _field + '@'})
-        } else if (value === 'action') {
-          this.props.form.setFieldsValue({Align: 'center', label: '鎿嶄綔'})
         } else if (value === 'index') {
           this.props.form.setFieldsValue({label: '搴忓彿'})
         }
@@ -173,15 +181,15 @@
         values.type = 'text'
       }
 
-      let _type = this.column.type
-      this.column.type = values.type
+      let _type = this.record.type
+      this.record.type = values.type
 
       if (values.type !== _type) {
         let _options = this.getOptions()
 
         this.setState({
           formlist: this.state.formlist.map(item => {
-            item.initVal = this.column[item.key] || item.initVal
+            item.initVal = this.record[item.key]
             item.hidden = !_options.includes(item.key)
 
             return item
@@ -194,12 +202,12 @@
       }
     } else if (key === 'format' && value === 'percent') {
       this.props.form.setFieldsValue({postfix: '%'})
-    } else if (key === 'editable' || key === 'editType' || key === 'resourceType' || key === 'ctrlField') {
+    } else if (['editable', 'editType', 'resourceType', 'ctrlField', 'eval', 'Hide'].includes(key)) {
       let _options = this.getOptions()
 
       this.setState({
         formlist: this.state.formlist.map(item => {
-          item.initVal = this.column[item.key] || item.initVal
+          item.initVal = this.record[item.key]
           item.hidden = !_options.includes(item.key)
 
           return item
@@ -211,7 +219,7 @@
   multiselectChange = (key, value) => {
     if (key !== 'linkSubField') return
 
-    this.column[key] = value
+    this.record[key] = value
   }
 
   handleEmpty = () => {
@@ -249,7 +257,7 @@
   }
 
   changeOptions = (data) => {
-    this.column.options = data || []
+    this.record.options = data || []
   }
 
   getFields() {
@@ -371,7 +379,7 @@
         span = 24
         className = 'text-area'
 
-        let linkSubFields = this.column.linkSubField || []
+        let linkSubFields = this.record.linkSubField || []
       
         content = <EditTable type={'select'} module="form" transfield={transfield} linkSubFields={linkSubFields} onChange={this.changeOptions}/>
       }
@@ -396,6 +404,7 @@
   }
 
   handleSubmit = () => {
+    const { fields } = this.props
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     this.props.form.validateFieldsAndScroll((err, values) => {
       if (!err) {
@@ -408,6 +417,18 @@
             })
             return
           }
+          // eslint-disable-next-line
+        } else if (values.type === 'formula' && values.eval !== 'false' && /^[\u4E00-\u9FA50-9a-zA-Z_\s@\+\-\*\/]*$/ig.test(values.formula) && /[\+\-\*\/]/ig.test(values.formula)) {
+          let cols = []
+          fields.forEach(col => {
+            if (/^(Int|Decimal)/ig.test(col.datatype)) {
+              cols.push({reg: new RegExp('@' + col.field + '@', 'ig'), value: `(@${col.field}@)`})
+            }
+          })
+
+          cols.forEach(col => {
+            values.formula = values.formula.replace(col.reg, col.value)
+          })
         }
 
         if (values.dataSource && /\s/.test(values.dataSource)) {
@@ -448,7 +469,7 @@
             if (result.status) {
               this.setState({visible: false, loading: false, formlist: null})
               this.props.submitCol(values)
-              this.column = null
+              this.record = null
             } else {
               this.setState({loading: false})
               Modal.error({
@@ -459,7 +480,7 @@
         } else {
           this.setState({visible: false, formlist: null})
           this.props.submitCol(values)
-          this.column = null
+          this.record = null
         }
       }
     })

--
Gitblit v1.8.0