From b69b5f6329ca5f87932436b7a6c1ddfc3377e10f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 16 五月 2024 10:56:41 +0800
Subject: [PATCH] 2024-05-16

---
 src/components/normalform/modalform/index.jsx |  171 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 136 insertions(+), 35 deletions(-)

diff --git a/src/components/normalform/modalform/index.jsx b/src/components/normalform/modalform/index.jsx
index ebf07cb..8a7599f 100644
--- a/src/components/normalform/modalform/index.jsx
+++ b/src/components/normalform/modalform/index.jsx
@@ -7,23 +7,28 @@
 import asyncComponent from '@/utils/asyncComponent'
 import MKEInput from './mkInput'
 import MKNumberInput from './mkNumberInput'
+import MKEmitter from '@/utils/events.js'
 import MKSelect from './mkSelect'
 import './index.scss'
 
 const { TextArea } = Input
 
 const MKRadio = asyncComponent(() => import('./mkRadio'))
+const MKTable = asyncComponent(() => import('./mkTable'))
 const MKCheckbox = asyncComponent(() => import('./mkCheckbox'))
 const StyleInput = asyncComponent(() => import('./styleInput'))
 const MKFileUpload = asyncComponent(() => import('@/tabviews/zshare/fileupload'))
-const MKColor = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkColor'))
-const MkIcon = asyncComponent(() => import('@/components/mkIcon'))
+const MkPrintTemps = asyncComponent(() => import('@/menu/components/share/actioncomponent/actionform/mkPrintTemps'))
+const MKColor = asyncComponent(() => import('@/mob/colorsketch'))
+// const MKColor = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkColor'))
+const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
 const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
 
 class ModalForm extends Component {
   static propTpyes = {
-    formlist: PropTypes.array,   // 琛ㄥ崟鍒楄〃
-    inputSubmit: PropTypes.func  // input鍥炶溅鎻愪氦
+    formlist: PropTypes.array,
+    inputSubmit: PropTypes.func,
+    transVals: PropTypes.func,
   }
 
   state = {
@@ -44,6 +49,8 @@
       
       item.hidden = false
 
+      if (item.forbid && item.del) return false
+
       if (item.forbid) {
         item.hidden = true
       }
@@ -56,6 +63,10 @@
           required: item.required,
           message: item.label + '涓嶅彲涓虹┖!'
         }]
