From 5088d267c69e87673c85ba302dd9dc62c9da4951 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 16 二月 2020 18:54:49 +0800
Subject: [PATCH] 2020-02-16

---
 src/tabviews/commontable/index.jsx |   83 +++++++++++++++++++++++++++++------------
 1 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index ffc11cf..4da0895 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -49,8 +49,7 @@
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
     pageIndex: 1,         // 椤电爜
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
-    orderColumn: '',      // 鎺掑簭瀛楁
-    orderType: 'asc',     // 鎺掑簭鏂瑰紡
+    orderBy: '',          // 鎺掑簭
     search: '',           // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞�
     BIDs: {},             // 涓婄骇琛╥d
     setsingle: false,     // 涓昏〃鍗曢�夊閫夊垏鎹�
@@ -58,7 +57,9 @@
     isLinkMain: false,    // 鏄惁瀛樺湪涓庝富琛ㄥ叧鑱旂殑瀛愯〃
     popAction: false,     // 寮规椤甸潰锛屾寜閽俊鎭�
     popData: false,       // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁
-    visible: false        // 寮规鏄剧ず闅愯棌鎺у埗
+    visible: false,       // 寮规鏄剧ず闅愯棌鎺у埗
+    tabBtn: null,         // 琛ㄥ崟鏍囩鎸夐挳
+    tabParam: null        // 琛ㄥ崟鏍囩鍙傛暟
   }
 
   /**
@@ -355,15 +356,14 @@
    * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
    */
   getCustomParam = () => {
-    const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+    const { pageIndex, pageSize, orderBy, search, setting } = this.state
 
     let _search = Utils.formatCustomMainSearch(search)
 
     let param = {
       PageIndex: pageIndex,
       PageSize: pageSize,
-      OrderCol: orderColumn,
-      OrderType: orderType,
+      OrderCol: orderBy || setting.order,
       ..._search
     }
 
@@ -390,7 +390,7 @@
    * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
    */
   getDefaultParam = () => {
-    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+    const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state
 
     if (!arr_field) {
       notification.warning({
@@ -412,7 +412,7 @@
       appkey: window.GLOB.appkey || ''
     }
     
-    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
+    let _orderBy = orderBy || setting.order
     let _dataresource = setting.dataresource
 
     if (/\s/.test(_dataresource)) {
@@ -445,10 +445,9 @@
       _search = ''
     }
 
-    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
+    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
     let DateCount = `select count(1) as total from ${_dataresource} ${_search}`
-    console.log(LText)
-    console.log(DateCount)
+
     param.LText = Utils.formatOptions(LText)
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
     param.secretkey = Utils.encrypt(param.LText, param.timestamp)
@@ -502,8 +501,7 @@
       loading: true,
       pageIndex: pagination.current,
       pageSize: pagination.pageSize,
-      orderColumn: sorter.field || this.state.setting.orderColumn,
-      orderType: sorter.order || 'asc'
+      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
     }, () => {
       this.loadmaindata()
     })
@@ -542,8 +540,7 @@
       loading: false,
       pageIndex: 1,
       pageSize: 10,
-      orderColumn: '',
-      orderType: 'asc',
+      orderBy: '',
       search: '',
       BIDs: {},
       setsingle: false,
@@ -576,6 +573,23 @@
   }
 
   /**
+   * @description 琛ㄥ崟鎿嶄綔瀹屾垚鍚庡埛鏂颁富椤甸潰
+   */
+  refreshbyformtab = (type) => {
+    this.setState({
+      view: 'commontable',
+      tabBtn: null,
+      tabParam: null
+    }, () => {
+      if (type === 'grid') {
+        this.reloadtable()
+      } else if (type === 'view') {
+        this.reloadview()
+      }
+    })
+  }
+
+  /**
    * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛�
    */
   handleMainTable = () => {
@@ -587,7 +601,7 @@
    */
   handleDefaultExcelout = (btn) => {
     const { MenuName } = this.props
-    const { arr_field, orderColumn, orderType, search, setting, config } = this.state
+    const { arr_field, orderBy, search, setting, config } = this.state
 
     let _arr_labels = []      // 鍒楀悕绉伴泦
     let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦
@@ -613,14 +627,14 @@
       appkey: window.GLOB.appkey || ''
     }
 
-    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
+    let _orderBy = orderBy || setting.order
     let _dataresource = setting.dataresource
 
     if (/\s/.test(_dataresource)) {
       _dataresource = '(' + _dataresource + ') tb'
     }
 
-    let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_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 ${_dataresource} ${_search}) tmptable order by tmptable.rows`
 
     param.LText = Utils.formatOptions(LText)
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -712,7 +726,7 @@
     if (btn.OpenType === 'popview') {
       this.setState({
         popAction: btn,
-        popData: data[0] ? data[0] : null,
+        popData: data[0] || null,
         visible: true
       })
     } else if (btn.OpenType === 'tab') {
@@ -724,25 +738,33 @@
         type: btn.tabTemplate,
         selected: true,
         param: {
+          parentId: this.props.MenuID,
           btn: btn,
-          data: data,
+          data: data[0] || null,
           primaryId: _primaryId,
           arr_field: this.state.arr_field
         }
       }
 
       let index = 0
+      let isexit = false
       let tabs = tabviews.map((tab, i) => {
+        tab.selected = false
+
         if (tab.MenuID === MenuID) {
           index = i
+        } else if (tab.MenuID === btn.uuid) {
+          tab.selected = true
+          isexit = true
         }
-        tab.selected = false
 
         return tab
       })
 
-      tabs.splice(index + 1, 0, newtab)
-      
+      if (!isexit) {
+        tabs.splice(index + 1, 0, newtab)
+      }
+
       this.props.modifyTabview(tabs)
     } else if (btn.OpenType === 'blank') {
       this.setState({
@@ -750,7 +772,7 @@
         tabBtn: btn,
         tabParam: {
           btn: btn,
-          data: data,
+          data: data[0] || null,
           primaryId: _primaryId,
           arr_field: this.state.arr_field
         }
@@ -768,6 +790,17 @@
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
+  }
+
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
+      if (nextProps.refreshTab.position === 'grid') {
+        this.reloadtable()
+      } else if (nextProps.refreshTab.position === 'view') {
+        this.reloadview()
+      }
+      this.props.refreshTabView('')
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -894,7 +927,7 @@
           </Modal>
           {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
         </div> : null}
-        {view === 'formtab' ? <FormTab MenuID={this.state.tabBtn.uuid} param={this.state.tabParam}/> : null}
+        {view === 'formtab' ? <FormTab MenuID={this.state.tabBtn.uuid} param={this.state.tabParam} refresh={this.refreshbyformtab}/> : null}
       </div>
     )
   }

--
Gitblit v1.8.0