king
2021-11-17 fe5dc955911feb6c376298e618de673da166fcab
src/tabviews/subtabtable/index.jsx
@@ -28,7 +28,6 @@
    BID: PropTypes.string,           // 上级数据ID
    BData: PropTypes.any,            // 上级数据
    MenuID: PropTypes.string,        // 菜单Id
    mainSearch: PropTypes.any,       // 主表搜索条件
    SupMenuID: PropTypes.string,     // 上级菜单Id
  }
@@ -315,13 +314,9 @@
  }
  loadData = () => {
    const { mainSearch } = this.props
    const { setting, search, hasReqFields, loadCustomApi } = this.state
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
    }
    if (hasReqFields) {
      let requireFields = searches.filter(item => item.required && item.value === '')
@@ -532,13 +527,10 @@
   * @description 子表数据加载
   */
  async loadmaindata () {
    const { mainSearch, BID } = this.props
    const { 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
@@ -644,6 +636,79 @@
  }
  /**
   * @description 获取单行数据
   */
  async loadmainLinedata (id) {
    const { BID } = this.props
    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
    let searches = fromJS(search).toJS()
    this.setState({
      loading: true
    })
    let _orderBy = orderBy || setting.order
    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 搜索条件改变时,重置表格数据
   * 含有初始不加载的页面,修改设置
   */
@@ -707,20 +772,15 @@
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, btnId) => {
    const { Tab, mainSearch, MenuID } = this.props
    const { Tab, 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]
    }
    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
      arr_field: arr_field,
      orderBy: orderBy || setting.order,
      search: searches,
      search: search,
      menuName: Tab.label
    })
  }
@@ -731,12 +791,16 @@
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn) => {
  refreshByButtonResult = (menuId, position, btn, id, lines) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    if (position === 'line' && lines && lines.length === 1) {
      this.loadmainLinedata(lines[0].$$uuid)
    } else {
    this.reloadtable(btn)
    }
    MKEmitter.emit('refreshPopButton', this.props.Tab.uuid)
  }