From 655ac8aef54bc134c1420c19975023182a10cae4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 十二月 2020 19:25:27 +0800
Subject: [PATCH] 2020-12-08

---
 src/tabviews/zshare/normalTable/index.jsx |  114 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/src/tabviews/zshare/normalTable/index.jsx b/src/tabviews/zshare/normalTable/index.jsx
index 23a8e27..d5e0826 100644
--- a/src/tabviews/zshare/normalTable/index.jsx
+++ b/src/tabviews/zshare/normalTable/index.jsx
@@ -5,7 +5,6 @@
 import { is, fromJS } from 'immutable'
 import { Table, Affix, Typography, Modal, Icon } from 'antd'
 
-import Utils from '@/utils/utils.js'
 import { modifyTabview } from '@/store/action'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
@@ -52,7 +51,7 @@
     imgSrc: '',           // 鍥剧墖璺緞
     lineMarks: null,      // 琛屾爣璁�
     activeIndex: null,    // 鏍囪褰撳墠閫変腑琛�
-    rowspan: null         // 琛屽悎骞跺瓧娈典俊鎭�
+    rowspans: null        // 琛屽悎骞跺瓧娈典俊鎭�
   }
 
   UNSAFE_componentWillMount () {
@@ -62,7 +61,7 @@
     let _columns = []
     let radio = 5          // 铏氬寲姣斾緥
     let _format = false    // 鏄惁铏氬寲澶勭悊
-    let rowspan = null
+    let rowspans = []
 
     if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
       _format = true
@@ -83,7 +82,7 @@
 
         item.subcols.forEach(col => {
           if (col.rowspan === 'true') {
-            rowspan = col
+            rowspans.push(col.field)
           }
           if (_format && !Math.floor(Math.random() * radio)) {
             col.blur = true
@@ -141,7 +140,7 @@
         }
       } else {
         if (item.rowspan === 'true') {
-          rowspan = item
+          rowspans.push(item.field)
         }
         if (_format && !Math.floor(Math.random() * radio)) {
           item.blur = true
@@ -183,11 +182,15 @@
       _columns.push(cell)
     })
 
+    if (rowspans.length === 0) {
+      rowspans = null
+    }
+
     this.setState({
       columns: _columns,
       pageSize: pageSize ? pageSize : 10,
-      lineMarks: lineMarks,
-      rowspan: rowspan
+      lineMarks,
+      rowspans
     })
   }
 
@@ -397,7 +400,7 @@
               </div>
             ),
             props: {
-              rowSpan: record.$$rowspan,
+              rowSpan: record['$$' + item.field],
             }
           }
         }
@@ -421,7 +424,7 @@
               </div>
             ),
             props: {
-              rowSpan: record.$$rowspan,
+              rowSpan: record['$$' + item.field],
             }
           }
         }
@@ -506,7 +509,8 @@
     } else if (item.type === 'picture') {
       let photos = ''
       if (item.field && record.hasOwnProperty(item.field)) {
-        photos = record[item.field].split(',')
+        photos = record[item.field] + ''
+        photos = photos.split(',')
       } else {
         photos = ''
       }
@@ -696,7 +700,8 @@
         } else if (col.type === 'picture') {
           let photos = []
           try {
-            photos = record[col.field].split(',')
+            photos = record[col.field] + ''
+            photos = photos.split(',')
           } catch {
             photos = []
           }
@@ -989,9 +994,63 @@
     }
   }
 
+  handleRowspan = (data) => {
+    const { rowspans } = this.state
+
+    if (!rowspans || data.length === 0) return data
+
+    data = fromJS(data).toJS()
+    data = data.reverse()
+    data.forEach((item, index) => {
+      if (index === 0) {
+        rowspans.forEach(cell => {
+          item['$' + cell] = 1
+        })
+      } else {
+        let preItem = data[index - 1]
+        rowspans.forEach((cell, i) => {
+          if (i === 0) {
+            if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) {
+              item['$' + cell] = preItem['$' + cell] + 1
+            } else {
+              item['$' + cell] = 1
+            }
+          } else {
+            if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) {
+              item['$' + cell] = preItem['$' + cell] + 1
+            } else {
+              item['$' + cell] = 1
+            }
+            if (item['$' + cell] > item['$' + rowspans[i - 1]]) {
+              item['$' + cell] = 1
+            }
+          }
+        })
+      }
+    })
+    data = data.reverse()
+    data.forEach((item, index) => {
+      if (index === 0) {
+        rowspans.forEach(cell => {
+          item['$$' + cell] = item['$' + cell]
+        })
+      } else {
+        let preItem = data[index - 1]
+        rowspans.forEach(cell => {
+          if (preItem['$' + cell] > 1) {
+            item['$$' + cell] = 0
+          } else {
+            item['$$' + cell] = item['$' + cell]
+          }
+        })
+      }
+    })
+    return data
+  }
+
   render() {
     const { setting, pickup, statFValue } = this.props
-    const { selectedRowKeys, lineMarks, activeIndex, rowspan } = this.state
+    const { selectedRowKeys, lineMarks, activeIndex } = this.state
 
     // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙��
     let rowSelection = null
@@ -1025,35 +1084,8 @@
       _data = _data.filter((item, index) => selectedRowKeys.includes(index))
     }
 
-    if (rowspan) {
-      let marks = {}
-      let premark = {val: '', mark: ''}
-      _data = _data.map(item => {
-        if (item[rowspan.field]) {
-          if (item[rowspan.field] !== premark.val) {
-            premark = {val: item[rowspan.field], mark: Utils.getuuid()}
-
-            marks[premark.mark] = 1
-            item.$$mark = premark.mark
-          } else {
-            marks[premark.mark]++
-            item.$$mark = premark.mark
-          }
-        } else {
-          item.$$rowspan = 1
-        }
-        return item
-      })
-
-      _data = _data.map(item => {
-        if (item.$$mark) {
-          item.$$rowspan = marks[item.$$mark]
-          marks[item.$$mark] = 0
-        }
-        return item
-      })
-    }
-
+    _data = this.handleRowspan(_data)
+    
     let _pagination = false
     if (setting.laypage !== 'false' && setting.laypage !== false) {
       _pagination = {

--
Gitblit v1.8.0