From 7facbed508592e842f9bca085cf0ffaebcbfc571 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 12 十一月 2020 19:22:37 +0800
Subject: [PATCH] 2020-11-12

---
 src/views/billprint/index.jsx |  196 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 175 insertions(+), 21 deletions(-)

diff --git a/src/views/billprint/index.jsx b/src/views/billprint/index.jsx
index 9565445..57d0ea1 100644
--- a/src/views/billprint/index.jsx
+++ b/src/views/billprint/index.jsx
@@ -25,6 +25,7 @@
     dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     loadingview: true,
     dataManager: false,
+    pages: null,
     BID: '',
     data: '',
     tempId: '',
@@ -105,6 +106,48 @@
           return
         }
 
+        config.style = config.style || {}
+
+        if (config.pageSize === 'A0') {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 1305
+          } else {
+            config.style.height = 1305
+          }
+        } else if (config.pageSize === 'A1') {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 1305
+          } else {
+            config.style.height = 1305
+          }
+        } else if (config.pageSize === 'A2') {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 1305
+          } else {
+            config.style.height = 1305
+          }
+        } else if (config.pageSize === 'A3') {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 1305
+          } else {
+            config.style.height = 1305
+          }
+        } else if (config.pageSize === 'A5') {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 1305
+          } else {
+            config.style.height = 1305
+          }
+        } else {
+          if (config.pageLayout === 'horizontal') {
+            config.style.height = 895
+          } else {
+            config.style.height = 1305
+          }
+        }
+
+        // config.style.height = 895
+
         let params = []
         let _pars = []
 
