From ef8acbf3859bd13e759fbb9b8ba726039c1fb2c5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 14 十一月 2023 15:51:59 +0800
Subject: [PATCH] 2023-11-14

---
 src/tabviews/zshare/mutilform/index.jsx |   83 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/index.jsx b/src/tabviews/zshare/mutilform/index.jsx
index d4b95fd..eff2368 100644
--- a/src/tabviews/zshare/mutilform/index.jsx
+++ b/src/tabviews/zshare/mutilform/index.jsx
@@ -46,10 +46,12 @@
     ID: '',
     send_type: '',
     timestamp: '',
-    n_id: ''
+    n_id: '',
+    focusId: ''
   }
 
   record = {}
+  submitId = ''
 
   componentDidMount () {
     const { action, unload } = this.props
@@ -268,7 +270,7 @@
       }
 
       if (item.type === 'number') {
-        if (isNaN(item.initval)) {
+        if (isNaN(item.initval) || item.initval === '') {
           item.initval = 0
         }
       } else if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && item.resourceType === '1') {
@@ -623,17 +625,19 @@
       }
 
       record[item.field] = item.initval
+      item.orgval = item.initval
 
       if (linkFields[item.field]) {
         item.linkFields = linkFields[item.field]
       }
       
       if (item.enter === 'tab' || item.enter === 'sub') {
-        if (fieldMap.has(item.tabField)) {
+        item.tabUuid = ''
+        if (item.tabField && fieldMap.has(item.tabField)) {
           item.tabUuid = fieldMap.get(item.tabField).uuid
         } else if (item.enter === 'tab') {
           item.enter = 'false'
-        } else if (item.enter === 'sub') {
+        } else if (item.enter === 'sub' && ['text', 'number'].includes(item.type)) {
           item.tabUuid = item.uuid
         }
       }
@@ -670,13 +674,16 @@
 
     this.record = record
     let ID = this.props.data ? this.props.data.$$uuid || '' : ''
+    let focusItem = null
 
-    this.setState({ formlist, ID }, () => {
+    if (action.setting.focus && fieldMap.has(action.setting.focus)) {
+      focusItem = fieldMap.get(action.setting.focus)
+    }
+
+    this.setState({ formlist, ID, focusId: focusItem ? focusItem.uuid : '' }, () => {
       if (unload) return
       
-      if (action.setting && action.setting.focus && fieldMap.has(action.setting.focus)) {
-        let focusItem = fieldMap.get(action.setting.focus)
-
+      if (focusItem) {
         if (focusItem.type === 'text' || focusItem.type === 'number') {
           setTimeout(() => {
             MKEmitter.emit('mkFC', 'focus', focusItem.uuid)
@@ -702,6 +709,62 @@
         }
       }
     })
+
+    if (action.subButton && action.subButton.resetForms) {
+      MKEmitter.addListener('resetForms', this.resetForms)
+    }
+  }
+
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('resetForms', this.resetForms)
+  }
+
+  resetForms = (id) => {
+    const { action } = this.props
+    const { focusId } = this.state
+
+    if (id !== action.uuid) return
+
+    let formlist = fromJS(this.state.formlist).toJS()
+    let resetForms = action.subButton.resetForms || []
+
+    formlist = formlist.map(item => {
+      if (item.type !== 'text' && item.type !== 'number') return item
+
+      if (resetForms.includes(item.field)) {
+        item.initval = item.orgval
+        this.record[item.field] = item.orgval
+      }
+
+      return item
+    })
+
+    let _list = fromJS(formlist).toJS().map(item => {
+      if (item.type !== 'text' && item.type !== 'number') return item
+
+      if (resetForms.includes(item.field) && !item.hidden) {
+        item.hidden = true
+      }
+
+      return item
+    })
+
+    this.setState({
+      formlist: _list
+    }, () => {
+      this.setState({
+        formlist
+      })
+    })
+
+    if (focusId || this.submitId) {
+      setTimeout(() => {
+        MKEmitter.emit('mkFC', 'focus', this.submitId || focusId)
+      }, 50)
+    }
   }
 
   getFormData = (deForms) => {
@@ -1218,7 +1281,7 @@
     return fields
   }
 
-  handleConfirm = () => {
+  handleConfirm = (formId) => {
     const { formlist, send_type, timestamp, n_id } = this.state
 
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
@@ -1316,6 +1379,8 @@
           forms.push(_item)
         })
 
+        this.submitId = formId || ''
+
         resolve(forms)
       })
     })

--
Gitblit v1.8.0