From 7bd04b1c21a59e8d79325f247bdb1726507b51fb Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 13 八月 2024 18:51:20 +0800
Subject: [PATCH] 2024-08-13

---
 src/tabviews/custom/components/card/double-data-card/index.jsx |  150 +++++++++++++++++++++----------------------------
 1 files changed, 64 insertions(+), 86 deletions(-)

diff --git a/src/tabviews/custom/components/card/double-data-card/index.jsx b/src/tabviews/custom/components/card/double-data-card/index.jsx
index 0275d3b..8ee5097 100644
--- a/src/tabviews/custom/components/card/double-data-card/index.jsx
+++ b/src/tabviews/custom/components/card/double-data-card/index.jsx
@@ -358,9 +358,7 @@
 
     if (config.$searchId !== searchId) return
     
-    this.setState({pageIndex: 1}, () => {
-      this.loadData()
-    })
+    this.reloadIndex()
   }
 
   /**
@@ -373,28 +371,23 @@
 
     let supModule = config.setting.supModule
 
+    let _id = config.wrap.selected === 'always' ? id : ''
     if (position === 'line' || position === 'line_grid') {
-      if (lines && lines.length === 1 && !config.forbidLine) {
-        this.loadLinedata(lines[0].$$parentId || lines[0].$$uuid, position)
-      } else if (btn.resetPageIndex !== 'false') {
-        this.setState({
-          pageIndex: 1
-        }, () => {
-          this.loadData(id)
-        })
+      if (lines && lines.length === 1) {
+        if (config.forbidLine) {
+          this.loadData(lines[0].$$parentId || lines[0].$$uuid, 'repage')
+        } else {
+          this.loadLinedata(lines[0].$$parentId || lines[0].$$uuid, position)
+        }
       } else {
-        this.loadData(id)
+        this.loadData(_id, 'repage')
       }
     } else if (['mainline', 'maingrid', 'popclose'].includes(position) && supModule) {
       MKEmitter.emit('reloadData', supModule, position === 'maingrid' ? '' : BID)
     } else if (btn.resetPageIndex !== 'false') {
-      this.setState({
-        pageIndex: 1
-      }, () => {
-        this.loadData(id)
-      })
+      this.reloadIndex()
     } else {
-      this.loadData(id)
+      this.loadData(_id, 'repage')
     }
   }
 
@@ -420,64 +413,40 @@
     })
   }
 
-  checkTopLine = (id) => {
-    const { config, data, selected, card } = this.state
+  checkTopLine = (id, selected) => {
+    const { config, data, card } = this.state
     let _opens = [...this.state.opens]
 
-    if (data.length === 0) {
-      this.setState({
-        activeKey: '',
-        selectKeys: [],
-        selectedData: []
-      })
-  
-      MKEmitter.emit('resetSelectLine', config.uuid, '', '')
-      return
-    }
+    let index = -1
+    let keys = []
+    let items = []
 
-    if (selected === 'sign') {
-      let index = ''
-      let keys = []
-      let items = []
-      let last = ''
-
-      if (card.setting.display === 'collapse') {
-        _opens = []
+    if (data.length > 0) {
+      if (id) {
+        index = data.findIndex(item => item.$$uuid === id && !item.$disabled)
       }
 
-      data.forEach((item, i) => {
-        if (!item.$disabled && item.selected === 'true') {
-          items.push(item)
-          keys.push(i)
-          index = i
-          last = item
-
-          if (card.setting.display === 'collapse') {
-            _opens.push(i)
+      if (index !== -1) {
+        keys = [index]
+        items = [data[index]]
+      } else if (selected === 'sign') {
+        data.forEach((item, i) => {
+          if (!item.$disabled && item.selected === 'true') {
+            items.push(item)
+            keys.push(i)
+            index = i
           }
+        })
+      } else if (selected !== 'false') {
+        if (!data[0].$disabled) {
+          index = 0
+          keys = [index]
+          items = [data[index]]
         }
-      })
-
-      this.setState({
-        opens: _opens,
-        activeKey: index,
-        selectKeys: keys,
-        selectedData: items
-      })
-  
-      MKEmitter.emit('resetSelectLine', config.uuid, last ? last.$$uuid : '', last)
-      return
-    }
-
-    let index = 0
-    if (id) {
-      index = data.findIndex(item => item.$$uuid === id)
-      if (index === -1) {
-        index = 0
       }
     }
 
-    if (data[index].$disabled) {
+    if (index === -1) {
       this.setState({
         activeKey: '',
         selectKeys: [],
@@ -489,17 +458,19 @@
     }
 
     if (card.setting.display === 'collapse') {
-      _opens = [index]
+      _opens = keys
     }
+
+    let item = items[items.length - 1]
 
     this.setState({
       opens: _opens,
       activeKey: index,
-      selectKeys: [index],
-      selectedData: [data[index]]
+      selectKeys: keys,
+      selectedData: items
     })
 
-    MKEmitter.emit('resetSelectLine', config.uuid, data[index].$$uuid, data[index])
+    MKEmitter.emit('resetSelectLine', config.uuid, item.$$uuid, item)
   }
 
   checkAll = () => {
@@ -547,7 +518,9 @@
     if (config.uuid !== menuId) return
 
     if (!id) {
-      this.loadData()
+      this.reloadIndex()
+    } else if (config.forbidLine) {
+      this.loadData(id, 'repage')
     } else {
       this.loadLinedata(id)
     }
@@ -643,6 +616,11 @@
     if (result.status) {
       if (result.$requestId && this.requestId !== result.$requestId) return
 
+      if (type === 'repage' && result.data.length === 0 && pageIndex > 1) {
+        this.reloadIndex()
+        return
+      }
+
       let start = 1
       if (config.setting.laypage) {
         start = pageSize * (pageIndex - 1) + 1
@@ -653,13 +631,10 @@
         Api.writeCacheConfig(config.uuid, result.data || [], BID)
       }
 
-      if (selected !== 'false' || (id && config.wrap.selected !== 'false')) {
+      if (selected !== 'false' || id) {
         setTimeout(() => {
-          this.checkTopLine(id)
+          this.checkTopLine(id, selected)
         }, 10)
-        if (selected === 'init') {
-          this.setState({selected: 'false'})
-        }
       } else {
         MKEmitter.emit('resetSelectLine', config.uuid, '', '')
       }
@@ -769,6 +744,10 @@
         loading: false
       })
 
+      if (selected === 'init') {
+        this.setState({selected: 'false'})
+      }
+
       if (config.timer && config.clearField && result.data && result.data[0]) {
         let vals = (config.clearValue || '').split(',')
         if (vals.includes(result.data[0][config.clearField])) {
@@ -793,15 +772,6 @@
   async loadLinedata (id, position) {
     const { config, pageIndex, pageSize, search, BID, BData, orderBy } = this.state
 
-    if (config.forbidLine) {
-      this.setState({
-        pageIndex: 1
-      }, () => {
-        this.loadData()
-      })
-      return
-    }
-
     let searches = fromJS(search).toJS()
     if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
       let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || []
@@ -823,7 +793,7 @@
     let result = await Api.genericInterface(param)
     if (result.status) {
       if (position === 'line_grid' && (!result.data || !result.data[0])) {
-        this.loadData()
+        this.reloadIndex()
         return
       }
 
@@ -946,6 +916,14 @@
     }
   }
 
+  reloadIndex = () => {
+    this.setState({
+      pageIndex: 1
+    }, () => {
+      this.loadData()
+    })
+  }
+
   loadMore = () => {
     const { total, pageIndex, pageSize, loading } = this.state
 

--
Gitblit v1.8.0