@@ -112,6 +155,7 @@
         config.components = config.components.map(component => {
           if (component.action) component.action = []
           if (component.search) component.search = []
+          component.data = [] // 鍒濆鍖栨暟鎹负绌�
     
           if (!component.setting) return component // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂
           if (!component.format || (component.subtype === 'propcard' && component.wrap.datatype === 'static')) return component // 娌℃湁鍔ㄦ�佹暟鎹�  鏁版嵁鏍煎紡 array 鎴� object
@@ -186,7 +230,7 @@
           config
         }, () => {
           if (params.length === 0) {
-            this.setState({loadingview: false})
+            this.setState({loadingview: false, pages: [config.components]})
           } else {
             this.loadmaindata(params)
           }
@@ -272,6 +316,8 @@
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
   loadmaindata = (params) => {
+    const { components, everyPCount, firstCount, lastCount } = this.state.config
+
     let deffers = params.map(item => {
       let componentId = item.componentId
       delete item.componentId
@@ -295,16 +341,124 @@
     Promise.all(deffers).then(results => {
       let _results = results.filter(Boolean)
 
-      this.setState({loadingview: false})
+      let comps = components.map(item => {
+        if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return item
 
-      if (_results.length === results.length) {
-        console.log(_results)
+        _results.forEach(res => {
+          if (res.componentId === item.uuid && res.data) {
+            item.data = res.data
+            item.dataArray = fromJS(res.data).toJS()
+          } else if (res.componentId === 'union' && res[item.dataName]) {
+            item.data = res[item.dataName]
+            item.dataArray = fromJS(res[item.dataName]).toJS()
+          }
+        })
+
+        return item
+      })
+
+      let length = comps.length
+      let pageIndex = 1
+      let pages = []
+      let over = false
+
+      if (length === 0) {
+        this.setState({loadingview: false, pages})
       }
 
-      // delete result.ErrCode
-      // delete result.ErrMesg
-      // delete result.message
-      // delete result.status
+      // everyPCount, firstCount, lastCount
+      while (!over) {
+        let page = []
+        let count = 0
+        let _pageover = false
+        let pagesover = false
+
+        let limit = pageIndex === 1 ? (firstCount || 20) : (everyPCount || 20)
+
+        comps.forEach((_item, index) => {
+          let item = fromJS(_item).toJS()
+          if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 椤电湁椤佃剼
+            page.push(item)
+          } else if (_pageover) {
+            return
+          } else if (item.type === 'card' && item.subtype === 'datacard') {
+            if (!_item.dataArray || _item.dataArray.length === 0) return
+
+            item.data = []
+
+            while (count < limit && _item.dataArray.length > 0) {
+              item.data.push(_item.dataArray.shift())
+              count++
+            }
+
+            if (count >= limit) {
+              _pageover = true
+            }
+            page.push(item)
+          } else {
+            page.push(item)
+          }
+
+          if (index + 1 === length && !_pageover) {
+            pagesover = true
+          }
+        })
+
+        if (pagesover && lastCount && count > lastCount) {
+          pagesover = false
+          page = []
+          count = 0
+          _pageover = false
+
+          if (pageIndex === 1) {
+            limit = (everyPCount - firstCount) + (everyPCount - lastCount)
+
+            if (limit <= 0) {
+              limit = firstCount
+            }
+          } else {
+            limit = lastCount
+          }
+
+          comps.forEach((_item, index) => {
+            let item = fromJS(_item).toJS()
+            if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 椤电湁椤佃剼
+              page.push(item)
+            } else if (_pageover) {
+              return
+            } else if (item.type === 'card' && item.subtype === 'datacard') {
+              if (!_item.dataArray || _item.dataArray.length === 0) return
+  
+              item.data = []
+  
+              while (count < limit && _item.dataArray.length > 0) {
+                item.data.push(_item.dataArray.shift())
+                count++
+              }
+  
+              if (count >= limit) {
+                _pageover = true
+              }
+              page.push(item)
+            } else {
+              page.push(item)
+            }
+  
+            if (index + 1 === length && !_pageover) {
+              pagesover = true
+            }
+          })
+        }
+
+        pages.push(page)
+        pageIndex++
+
+        if (pageIndex >= 2000 || pagesover) {
+          over = true
+        }
+      }
+
+      this.setState({loadingview: false, pages})
     })
   }
 
@@ -312,7 +466,7 @@
     let bdhtml = window.document.body.innerHTML
     let jubuData = document.getElementById('bill-print').innerHTML
     window.document.body.innerHTML = jubuData
-    // document.getElementsByTagName('body')[0].style.zoom = 0.7
+    document.getElementsByTagName('body')[0].style.zoom = 0.8
 
     try {
       if (window.ActiveXObject) {
@@ -366,34 +520,32 @@
     window.location.reload()
   }
 
-  getComponents = () => {
-    const { config, BID, data, dataManager } = this.state
+  getComponents = (components) => {
+    const { dataManager } = this.state
 
-    return config.components.map(item => {
-      if (!item) return null
-
+    return components.map(item => {
       if (item.type === 'bar' || item.type === 'line') {
         return (
           <Col span={item.width} key={item.uuid}>
-            <AntvBarAndLine config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} />
+            <AntvBarAndLine config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} />
           </Col>
         )
       } else if (item.type === 'pie') {
         return (
           <Col span={item.width} key={item.uuid}>
-            <AntvPie config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} />
+            <AntvPie config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} />
           </Col>
         )
       } else if (item.type === 'card' && item.subtype === 'datacard') {
         return (
           <Col span={item.width} key={item.uuid}>
-            <DataCard config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} />
+            <DataCard config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} />
           </Col>
         )
       } else if (item.type === 'card' && item.subtype === 'propcard') {
         return (
           <Col span={item.width} key={item.uuid}>
-            <PropCard config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} />
+            <PropCard config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} />
           </Col>
         )
       } else {
@@ -403,14 +555,16 @@
   }
 
   render() {
-    const { loadingview, viewlost, config } = this.state
+    const { loadingview, viewlost, config, pages } = this.state
 
     return (
       <div className="bill-print-wrap" >
         {loadingview && <Spin size="large" />}
-        {config ? <div id="bill-print" style={config.style}><Row>{this.getComponents()}</Row></div> : null}
+        {pages ? <div id="bill-print">
+          {pages.map((components, index) => (<div className="print-page" key={index} style={config.style}><Row>{this.getComponents(components)}</Row></div>))}
+        </div> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
-        {!loadingview && !viewlost ? <div className="print-button"><Button onClick={this.print}>鎵撳嵃</Button></div> : null}
+        {pages && !loadingview && !viewlost ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null}
       </div>
     )
   }

--
Gitblit v1.8.0