From 68f84129b685aa9539ac38ca1cf1f164c4d58074 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 26 一月 2021 13:54:26 +0800
Subject: [PATCH] 2021-01-26

---
 src/tabviews/subtable/index.jsx |   98 +++++++++++++++++++-----------------------------
 1 files changed, 39 insertions(+), 59 deletions(-)

diff --git a/src/tabviews/subtable/index.jsx b/src/tabviews/subtable/index.jsx
index 555c951..fd24de6 100644
--- a/src/tabviews/subtable/index.jsx
+++ b/src/tabviews/subtable/index.jsx
@@ -70,21 +70,19 @@
    * @description 涓婄骇鑿滃崟id鍙樺寲鏃讹紝鍒锋柊鏁版嵁
    */
   UNSAFE_componentWillReceiveProps(nextProps) {
-    if (this.state.config && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
+    const { config, setting } = this.state
+
+    if (config && setting && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
       MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1
       }, () => {
-        if (this.state.setting) {
-          this.loadmaindata()
-        }
+        this.loadData()
       })
-    } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      if (this.state.setting) {
-        this.setState({}, () => {
-          this.loadmaindata()
-        })
-      }
+    } else if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+      this.setState({}, () => {
+        this.loadData()
+      })
     }
   }
 
@@ -266,11 +264,10 @@
       let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉
       let hasReqFields = false
       config.search.forEach(field => {
-        if (field.required === 'true' && !field.initval) {
+        if (field.required !== 'true') return
+        hasReqFields = true
+        if (!field.initval) {
           valid = false
-        }
-        if (field.required === 'true') {
-          hasReqFields = true
         }
       })
 
@@ -327,7 +324,7 @@
         hasReqFields
       }, () => {
         if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 鍒濆鍖栧彲鍔犺浇
-          this.loadmaindata()
+          this.loadData()
         }
       })
     } else {
@@ -347,17 +344,20 @@
   
   loadData = () => {
     const { mainSearch, BID } = this.props
-    const { setting, search, loadCustomApi } = this.state
+    const { setting, search, loadCustomApi, hasReqFields } = this.state
 
     let searches = fromJS(search).toJS()
     if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
       searches = [...mainSearch, ...searches]
     }
 
-    let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
-    let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
-
+    let requireFields = []
+    if (hasReqFields) {
+      requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
+    }
+    
     if (requireFields.length > 0) {
+      let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
       let labels = requireFields.map(item => item.label)
       labels = Array.from(new Set(labels))
 
@@ -374,6 +374,7 @@
         statFValue: [],
         total: 0
       })
+      this.handleTableId()
       return
     } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
       notification.warning({
@@ -384,12 +385,17 @@
       return
     }
 
+    this.setState({
+      selectedData: []
+    })
+    this.handleTableId()
+
     if (setting.interType === 'custom' && loadCustomApi) {
       if (setting.execTime === 'once') {
         this.setState({loadCustomApi: false})
       }
 
-      this.loadOutResource()
+      this.loadOutResource(searches)
       if (setting.execType === 'async') {
         this.loadmaindata()
       }
@@ -398,10 +404,11 @@
     }
   }
 
-  loadOutResource = () => {
-    const { setting, search, BID } = this.state
+  loadOutResource = (searches) => {
+    const { BID } = this.props
+    const { setting } = this.state
 
-    let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType)
+    let param = UtilsDM.getPrevQueryParams(setting, searches, BID, this.props.menuType)
 
     if (setting.execType === 'sync') {
       this.setState({
@@ -464,7 +471,7 @@
         let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒'
 
         if (typeof(res) === 'string') {
-          error = res
+          error = res.replace(/'/ig, '"')
         }
 
         let _result = {
@@ -569,8 +576,8 @@
       
       param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
 
-      if (this.state.BID) {
-        param.BID = this.state.BID
+      if (this.props.BID) {
+        param.BID = this.props.BID
       }
 
       if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
@@ -579,8 +586,8 @@
     } else {
       param.func = 's_ex_result_back'
       param.s_ex_result = [...lineMap.values()].map((item, index) => ({
-        MenuID: this.state.config.MenuID,
-        MenuName: this.state.config.MenuName,
+        MenuID: this.props.MenuID,
+        MenuName: this.props.Tab.label,
         TableName: item.table,
         LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
         Sort: index + 1
@@ -629,39 +636,12 @@
       searches = [...mainSearch, ...searches]
     }
 
-    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
-    let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
-
-    if (requireFields.length > 0) {
-      let labels = requireFields.map(item => item.label)
-      labels = Array.from(new Set(labels))
-
-      notification.warning({
-        top: 92,
-        message: prex + this.state.dict['form.required.input'] + labels.join('銆�') + ' !',
-        duration: 3
-      })
-      return
-    }
-
-    if (this.props.Tab.supMenu && !BID) { // 涓昏〃ID涓嶅瓨鍦ㄦ椂锛屼笉鏌ヨ瀛愯〃
-      this.setState({
-        data: [],
-        selectedData: [],
-        statFValue: [],
-        total: 0
-      })
-      return
-    }
-
     this.setState({
       loading: true
     })
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
-
-    this.handleTableId()
 
     if (param.func === 'sPC_Get_TableData') {
       param.menuname = this.props.Tab.label || ''
@@ -836,7 +816,7 @@
       pageIndex: 1,
       search: searches,
     }, () => {
-      this.loadmaindata()
+      this.loadData()
     })
   }
 
@@ -857,7 +837,7 @@
       pageSize: pagination.pageSize,
       orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
     }, () => {
-      this.loadmaindata()
+      this.loadData()
     })
   }
 
@@ -870,11 +850,11 @@
       this.setState({
         pageIndex: 1
       }, () => {
-        this.loadmaindata()
+        this.loadData()
       })
     } else {
       MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 鍒楄〃閲嶇疆
-      this.loadmaindata()
+      this.loadData()
     }
   }
 

--
Gitblit v1.8.0