+
+        if (item.rules) {
+          _rules.push(...item.rules)
+        }
         
         item.rules = _rules
       } else if (item.type === 'number') {
@@ -63,16 +74,22 @@
           required: item.required,
           message: item.label + '涓嶅彲涓虹┖!'
         }, {
-          validator: (rule, value, callback) => this.handleConfirmPassword(rule, value, callback, item)
+          validator: (rule, value, callback) => this.checkNumber(rule, value, callback, item)
         }]
       } else if (item.type === 'textarea') {
-        let _rules = [
+        item.rules = [
           {
             required: item.required,
             message: item.label + '涓嶅彲涓虹┖!'
           }
         ]
-        item.rules = _rules
+      } else if (item.type === 'table') {
+        item.rules = [
+          {
+            required: item.required,
+            message: '璇锋坊鍔�' + item.label + '!'
+          }
+        ]
       } else {
         item.rules = [
           {
@@ -93,8 +110,13 @@
       if (!fieldMap.has(key)) return
 
       let supItem = fieldMap.get(key)
+      let supval = supItem.initval
+
+      if (supval && JSON.stringify(supval) === '[]') {
+        supval = ''
+      }
+
       let fields = []
-      
       controlFields[key].forEach(item => {
         if (!fieldMap.has(item.field)) return
 
@@ -102,16 +124,21 @@
 
         if (cell.hidden) return
 
-        if (supItem.hidden) {
+        if (cell.skip && supItem.forbid) { // 涓婄骇琛ㄥ崟绂佺敤鏃讹紝姝よ〃鍗曚笉鍙楁帶鍒�
+
+        } else if (supItem.hidden) {
           cell.hidden = true
-        } else if (supItem.type === 'checkbox') {
-          let vals = [...supItem.initval, ...item.values]
+        } else if (item.notNull) {
+          cell.hidden = !supval
+        } else if (supItem.type === 'checkbox' || supItem.type === 'multiselect') {
+          let vals = [...(supval || []), ...item.values]
           if (vals.length === new Set(vals).size) {
             cell.hidden = true
           }
-        } else if (!item.values.includes(supItem.initval)) {
+        } else if (!item.values.includes(supval)) {
           cell.hidden = true
         }
+
         fieldMap.set(item.field, cell)
 
         fields.push(item)
@@ -139,7 +166,7 @@
     this.setState({ formlist })
   }
 
-  handleConfirmPassword = (rule, value, callback, item) => {
+  checkNumber = (rule, value, callback, item) => {
     let val = parseFloat(value)
 
     if (!isNaN(val)) {
@@ -155,7 +182,13 @@
   recordChange = (values, item) => {
     this.record = {...this.record, ...values}
 
-    if (item && item.controlFields) {
+    if (!item) return
+
+    if (item.$trans) {
+      this.props.transVals && this.props.transVals(values, item.field)
+    }
+    
+    if (item.controlFields) {
       let map = new Map()
       this.state.formlist.forEach(cell => {
         if (!cell.field) return
@@ -165,13 +198,19 @@
       let reset = (current) => {
         let val = this.record[current.field]
 
+        if (val && JSON.stringify(val) === '[]') {
+          val = ''
+        }
+
         current.controlFields.forEach(cell => {
           let m = map.get(cell.field)
 
           if (current.hidden) {
             m.hidden = true
-          } else if (current.type === 'checkbox') {
-            let vals = [...val, ...cell.values]
+          } else if (cell.notNull) {
+            m.hidden = !val
+          } else if (current.type === 'checkbox' || current.type === 'multiselect') {
+            let vals = [...(val || []), ...cell.values]
             if (vals.length !== new Set(vals).size) {
               m.hidden = false
             } else {
@@ -197,10 +236,35 @@
 
       this.setState({
         formlist: this.state.formlist.map(cell => {
-          if (cell.field) {
-            return map.get(cell.field)
+          if (!cell.field) return cell
+
+          let item = map.get(cell.field)
+
+          if (item && item.linkField) {
+            let supInitVal = this.record[item.linkField] || ''
+            
+            item.options = item.oriOptions.filter(option => option.ParentID === supInitVal)
           }
-          return cell
+
+          return item || cell
+        })
+      })
+    } else if (item.reset_source) {
+      let map = new Map()
+      this.state.formlist.forEach(cell => {
+        if (!cell.field) return
+        map.set(cell.field, cell)
+      })
+
+      item.callback(map, this.record, MKEmitter)
+
+      this.setState({
+        formlist: this.state.formlist.map(cell => {
+          if (!cell.field) return cell
+
+          let item = map.get(cell.field)
+
+          return item || cell
         })
       })
     }
@@ -216,16 +280,23 @@
       if (item.hidden || item.forbid) return
 
       let content = null
-      let label = item.tooltip ? <Tooltip placement="topLeft" title={item.tooltip}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip> : item.label
+      let label = item.label
+      if (item.tooltip) {
+        if (item.toolWidth) {
+          label = <Tooltip placement="topLeft" overlayStyle={{maxWidth: item.toolWidth}} title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip>
+        } else {
+          label = <Tooltip placement="topLeft" title={<div onClick={(e) => e.stopPropagation()}>{item.tooltip}</div>}><QuestionCircleOutlined className="mk-form-tip" />{item.label}</Tooltip>
+        }
+      }
     
       if (item.type === 'text') {
-        content = (<MKEInput config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val})} onSubmit={this.props.inputSubmit} />)
+        content = (<MKEInput config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val}, item)} onSubmit={this.props.inputSubmit} />)
       } else if (item.type === 'number') {
-        content = (<MKNumberInput config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val})} onSubmit={this.props.inputSubmit} />)
+        content = (<MKNumberInput config={item} onChange={(val, defer) => !defer && this.recordChange({[item.field]: val}, item)} onSubmit={this.props.inputSubmit} />)
       } else if (item.type === 'select' || item.type === 'multiselect') {
         content = (<MKSelect config={item} onChange={(val, other) => this.recordChange({[item.field]: val, ...other}, item)} />)
       } else if (item.type === 'color') {
-        content = (<MKColor config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>)
+        content = (<MKColor config={item} allowClear={item.allowClear} onChange={(val) => this.recordChange({[item.field]: val})}/>)
       } else if (item.type === 'styleInput') {
         content = (<StyleInput config={item} onChange={(val) => this.recordChange({[item.field]: val})}/>)
       } else if (item.type === 'radio') {
@@ -235,27 +306,57 @@
       } else if (item.type === 'fileupload') {
         content = (<MKFileUpload config={item} onChange={(val) => this.recordChange({[item.field]: val})} />)
       } else if (item.type === 'cascader') {
-        content = (<Cascader allowClear={!!item.allowClear} options={item.options} expandTrigger="hover" placeholder="" />)
+        content = (<Cascader allowClear={!!item.allowClear} onChange={(val) => this.recordChange({[item.field]: val}, item)} options={item.options} expandTrigger="hover" placeholder="" />)
       } else if (item.type === 'textarea') {
         content = (<TextArea rows={item.rows || 2} placeholder=""/>)
       } else if (item.type === 'mkicon') {
-        content = (<MkIcon allowClear={item.allowClear}/>)
+        content = (<MkEditIcon allowClear={item.allowClear}/>)
       } else if (item.type === 'source') {
         content = (<SourceComponent type="" placement="right"/>)
+      } else if (item.type === 'table') {
+        content = (<MKTable tip={item.tip || ''} columns={item.columns || []} actions={item.actions || []}/>)
+      } else if (item.type === 'hint') {
+        fields.push(
+          <Col span={24} key={index}>
+            <div style={{color: '#1890ff', borderBottom: '1px solid #e9e9e9', marginBottom: '15px', paddingLeft: '10px'}}>{item.label}</div>
+          </Col>
+        )
+        return
+      } else if (item.type === 'printTemps') {
+        content = <MkPrintTemps onChange={(val) => this.recordChange({[item.field]: val})}/>
       }
 
       if (!content) return
 
-      fields.push(
-        <Col span={item.span || 12} key={index}>
-          <Form.Item label={label}>
-            {getFieldDecorator(item.field, {
-              initialValue: item.initval,
-              rules: item.rules
-            })(content)}
-          </Form.Item>
-        </Col>
-      )
+      if (item.help) {
+        let help = null
+        if (typeof(item.help) === 'function') {
+          help = item.help(this.record)
+        } else {
+          help = <span style={{fontSize: '12px'}}>{item.help}</span>
+        }
+        fields.push(
+          <Col span={item.span || 12} key={index}>
+            <Form.Item label={label} help={help}>
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval,
+                rules: item.rules
+              })(content)}
+            </Form.Item>
+          </Col>
+        )
+      } else {
+        fields.push(
+          <Col span={item.span || 12} key={index}>
+            <Form.Item label={label}>
+              {getFieldDecorator(item.field, {
+                initialValue: item.initval,
+                rules: item.rules
+              })(content)}
+            </Form.Item>
+          </Col>
+        )
+      }
     })
     
     return fields

--
Gitblit v1.8.0