From ff045a6a19e2e0bd5c2433aae71145401627c22d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 19 十二月 2019 19:08:32 +0800
Subject: [PATCH] 2019-12-19

---
 src/tabviews/commontable/index.jsx |  136 ++++++++++++++++++++++++++++++--------------
 1 files changed, 92 insertions(+), 44 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index 0325d43..7bdf4db 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -16,8 +16,9 @@
 
 export default class NormalTable extends Component {
   static propTpyes = {
-    MenuNo: PropTypes.string,  // 鑿滃崟鍙傛暟
-    MenuID: PropTypes.string   // 鑿滃崟Id
+    MenuNo: PropTypes.string,    // 鑿滃崟鍙傛暟
+    MenuName: PropTypes.string,  // 鑿滃崟鍙傛暟
+    MenuID: PropTypes.string     // 鑿滃崟Id
   }
 
   state = {
@@ -233,13 +234,70 @@
 
 
   async loadmaindata () {
+    const { setting } = this.state
+    let param = ''
+
+    if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) {
+      param = this.getCustomParam()
+    } else {
+      param = this.getDefaultParam()
+    }
+
+    let result = await Api.genericInterface(param)
+    if (result.status) {
+      this.setState({
+        data: result.data.map((item, index) => {
+          item.key = index
+          return item
+        }),
+        total: result.total,
+        loading: false
+      })
+    } else {
+      this.setState({
+        loading: false
+      })
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 15
+      })
+    }
+  }
+
+  getCustomParam = () => {
+    const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+
+    let _search = Utils.formatCustomMainSearch(search)
+
+    let param = {
+      PageIndex: pageIndex,
+      PageSize: pageSize,
+      OrderCol: orderColumn,
+      OrderType: orderType,
+      ..._search
+    }
+
+    if (setting.interType === 'inner') {
+      param.func = setting.innerFunc
+    } else {
+      param.rduri = setting.interface
+      if (setting.outerFunc) {
+        param.func = setting.outerFunc
+      }
+    }
+
+    return param
+  }
+
+  getDefaultParam = () => {
     const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
 
     let _search = Utils.joinMainSearchkey(search)
     _search = _search ? 'where (' + _search + ')' : ''
-    // 鑾峰彇鍒楄〃鏁版嵁
+
     let param = {
-      func: setting.innerFunc || 'sPC_Get_TableData',
+      func: 'sPC_Get_TableData',
       obj_name: 'data',
       arr_field: arr_field
     }
@@ -254,39 +312,7 @@
     param.secretkey = Utils.encrypt(param.LText, param.timestamp)
     param.DateCount = Utils.formatOptions(DateCount)
 
-    let result = await Api.genericInterface(param)
-    if (result.status) {
-      this.setState({
-        data: result.data.map((item, index) => {
-          item.key = index
-          return item
-        }),
-        total: result.total,
-        loading: false
-      })
-    } else {
-      // this.setState({
-      //   data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
-      //     let cell = {}
-      //     this.state.config.columns.forEach(column => {
-      //       if (!column.field) return
-      //       cell[column.field] = 'test' + item
-      //     })
-      //     cell.key = index
-      //     return cell
-      //   }),
-      //   total: 329,
-      //   loading: false
-      // })
-      this.setState({
-        loading: false
-      })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 15
-      })
-    }
+    return param
   }
 
   refreshbysearch = (searches) => {
@@ -369,32 +395,54 @@
     } else if (btn.execError === 'view' && type === 'error') {
       this.reloadview()
     } else if (type === 'excelOut') {
-      this.handleExcelout()
+      this.handleDefaultExcelout(btn)
     }
   }
 
-  handleExcelout = () => {
-    const { arr_field, orderColumn, orderType, search, setting } = this.state
+  handleDefaultExcelout = (btn) => {
+    const { MenuName } = this.props
+    const { arr_field, orderColumn, orderType, search, setting, config } = this.state
+
+    let _arr_labels = []      // 鍒楀悕绉伴泦
+    let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦
+
+    config.columns.forEach(col => {
+      if (col.field) {
+        _arr_labels.push(col.label)
+        _arr_label_field.push(`${col.field} as ${col.label}`)
+      }
+    })
+
+    _arr_labels = _arr_labels.join(',')
+    _arr_label_field = _arr_label_field.join(',')
 
     let _search = Utils.joinMainSearchkey(search)
     _search = _search ? 'where (' + _search + ')' : ''
     // 鑾峰彇鍒楄〃鏁版嵁
     let param = {
-      func: setting.innerFunc || 'sPC_Get_TableData',
+      func: 'sPC_Get_TableData',
       obj_name: 'data',
-      arr_field: arr_field
+      arr_field: _arr_labels
     }
 
     let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
 
-    let LText = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${setting.dataresource} ${_search}) tmptable order by tmptable.rows`
+    let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${setting.dataresource} ${_search}) tmptable order by tmptable.rows`
 
     param.LText = Utils.formatOptions(LText)
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
     param.secretkey = Utils.encrypt(param.LText, param.timestamp)
     param.DateCount = ''
 
-    Api.genericInterface(param)
+    let name = `${MenuName}${moment().format('YYYYMMDDHHmmss')}.xlsx`
+
+    Api.getExcelOut(param, name).then(res => {
+      if (res && res.status === false) {
+        this.refs.mainButton.execError(res, btn)
+      } else {
+        this.refs.mainButton.execSuccess(btn)
+      }
+    })
   }
 
   gettableselected = () => {

--
Gitblit v1.8.0