From cf8e332b14ca79859fcd89f2ac097ed7c6aa66c5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 01 十二月 2019 18:15:45 +0800
Subject: [PATCH] 2019-12-01

---
 src/tabviews/commontable/index.jsx |  148 +++++++++++++++++++++++++++++-------------------
 1 files changed, 89 insertions(+), 59 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index c87be74..027f7fb 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -27,17 +27,16 @@
     searchlist: null,
     actions: null,
     columns: null,
+    arr_field: '',
     setting: null,
     data: null,
     total: 0,
     loading: false,
-    param: {
-      pageIndex: 1,
-      pageSize: 10,
-      orderColumn: '',
-      orderType: '',
-      search: ''
-    },
+    pageIndex: 1,
+    pageSize: 10,
+    orderColumn: '',
+    orderType: 'asc',
+    search: '',
     fixed: {}
   }
 
@@ -67,14 +66,29 @@
           duration: 10
         })
       }
+
+      let _search = Utils.mainjointsearchkey(config.search)
+      let _arrField = []
+
+      config.columns.forEach(col => {
+        if (col.field) {
+          _arrField.push(col.field)
+        }
+      })
+
       this.setState({
         config: config,
         setting: config.setting,
         searchlist: config.search,
         actions: config.action,
-        columns: config.columns
+        columns: config.columns,
+        arr_field: _arrField.join(','),
+        search: _search ? 'where (' + _search + ')' : '',
+        orderColumn: config.setting.orderColumn,
+        loading: true
       }, () => {
         this.improveSearch()
+        this.loadmaindata()
       })
     } else {
       this.setState({
@@ -159,66 +173,82 @@
     })
   }
 
-  async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') {
+  async loadmaindata () {
+    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
     // 鑾峰彇鍒楄〃鏁版嵁
-    let result = await Api.getMainTableData(this.props.MenuNo, pageIndex, pageSize, orderColumn, orderType, search)
+    let param = {
+      func: 'sPC_Get_TableData',
+      obj_name: 'data',
+      arr_field: arr_field
+    }
+
+    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderColumn} ${orderType}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
+    let DateCount = `select count(1) as total from ${setting.dataresource} ${search}`
+    console.log(LText)
+    console.log(DateCount)
+    param.LText = Utils.formatOptions(LText)
+    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
-          item.rows = item.mkrows
           return item
         }),
         total: result.total,
         loading: false
+      })
+    } else {
+      this.setState({
+        loading: false
+      })
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 15
       })
     }
   }
 
   refreshbysearch = (searches) => {
     // 鎼滅储鏉′欢鍙樺寲
-    console.log(searches)
-    // searches = Utils.jointsearchkey(searches)
-    // this.loadmaindata(this.state.param.pageIndex, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, searches)
-    // let param = Object.assign({}, this.state.param, {
-    //   search: searches
-    // })
-    // this.setState({
-    //   loading: true,
-    //   param: param
-    // })
+    let search = Utils.mainjointsearchkey(searches)
+    this.refs.mainTable.resetTable()
+
+    this.setState({
+      loading: true,
+      search: search ? 'where (' + search + ')' : ''
+    }, () => {
+      this.loadmaindata()
+    })
   }
 
   refreshbytable = (pagination, filters, sorter) => {
     // 琛ㄦ牸鏌ヨ鏉′欢淇敼
-    console.log(pagination)
-    console.log(filters)
-    console.log(sorter)
-    // if (sorter.order) {
-    //   let _chg = {
-    //     ascend: 'asc',
-    //     descend: 'desc'
-    //   }
-    //   sorter.order = _chg[sorter.order]
-    // }
-    // this.loadmaindata(pagination.current, pagination.pageSize, sorter.field, sorter.order, this.state.param.search)
-    // let param = Object.assign({}, this.state.param, {
-    //   pageIndex: pagination.current,
-    //   pageSize: pagination.pageSize,
-    //   orderColumn: sorter.field,
-    //   orderType: sorter.order
-    // })
-    // this.setState({
-    //   loading: true,
-    //   param: param
-    // })
+    if (sorter.order) {
+      let _chg = {
+        ascend: 'asc',
+        descend: 'desc'
+      }
+      sorter.order = _chg[sorter.order]
+    }
+
+    this.setState({
+      loading: true,
+      pageIndex: pagination.current,
+      pageSize: pagination.pageSize,
+      orderColumn: sorter.field || this.state.setting.orderColumn,
+      orderType: sorter.order || 'asc'
+    }, () => {
+      this.loadmaindata()
+    })
   }
 
   refreshbyaction = (btn, type) => {
     // 鎸夐挳鎿嶄綔鍚庡埛鏂拌〃鏍�,閲嶇疆椤电爜鍙婇�夋嫨椤�
     console.log(btn)
     console.log(type)
-    // this.refs.mainTable.resetTable()
+    this.refs.mainTable.resetTable()
     // this.loadmaindata(1, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, this.state.param.search)
     // this.setState({
     //   loading: true
@@ -239,22 +269,22 @@
     this.loadconfig()
     // this.loadmaindata()
 
-    this.setState({
-      data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
-        return {
-          key: index,
-          ID: item + 'mainkey',
-          ExRateName: '$',
-          SupplierName: '澶╃尗' + item + '搴�',
-          SupShortName: '澶╃尗',
-          SupplierCode: '201922' + item,
-          OrgName: '闃块噷宸村反',
-          OrgCode: '302999',
-          PlanDate: '2019-11-' + (item < 10 ? '0' + item : item)
-        }
-      }),
-      total: 329
-    })
+    // this.setState({
+    //   data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
+    //     return {
+    //       key: index,
+    //       ID: item + 'mainkey',
+    //       ExRateName: '$',
+    //       SupplierName: '澶╃尗' + item + '搴�',
+    //       SupShortName: '澶╃尗',
+    //       SupplierCode: '201922' + item,
+    //       OrgName: '闃块噷宸村反',
+    //       OrgCode: '302999',
+    //       PlanDate: '2019-11-' + (item < 10 ? '0' + item : item)
+    //     }
+    //   }),
+    //   total: 329
+    // })
   }
 
   shouldComponentUpdate (nextProps, nextState) {

--
Gitblit v1.8.0