From 34e7681fd12b1c4e4994d3bea1a553870e10bc50 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 11 三月 2023 17:58:54 +0800
Subject: [PATCH] 2023-03-11

---
 src/tabviews/zshare/actionList/exceloutbutton/index.jsx |  125 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 110 insertions(+), 15 deletions(-)

diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx
index 3d93b36..be05ea6 100644
--- a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx
@@ -18,6 +18,7 @@
   static propTpyes = {
     BID: PropTypes.string,            // 涓昏〃ID
     BData: PropTypes.any,             // 涓昏〃鏁版嵁
+    selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
     btn: PropTypes.object,            // 鎸夐挳
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
     updateStatus: PropTypes.func,     // 鎸夐挳鐘舵�佹洿鏂�
@@ -41,7 +42,7 @@
         this.setState({hidden: true})
       } else {
         let s = BData[btn.controlField] + ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+        if (btn.controlVals.includes(s)) {
           this.setState({hidden: true})
         } else {
           this.setState({hidden: false})
@@ -70,7 +71,7 @@
         this.setState({hidden: true})
       } else {
         let s = nextProps.BData[btn.controlField] + ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+        if (btn.controlVals.includes(s)) {
           this.setState({hidden: true})
         } else {
           this.setState({hidden: false})
@@ -593,29 +594,68 @@
 
         this.table2excel(column, table, this.state.excelName.replace(/\.xlsx/ig, '.xls'))
 
-        if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) {
+        if (btn.verify.enable === 'true' && btn.verify.script) {
           this.execCustomScript()
         } else {
           this.execSuccess({ErrCode: 'S', ErrMesg: '瀵煎嚭鎴愬姛锛�'})
         }
       } else {
+        let letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+        let cols = []
+
+        for (let index = 0; index < columns.length; index++) {
+          let i = Math.floor(index / 26)
+          let s = letters[i - 1] || ''
+          
+          cols.push(s + letters[index % 26])
+        }
+
+        let table = []
         let _header = []
         let _topRow = {}
         let colwidth = []
         let requires = []
+        let merges = []
 
         columns.forEach((col, i) => {
           _header.push(col.Column)
           _topRow[col.Column] = col.Text
-          colwidth.push({width: col.Width || 20})
+          colwidth.push({wch: col.Width || 20})
           if (col.required === 'true') {
             requires.push(i)
           }
         })
-  
-        let table = []
-  
-        table.push(_topRow)
+
+        if (btn.verify.merge === 'true') {
+          let fLine = {}
+          let sLine = {}
+          let sign = ''
+          columns.forEach((col, i) => {
+            if (/.+-.+/.test(col.Text)) {
+              let _sign = col.Text.split('-')[0]
+              let _name = col.Text.split('-')[1]
+              fLine[col.Column] = _sign
+              sLine[col.Column] = _name
+
+              if (sign === _sign) {
+                merges[merges.length - 1] = merges[merges.length - 1].split(':')[0] + `:${cols[i]}1`
+              } else {
+                merges.push(`${cols[i]}1:${cols[i]}2`)
+                sign = _sign
+              }
+            } else {
+              fLine[col.Column] = col.Text
+              sLine[col.Column] = col.Text
+              sign = ''
+              merges.push(`${cols[i]}1:${cols[i]}2`)
+            }
+          })
+
+          table.push(fLine)
+          table.push(sLine)
+        } else {
+          table.push(_topRow)
+        }
   
         data && data.forEach((item, index) => {
           let _row = {}
@@ -645,22 +685,42 @@
 
         ws['!cols'] = colwidth
 
+        if (btn.verify.rowHeight) {
+          ws['!rows'] = Array(table.length).fill({hpx: btn.verify.rowHeight})
+        }
+
         if (requires.length) {
-          let cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
           requires.forEach(col => {
             if (cols[col]) {
               ws[cols[col] + '1'].s = {font: { color: { rgb: 'F5222D' } }}
             }
           })
         }
+
+        if (merges.length) {
+          ws['!merges'] = []
+          merges.forEach(item => {
+            ws['!merges'].push(XLSX.utils.decode_range(item))
+          })
+
+          cols.forEach(col => {
+            if (ws[col + '1'].s) {
+              ws[col + '1'].s = {font: { color: { rgb: 'F5222D' } }, alignment: { horizontal: 'center', vertical: 'center' }}
+            } else {
+              ws[col + '1'].s = {alignment: { horizontal: 'center', vertical: 'center' }}
+            }
+            ws[col + '2'].s = {alignment: { horizontal: 'center', vertical: 'center' }}
+          })
+        }
+
         // ws["A1"].s = {fill: { bgColor: { rgb: "FFFFAA"  }}, font: { color: { rgb: "1890FF" } }}
-  
+
         const wb = XLSX.utils.book_new()
-        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
+        XLSX.utils.book_append_sheet(wb, ws, btn.verify.sheet || 'Sheet1')
   
         XLSX.writeFile(wb, this.state.excelName)
   
-        if (btn.verify && btn.verify.enable === 'true' && btn.verify.script) {
+        if (btn.verify.enable === 'true' && btn.verify.script) {
           this.execCustomScript()
         } else {
           this.execSuccess({ErrCode: 'S', ErrMesg: '瀵煎嚭鎴愬姛锛�'})
@@ -776,6 +836,7 @@
    * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
    */
   getExcelCustomParam = (orderBy, search, pagination = false, pageIndex = 1, pageSize = 100) => {
+    const { btn, selectedData } = this.props
     let _search = Utils.formatCustomMainSearch(search)
 
     let param = {
@@ -786,6 +847,13 @@
     // 鏁版嵁绠$悊鏉冮檺
     if (sessionStorage.getItem('dataM') === 'true') {
       param.dataM = 'Y'
+    }
+
+    if (btn.Ot === 'requiredOnce' && selectedData && selectedData.length > 0) {
+      let primaryId = selectedData.map(d => d.$$uuid || '').filter(Boolean).join(',')
+      if (primaryId) {
+        param.ID = primaryId
+      }
     }
 
     if (this.props.BID) {
@@ -804,17 +872,19 @@
    * @description 鑾峰彇榛樿瀛樺偍杩囩▼璇锋眰鍙傛暟
    */
   getExcelDefaultParam = (arr_field, orderBy, search, pagination = false, pageIndex = 1, pageSize = 100) => {
-    const { setting, btn } = this.props
+    const { setting, btn, selectedData, BID } = this.props
 
     let defaultSql = setting.execute || setting.default || 'true'
     let customScript = setting.customScript || ''
     let _dataresource = setting.dataresource || ''
     let queryType = setting.queryType
+    let primaryKey = setting.primaryKey || 'ID'
 
     if (btn.verify.dataType === 'custom') {
       defaultSql = btn.verify.defaultSql || 'true'
       _dataresource = btn.verify.dataresource || ''
       queryType = btn.verify.queryType
+      primaryKey = btn.verify.primaryKey || 'ID'
 
       if (/\s/.test(_dataresource)) {
         _dataresource = '(' + _dataresource + ') tb'
@@ -857,8 +927,8 @@
       param.dataM = 'Y'
     }
 
-    if (this.props.BID) {
-      param.BID = this.props.BID
+    if (BID) {
+      param.BID = BID
     }
 
     let userName = sessionStorage.getItem('User_Name') || ''
@@ -914,6 +984,16 @@
       _search = ''
     }
 
+    let primaryId = ''
+    if (btn.Ot === 'requiredOnce' && selectedData && selectedData.length > 0) {
+      primaryId = selectedData.map(d => d.$$uuid || '').filter(Boolean).join(',')
+      if (_search && primaryId) {
+        _search += ` and ${primaryKey} in (select ID from  dbo.SplitComma('${primaryId}'))`
+      } else if (primaryId) {
+        _search = `where ${primaryKey} in (select ID from  dbo.SplitComma('${primaryId}'))`
+      }
+    }
+
     let LText = ''
 
     if (defaultSql !== 'false' && !pagination) {
@@ -949,6 +1029,21 @@
       `
     }
 
+    LText = LText.replace(/@ID@/ig, `'${primaryId || ''}'`)
+    param.custom_script = param.custom_script.replace(/@ID@/ig, `'${primaryId || ''}'`)
+    LText = LText.replace(/@BID@/ig, `'${BID}'`)
+    param.custom_script = param.custom_script.replace(/@BID@/ig, `'${BID}'`)
+    LText = LText.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    param.custom_script = param.custom_script.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    LText = LText.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    param.custom_script = param.custom_script.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    LText = LText.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    param.custom_script = param.custom_script.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    LText = LText.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    param.custom_script = param.custom_script.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    LText = LText.replace(/@typename@/ig, `'admin'`)
+    param.custom_script = param.custom_script.replace(/@typename@/ig, `'admin'`)
+
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
       param.custom_script && console.info(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${param.custom_script}`)

--
Gitblit v1.8.0