king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
src/tabviews/subtable/index.jsx
@@ -8,18 +8,18 @@
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import UtilsUpdate from '@/utils/utils-update.js'
import { modifyTabview } from '@/store/action'
import SubSearch from '@/tabviews/zshare/topSearch'
import { updateSubTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import NotFount from '@/components/404'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const { TabPane } = Tabs
const SubSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
const SubAction = asyncComponent(() => import('@/tabviews/zshare/actionList'))
const SubTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable'))
const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
@@ -35,10 +35,6 @@
    mainSearch: PropTypes.any,       // 主表搜索条件
    ContainerId: PropTypes.any,      // 三级菜单Container(html) ID
    handleTableId: PropTypes.func,   // 控制表格数据切换时,更新在主表中的id
    handleMainTable: PropTypes.func, // 刷新主表
    refreshtabs: PropTypes.any,      // 标签刷新控制
    userConfig: PropTypes.any,       // 用户自定义设置
    triggerBtn: PropTypes.any        // 快捷键或点击行按钮触发事件
  }
  state = {
@@ -50,12 +46,10 @@
    searchlist: null,     // 搜索条件
    actions: null,        // 按钮集
    columns: null,        // 显示列
    logcolumns: null,     // 日志中显示的列信息 (增加至全部列,除去合并列)
    arr_field: '',        // 使用 sPC_Get_TableData 时的查询字段集
    setting: null,        // 页面全局设置:数据源、按钮及显示列固定、主键等
    data: null,           // 列表数据集
    data: [],             // 列表数据集
    selectedData: [],     // 已选表格数据
    resetTable: false,    // 表格重置,值在true与false之间切换,切换时表格重置
    total: 0,             // 总数
    loading: false,       // 列表数据加载中
    pageIndex: 1,         // 页码
@@ -63,44 +57,31 @@
    orderBy: '',          // 排序
    search: [],           // 搜索条件数组,使用时需分场景处理
    pickup: false,        // 子表数据隐藏显示切换
    triggerBtn: null,     // 按钮触发
    chartId: '',          // 展开图表ID
    statFields: [],       // 合计字段
    statFValue: []        // 合计值
    statFValue: [],       // 合计值
    absFields: [],        // 绝对值字段
    loadCustomApi: true,  // 加载外部资源
    hasReqFields: false
  }
  /**
   * @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,
        selectedData: [],
        resetTable: !this.state.resetTable,
        pageIndex: 1
      }, () => {
        if (this.state.setting) {
          this.loadmaindata(nextProps.BID, 'refresh')
          this.getStatFieldsValue(nextProps.BID, 'refresh')
        }
        this.loadData()
      })
    } else if (this.state.config && nextProps.refreshtabs && nextProps.refreshtabs.includes(this.props.Tab.uuid)) {
      this.reloadtable()
    } else if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.parentId === this.props.Tab.uuid) {
      let trigger = nextProps.triggerBtn
      trigger.parentId = this.props.MenuID
      this.setState({
        triggerBtn: trigger
    } else if (setting && !this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        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()
          this.getStatFieldsValue()
        })
      }
    }
  }
@@ -108,7 +89,7 @@
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { permAction, permMenus, Tab, BID, userConfig } = this.props
    const { permAction, permMenus, Tab, BID } = this.props
    let param = {
      func: 'sPC_Get_LongParam',
@@ -120,6 +101,8 @@
      try { // 配置信息解析
        config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
        config.setting.MenuName = Tab.label
        config.setting.$name = Tab.label
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
@@ -146,43 +129,34 @@
      let _arrField = []     // 字段集
      let _columns = []      // 显示列
      let _logcolumns = []   // 日志显示列
      let _hideCol = []      // 隐藏及合并列中字段的uuid集
      let colMap = new Map()
      let statFields = []    // 合计字段信息
      let absFields = []     // 绝对值字段
      // 版本兼容
      config = UtilsUpdate.updateSubTable(config)
      config = updateSubTable(config)
      // 权限过滤
      if (this.props.menuType !== 'HS') {
        config.action = config.action.filter(item => permAction[item.uuid])
      }
      // 字段权限黑名单
      config.search = config.search.map(item => {
        item.oriInitval = item.initval
        if (!item.blacklist || item.blacklist.length === 0) return item
      config.search = Utils.initSearchVal(config.search)
        let _black = item.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0) {
          item.Hide = 'true'
      let hasReqFields = false
      config.search.forEach(field => {
        if (field.required) {
          hasReqFields = true
        }
        return item
      })
      // 字段权限黑名单
      let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
      config.columns = config.columns.map(col => {
        if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return col
        let _black = col.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0) {
        if (!col.blacklist || col.blacklist.length === 0) return col
        if (col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
          col.Hide = 'true'
        }
@@ -193,16 +167,7 @@
      config.charts = config.charts.filter(item => {
        if (item.Hide === 'true') return false
        if (!item.blacklist || item.blacklist.length === 0) return true
        let _black = item.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0 || item.Hide === 'true') {
          return false
        } else {
          return true
        }
        return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0
      })
      if (config.charts.length <= 1) {
@@ -211,49 +176,28 @@
      let chartId = config.charts[0] ? config.charts[0].uuid : ''
      if (userConfig) {
        config.setting.tableType = userConfig.setting.tableType
        config.action = config.action.map(item => {
          if (userConfig.action[item.uuid]) {
            delete userConfig.action[item.uuid].label
            item = {...item, ...userConfig.action[item.uuid]}
          }
          if (item.execMode) {
            item.OpenType = 'funcbutton'
          }
          if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify && item.printer) {
            item.verify.defaultPrinter = item.printer.defaultPrinter || ''
            if (item.verify.printerTypeList && item.printer.printerList) {
              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
                cell.printer = item.printer.printerList[cell.Value] || ''
                return cell
              })
            }
          }
          return item
        })
      }
      // 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
      config.columns.forEach(col => {
        if (col.field) {
          _arrField.push(col.field)
          _logcolumns.push(col)
          if (col.linkmenu && col.linkmenu.length > 0) {
            let menu_id = col.linkmenu.slice(-1)[0]
            col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
          } else {
            col.linkThdMenu = ''
          }
          col.nameField && _arrField.push(col.nameField) // 链接名字段
          if (col.Hide !== 'true' && col.type === 'number' && col.sum === 'true') {
            statFields.push(col)
          }
          if (col.format === 'abs') {
            absFields.push(col.field)
          }
        }
        if (col.type === 'colspan' && col.sublist) { // 筛选隐藏列
          _hideCol = _hideCol.concat(col.sublist)
        } else if (col.Hide === 'true') {
          _hideCol.push(col.uuid)
        }
        colMap.set(col.uuid, col)
      })
@@ -262,22 +206,24 @@
      config.columns.forEach((col, index) => {
        if (_hideCol.includes(col.uuid)) return
        if (col.linkThdMenu && !permMenus[col.linkThdMenu.MenuID]) {
          col.linkThdMenu = ''
        }
        col.sort = index
        if (col.type === 'colspan' && col.sublist) {
          let _col = JSON.parse(JSON.stringify(col))
          let subColumn = []
          _col.sublist.forEach(sub => {
        if (col.type === 'colspan') {
          if (col.unfold !== 'true') { // 不展开为旧版合并列
            col.type = 'old_colspan'
          }
          let _col = fromJS(col).toJS()
          let subcols = []
          _col.sublist && _col.sublist.forEach(sub => {
            if (colMap.has(sub)) {
              subColumn.push(colMap.get(sub))
              subcols.push(colMap.get(sub))
            }
          })
          _col.subColumn = subColumn
          _columns.push(_col)
          if (subcols.length > 0) {
            _col.subcols = subcols
            _columns.push(_col)
          }
        } else {
          _columns.push(col)
        }
@@ -287,10 +233,23 @@
      let _operations = []  // 操作列按钮(存在时)
      config.action.forEach(item => {
        if (item.execMode) {
          item.OpenType = 'funcbutton'
        }
        item.logLabel = Tab.label + '-' + item.label // 用于sPC_TableData_InUpDe记录操作按钮
        item.$menuId = this.props.MenuID
        if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify) { // 打印机设置
          let _item = window.GLOB.UserCacheMap.get(Tab.uuid + item.uuid)
          if (_item) {
            item.verify.defaultPrinter = _item.printer || ''
            if (item.verify.printerTypeList && _item.printerList) {
              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
                cell.printer = _item.printerList[cell.Value] || ''
                return cell
              })
            }
          }
        }
        if (item.position === 'toolbar') {
          _actions.push(item)
        } else if (item.position === 'grid') {
@@ -303,36 +262,13 @@
        _columns.push(config.gridBtn)
      }
      let valid = true // 搜索条件必填验证
      config.search.forEach(field => {
        if (field.required === 'true' && !field.initval) {
          valid = false
        }
      })
      // 添加用户显示列设置
      if (userConfig) {
        _columns = _columns.map(item => {
          if (userConfig.columns[item.uuid]) {
            delete userConfig.columns[item.uuid].label
            item = {...item, ...userConfig.columns[item.uuid]}
          }
          return item
        })
        _columns.sort((pre, next) => {
          return pre.sort - next.sort
        })
      }
      config.setting.tabType = 'sub'
      // 数据源信息预处理
      config.setting.laypage = config.setting.laypage !== 'false'     // 是否分页,转为boolean 统一格式
      config.setting.execute = config.setting.default !== 'false'     // 默认sql是否执行,转为boolean 统一格式
      config.setting.customScript = ''                                // 自定义脚本
      if (config.setting.interType === 'system') {
      if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) {
        if (config.setting.scripts && config.setting.scripts.length > 0) {
          let _customScript = ''
          config.setting.scripts.forEach(item => {
@@ -353,7 +289,7 @@
          config.setting.dataresource = '(' + config.setting.dataresource + ') tb'
        }
  
        if (this.props.dataManager) { // 数据权限
        if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
          config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*')
          config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/')
          config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*')
@@ -362,24 +298,44 @@
          config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
          config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '')
        }
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
        let city = sessionStorage.getItem('city') || ''
        if (sessionStorage.getItem('isEditState') === 'true') {
          userName = sessionStorage.getItem('CloudUserName') || ''
          fullName = sessionStorage.getItem('CloudFullName') || ''
        }
        let regs = [
          { reg: /@userName@/ig, value: `'${userName}'` },
          { reg: /@fullName@/ig, value: `'${fullName}'` },
          { reg: /@login_city@/ig, value: `'${city}'` }
        ]
        regs.forEach(cell => {
          config.setting.dataresource = config.setting.dataresource.replace(cell.reg, cell.value)
          config.setting.customScript = config.setting.customScript.replace(cell.reg, cell.value)
        })
      }
      this.setState({
        loadingview: false,
        chartId: chartId,
        config: config,
        statFields: statFields,
        chartId,
        config,
        absFields,
        statFields,
        setting: config.setting,
        searchlist: config.search,
        actions: _actions,
        columns: _columns,
        logcolumns: _logcolumns,
        arr_field: _arrField.join(','),
        search: Utils.initMainSearch(config.search) // 搜索条件初始化(含有时间格式,需要转化)
        search: Utils.initMainSearch(config.search),
        hasReqFields
      }, () => {
        if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 初始化可加载
          this.loadmaindata()
          this.getStatFieldsValue()
        if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode)) { // 初始化可加载
          this.loadData()
        }
      })
    } else {
@@ -396,60 +352,275 @@
      })
    }
  }
  loadData = () => {
    const { mainSearch, BID } = this.props
    const { setting, search, loadCustomApi, hasReqFields } = this.state
  /**
   * @description 子表数据加载
   */
  async loadmaindata (bid, type) {
    const { mainSearch } = this.props
    const { setting, arr_field, search, orderBy, pageIndex, pageSize } = this.state
    let _BID = this.props.BID
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      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))
    if (hasReqFields) {
      let requireFields = searches.filter(item => item.required && item.value === '')
      if (requireFields.length > 0) {
        this.setState({
          loading: false
        })
        return
      }
    }
    if (this.props.Tab.supMenu && !BID) { // 主表ID不存在时,不查询子表
      this.setState({
        data: [],
        selectedData: [],
        statFValue: [],
        total: 0
      })
      this.handleTableId()
      return
    } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
      notification.warning({
        top: 92,
        message: prex + this.state.dict['form.required.input'] + labels.join('、') + ' !',
        message: '未设置正式系统地址!',
        duration: 3
      })
      return
    }
    if (type === 'refresh') {
      if (!bid) { // 主表ID不存在时,不查询子表
        this.setState({
          data: [],
          total: 0
        })
        return
    this.setState({
      selectedData: []
    })
    this.handleTableId()
    if (setting.interType === 'custom' && loadCustomApi) {
      if (setting.execTime === 'once') {
        this.setState({loadCustomApi: false})
      }
      this.loadOutResource(searches)
      if (setting.execType === 'async') {
        this.loadmaindata()
      }
    } else {
      this.loadmaindata()
    }
  }
  loadOutResource = (searches) => {
    const { BID } = this.props
    const { setting } = this.state
    let param = UtilsDM.getPrevQueryParams(setting, searches, BID, this.props.menuType)
    if (setting.execType === 'sync') {
      this.setState({
        loading: true
      })
    }
    Api.genericInterface(param).then(res => {
      if (res.status) {
        if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) {
          this.loadmaindata()
        } else {
          this.customOuterRequest(res)
        }
      } else {
        _BID = bid
        this.setState({
          loading: false
        })
        notification.error({
          top: 92,
          message: res.message,
          duration: 10
        })
      }
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  customOuterRequest = (result) => {
    const { setting } = this.state
    let url = ''
    if (window.GLOB.systemType === 'production') {
      url = setting.proInterface
    } else {
      url = setting.interface
    }
    let mkey = result.mk_api_key || ''
    delete result.mk_ex_invoke
    delete result.status
    delete result.message
    delete result.ErrCode
    delete result.ErrMesg
    delete result.mk_api_key
    let param = {}
    Object.keys(result).forEach(key => {
      key = key.replace(/^mk_/ig, '')
      param[key] = result[key]
    })
    Api.directRequest(url, setting.method, param, setting.cross).then(res => {
      if (typeof(res) !== 'object') {
        let error = '未知的返回结果!'
        if (typeof(res) === 'string') {
          error = res.replace(/'/ig, '"')
        }
        let _result = {
          mk_api_key: mkey,
          $ErrCode: 'E',
          $ErrMesg: error
        }
        this.customCallbackRequest(_result)
      } else {
        if (Array.isArray(res)) {
          res = { data: res }
        }
        res.mk_api_key = mkey
        this.customCallbackRequest(res)
      }
    }, (e) => {
      let _result = {
        mk_api_key: mkey,
        $ErrCode: 'E',
        $ErrMesg: e && e.statusText ? e.statusText : ''
      }
      this.customCallbackRequest(_result)
    })
  }
  customCallbackRequest = (result) => {
    const { setting } = this.state
    let errSql = ''
    if (result.$ErrCode === 'E') {
      errSql = `
        set @ErrorCode='E'
        set @retmsg='${result.$ErrMesg}'
      `
      delete result.$ErrCode
      delete result.$ErrMesg
    }
    let lines = UtilsDM.getCallBackSql(setting, result)
    let param = {}
    if (setting.callbackType === 'script') { // 使用自定义脚本
      let sql = lines.map(item => (`
        ${item.insert}
        ${item.selects.join(` union all
        `)}
      `))
      sql = sql.join('')
      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
      if (this.props.BID) {
        param.BID = this.props.BID
      }
      if (this.props.menuType === 'HS') { // 函数 sPC_TableData_InUpDe 云端验证
        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
      }
    } else {
      param.func = 's_ex_result_back'
      param.s_ex_result = lines.map((item, index) => ({
        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
      }))
      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
        let sql = lines.map(item => (`
          ${item.insert}
          ${item.selects.join(` union all
          `)}
        `))
        sql = sql.join('')
        console.info(sql.replace(/\n\s{10}/ig, '\n'))
      }
    }
    Api.genericInterface(param).then(res => {
      if (res.status) {
        this.loadmaindata()
      } else {
        this.setState({
          loading: false
        })
        notification.error({
          top: 92,
          message: res.message,
          duration: 10
        })
      }
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  /**
   * @description 子表数据加载
   */
  async loadmaindata () {
    const { mainSearch, BID } = this.props
    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
    }
    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.props.dataManager)
    this.handleTableId()
    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
    let result = await Api.genericInterface(param)
    this.getStatFieldsValue(searches)
    if (result.status) {
      let start = 1
      if (setting.laypage) {
        start = pageSize * (pageIndex - 1) + 1
      }
      this.setState({
        data: result.data.map((item, index) => {
          if (absFields.length) {
            absFields.forEach(field => {
              if (!item[field]) return
              if (isNaN(Math.abs(item[field]))) return
              item[field] = Math.abs(item[field])
            })
          }
          item.key = index
          item.$$uuid = item[setting.primaryKey] || ''
          item.$$BID = BID || ''
          item.$Index = start + index + ''
          return item
        }),
        total: result.total,
@@ -457,6 +628,7 @@
        loading: false
      })
    } else {
      let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
      this.setState({
        loading: false
      })
@@ -470,38 +642,92 @@
  }
  /**
   * @description 获取合计字段值
   */
  getStatFieldsValue = (bid, type) => {
    const { mainSearch } = this.props
    const { setting, search, orderBy, statFields } = this.state
   * @description 获取单行数据
   */
  async loadmainLinedata (id) {
    const { mainSearch, BID } = this.props
    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
    let _BID = this.props.BID
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
    }
    if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return
    let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
    if (requireFields.length > 0) {
      return
    }
    if (type === 'refresh') {
      if (!bid) { // 主表ID不存在时,不查询子表合计值
        this.setState({
          statFValue: []
        })
        return
      } else {
        _BID = bid
      }
    }
    this.setState({
      loading: true
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, _BID, this.props.menuType, this.props.dataManager)
    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
    let result = await Api.genericInterface(param)
    if (result.status) {
      let data = fromJS(this.state.data).toJS()
      let selectedData = fromJS(this.state.selectedData).toJS()
      if (result.data && result.data[0]) {
        let _data = result.data[0] || {}
        if (absFields.length) {
          absFields.forEach(field => {
            if (!_data[field]) return
            if (isNaN(Math.abs(_data[field]))) return
            _data[field] = Math.abs(_data[field])
          })
        }
        _data.$$uuid = _data[setting.primaryKey] || ''
        _data.$$BID = BID || ''
        try {
          data = data.map(item => {
            if (item.$$uuid === _data.$$uuid) {
              _data.key = item.key
              _data.$Index = item.$Index
              return _data
            } else {
              return item
            }
          })
          selectedData = selectedData.map(item => {
            if (_data.$$uuid === item.$$uuid) {
              return _data
            }
            return item
          })
        } catch (e) {
          console.warn('数据查询错误')
        }
      }
      this.setState({
        data,
        selectedData,
        loading: false
      })
    } else {
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
    }
  }
  /**
   * @description 获取合计字段值
   */
  getStatFieldsValue = (searches) => {
    const { BID } = this.props
    const { setting, orderBy, statFields } = this.state
    if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType)
    Api.genericInterface(param).then(res => {
      if (res.status) {
@@ -541,14 +767,12 @@
   * 含有初始不加载的页面,修改设置
   */
  refreshbysearch = (searches) => {
    MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
    this.setState({
      pageIndex: 1,
      search: searches,
      resetTable: !this.state.resetTable,
      selectedData: [],
    }, () => {
      this.loadmaindata()
      this.getStatFieldsValue()
      this.loadData()
    })
  }
@@ -565,83 +789,51 @@
    }
    this.setState({
      selectedData: [],
      pageIndex: pagination.current,
      pageSize: pagination.pageSize,
      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
    }, () => {
      this.loadmaindata()
      this.loadData()
    })
  }
  /**
   * @description 表格刷新
   */
  reloadtable = () => {
    this.setState({
      pageIndex: 1,
      selectedData: [],
      resetTable: !this.state.resetTable
    }, () => {
      this.loadmaindata()
      this.getStatFieldsValue()
    })
  }
  /**
   * @description 页面刷新,重新获取配置
   */
  reloadview = () => {
    this.setState({ loadingview: true, viewlost: false, lostmsg: '', config: null, searchlist: null, actions: null,
      columns: null, arr_field: '', setting: null, data: null, total: 0, loading: false, pageIndex: 1, pageSize: 10,
      orderBy: '', search: [], triggerBtn: null
    }, () => {
      this.loadconfig()
    })
  }
  /**
   * @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项
   */
  refreshbyaction = (position) => {
    const { Tab } = this.props
    if (position === 'grid') {
      this.reloadtable()
    } else if (position === 'view') {
      this.reloadview()
    } else if (position === 'maingrid') {
      if (Tab.isTreeNode) {
        this.reloadtable()
      }
      this.props.handleMainTable('maingrid')
    } else if (position === 'equaltab') {
      this.reloadtable()
      this.props.handleMainTable('equaltab')
    } else if (position === 'mainline') {
      this.reloadtable()
      this.props.handleMainTable('mainline')
  reloadtable = (btn) => {
    if (!btn || btn.resetPageIndex !== 'false') {
      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
      this.setState({
        pageIndex: 1
      }, () => {
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid, 'false') // 列表重置
      this.loadData()
    }
  }
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  getexceloutparam = () => {
    const { Tab, mainSearch } = this.props
  queryModuleParam = (menuId, btnId) => {
    const { Tab, mainSearch, MenuID } = this.props
    const { arr_field, orderBy, search, setting} = this.state
    if (MenuID !== menuId) return
    let searches = search
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...search]
    }
    return {
    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
      arr_field: arr_field,
      orderBy: orderBy || setting.order,
      search: searches,
      menuName: Tab.label
    }
    })
  }
  /**
@@ -649,20 +841,6 @@
   */
  changeSelectedData = (selectedData) => {
    this.setState({selectedData})
  }
  /**
   * @description 表格中,按钮触发事件传递
   */
  buttonTrigger = (btn, record) => {
    this.setState({
      triggerBtn: {
        uuid: new Date().getTime(),
        parentId: this.props.MenuID,
        button: btn,
        data: record
      }
    })
  }
  /**
@@ -690,13 +868,64 @@
    this.setState({chartId: uuid})
  }
  reloadData = (menuId, id) => { // Id存在时,刷新行
    const { MenuID } = this.props
    if (menuId.indexOf(MenuID) === -1) return
    if (id === 'empty') return
    if (!id) {
      this.reloadtable()
    } else {
      this.loadmainLinedata(id)
    }
  }
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    const { Tab, SupMenuID, BID } = this.props
    if (position === 'grid' || position === 'view') {
      this.reloadtable(btn)
    } else if (position === 'maingrid' || position === 'mainline') {
      this.reloadtable(btn)
      if (Tab.supMenu === 'mainTable') {
        MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty'))   // 主表重置
      } else if (Tab.supMenu) {
        MKEmitter.emit('reloadData', Tab.supMenu, (BID || 'empty')) // 主表重置
      } else if (!Tab.supMenu && Tab.level === 0) {
        MKEmitter.emit('reloadData', SupMenuID, (BID || 'empty'))   // 树形结构,0级标签
      }
    } else if (position === 'equaltab') {
      this.reloadtable(btn)
      if (Tab.equalTab && Tab.equalTab.length > 0) {
        MKEmitter.emit('reloadData', Tab.equalTab.join(',')) // 同级标签重置
      }
    }
  }
  UNSAFE_componentWillMount() {
    // 组件加载时,获取菜单数据
    this.loadconfig()
  }
  shouldComponentUpdate (nextProps, nextState) { // handleMainTable 函数判断时不相等
    return !is(fromJS({...this.props, handleMainTable: '', handleTableId: ''}), fromJS({...nextProps, handleMainTable: '', handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState))
  shouldComponentUpdate (nextProps, nextState) { // handleTableId 函数判断时不相等
    return !is(fromJS({...this.props, handleTableId: ''}), fromJS({...nextProps, handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
  }
  /**
@@ -706,23 +935,19 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
  render() {
    const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, triggerBtn, chartId, selectedData } = this.state
    const { config, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, chartId, selectedData } = this.state
    return (
      <div className="subtable" id={'subtable' + this.props.MenuID}>
        {loadingview && <Spin />}
        {searchlist && searchlist.length > 0 ?
          <SubSearch
            BID={this.props.BID}
            dict={this.state.dict}
            searchlist={searchlist}
            menuType={this.props.menuType}
            dataManager={this.props.dataManager}
            refreshdata={this.refreshbysearch}
          /> : null
        {searchlist && searchlist.length ?
          <SubSearch BID={this.props.BID} setting={setting} searchlist={searchlist} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
        }
        {config ? <Row className="chart-view" gutter={16}>
          {/* 视图组 */}
@@ -741,40 +966,35 @@
                    <SubAction
                      setting={setting}
                      actions={actions}
                      columns={columns}
                      Tab={this.props.Tab}
                      BID={this.props.BID}
                      triggerBtn={triggerBtn}
                      BData={this.props.BData}
                      MenuID={this.props.MenuID}
                      selectedData={selectedData}
                      logcolumns={this.state.logcolumns}
                      refreshdata={this.refreshbyaction}
                      ContainerId={this.props.ContainerId}
                      operations={config.gridBtn.operations || []}
                      getexceloutparam={this.getexceloutparam}
                    />
                  </div>
                  <div className="subtable-box">
                    {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
                      <Switch title="收起" className="subtable-pickup" checkedChildren="开" unCheckedChildren="关" defaultChecked={pickup} onChange={this.pickupChange} /> : null
                      <Switch title="收起" className="subtable-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> : null
                    }
                    <SubTable
                      tableId={this.props.Tab.uuid}
                      pickup={pickup}
                      config={config}
                      setting={setting}
                      columns={columns}
                      pageSize={pageSize}
                      dict={this.state.dict}
                      data={this.state.data}
                      BData={this.props.BData}
                      total={this.state.total}
                      MenuID={this.props.MenuID}
                      loading={this.state.loading}
                      statFValue={this.state.statFValue}
                      ContainerId={this.props.ContainerId}
                      refreshdata={this.refreshbytable}
                      buttonTrigger={this.buttonTrigger}
                      handleTableId={this.handleTableId}
                      resetTable={this.state.resetTable}
                      chgSelectData={this.changeSelectedData}
                    />
                  </div>
@@ -782,10 +1002,11 @@
              )
            } else if (item.chartType === 'card') {
              return (
                <Col span={item.width} key={item.uuid}>
                <Col className="card-view" span={item.width} key={item.uuid}>
                  <CardComponent
                    plot={item}
                    config={config}
                    columns={columns}
                    Tab={this.props.Tab}
                    BID={this.props.BID}
                    BData={this.props.BData}
@@ -793,10 +1014,7 @@
                    MenuID={this.props.MenuID}
                    loading={this.state.loading}
                    tableId={this.props.Tab.uuid}
                    logcolumns={this.state.logcolumns}
                    refreshdata={this.refreshbyaction}
                    handleTableId={this.handleTableId}
                    getexceloutparam={this.getexceloutparam}
                  />
                </Col>
              )
@@ -809,7 +1027,6 @@
                    BID={this.props.BID}
                    Tab={this.props.Tab}
                    data={this.state.data}
                    getexceloutparam={this.getexceloutparam}
                    loading={this.state.loading}
                  />
                </Col>
@@ -825,19 +1042,14 @@
const mapStateToProps = (state) => {
  return {
    tabviews: state.tabviews,
    menuType: state.editLevel,
    permAction: state.permAction,
    permRoles: state.permRoles,
    permMenus: state.permMenus,
    dataManager: state.dataManager,
  }
}
const mapDispatchToProps = (dispatch) => {
  return {
    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
  }
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(SubTabViewTable)