king
2021-10-18 4b6a4e2f04f492d770573cf48ca52d4e748a086a
src/tabviews/verupmanage/subtabtable/index.jsx
@@ -29,7 +29,6 @@
    MenuID: PropTypes.string,        // 菜单Id
    SupMenuID: PropTypes.string,     // 上级菜单Id
    ContainerId: PropTypes.any,      // 三级菜单Container(html) ID
    handleTableId: PropTypes.func,   // 控制表格数据切换时,更新在主表中的id
    handleMainTable: PropTypes.func, // 刷新主表
    refreshtabs:PropTypes.any
  }
@@ -54,22 +53,15 @@
    popData: false,       // 弹框页面,所选的表格数据
    visible: false,       // 弹框显示隐藏控制
    pickup: false,         // 子表数据隐藏显示切换
    BID: '',
    BData: ''
  }
  /**
   * @description 上级菜单id变化时,刷新数据
   */
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (this.state.config && this.props.Tab.supMenu && !is(fromJS(this.props.BID), fromJS(nextProps.BID))) {
      this.setState({
        pageIndex: 1,
        selectedData: []
      }, () => {
        MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
        this.loadmaindata(nextProps.BID, 'refresh')
      })
    } else if (this.state.config && nextProps.refreshtabs && nextProps.refreshtabs.includes(this.props.Tab.uuid)) {
    if (this.state.config && nextProps.refreshtabs && nextProps.refreshtabs.includes(this.props.Tab.uuid)) {
      this.reloadtable()
    }
  }
@@ -78,7 +70,7 @@
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { Tab, BID } = this.props
    const { Tab, BID, BData } = this.props
    let config = tabConfig[this.props.MenuID]
@@ -127,6 +119,8 @@
    }
    this.setState({
      BID: BID || '',
      BData: BData || '',
      config: config,
      setting: config.setting,
      searchlist: config.search,
@@ -152,14 +146,12 @@
  /**
   * @description 子表数据加载
   */
  async loadmaindata (bid, type) {
    const { setting } = this.state
  async loadmaindata (type) {
    const { setting, BID } = this.state
    let param = ''
    let _BID = this.props.BID
    
    if (type === 'refresh') {
      _BID = bid
      if (!bid) { // 主表ID不存在时,不查询子表
      if (!BID) { // 主表ID不存在时,不查询子表
        this.setState({
          data: [],
          total: 0,
@@ -171,12 +163,10 @@
    }
    if (setting.interType === 'system') {
      param = this.getDefaultParam(_BID)
      param = this.getDefaultParam(BID)
    } else {
      param = this.getCustomParam(_BID)
      param = this.getCustomParam(BID)
    }
    this.handleTableId()
    let result = await Api.genericInterface(param)
    if (result.status) {
@@ -184,7 +174,7 @@
        data: result.data.map((item, index) => {
          item.key = index
          item.$$uuid = item[setting.primaryKey] || ''
          item.$$BID = _BID || ''
          item.$$BID = BID || ''
          return item
        }),
        total: result.total,
@@ -304,7 +294,7 @@
   * 含有初始不加载的页面,修改设置
   */
  refreshbysearch = (searches) => {
    MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
    MKEmitter.emit('resetTable', this.props.Tab.uuid) // 列表重置
    this.setState({
      loading: true,
      pageIndex: 1,
@@ -342,7 +332,7 @@
   * @description 表格刷新
   */
  reloadtable = () => {
    MKEmitter.emit('resetTable', this.props.MenuID + this.props.Tab.uuid) // 列表重置
    MKEmitter.emit('resetTable', this.props.Tab.uuid) // 列表重置
    this.setState({
      loading: true,
      pageIndex: 1,
@@ -404,13 +394,6 @@
  }
  /**
   * @description 表格Id变化
   */
  handleTableId = (type = this.props.Tab.uuid, id = '', data = '') => {
    this.props.handleTableId(type, id, data)
  }
  /**
   * @description 数据展开合并切换
   */
  pickupChange = () => {
@@ -421,13 +404,35 @@
    })
  }
  changeTableLine = (ContainerId, tableId, id, data) => {
    const { Tab } = this.props
    if (tableId !== Tab.supMenu) return
    this.setState({BData: data, BID: id})
    if (id !== this.state.BID) {
      MKEmitter.emit('resetTable', this.props.Tab.uuid) // 列表重置
      this.setState({
        pageIndex: 1,
        selectedData: []
      }, () => {
        this.loadmaindata('refresh')
      })
    }
  }
  UNSAFE_componentWillMount() {
    // 组件加载时,获取菜单数据
    this.loadconfig()
  }
  componentDidMount () {
    MKEmitter.addListener('changeTableLine', this.changeTableLine)
  }
  shouldComponentUpdate (nextProps, nextState) { // handleMainTable 函数判断时不相等
    return !is(fromJS({...this.props, handleMainTable: '', handleTableId: ''}), fromJS({...nextProps, handleMainTable: '', handleTableId: ''})) || !is(fromJS(this.state), fromJS(nextState))
    return !is(fromJS(this.state), fromJS(nextState))
  }
  /**
@@ -437,10 +442,11 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
  }
  render() {
    const { setting, searchlist, actions, columns, pickup, selectedData } = this.state
    const { BID, BData, setting, searchlist, actions, columns, pickup, selectedData } = this.state
    return (
      <div className="verup-subtable" id={'subtable' + this.props.MenuID}>
@@ -451,12 +457,12 @@
          <div className="sub-action">
            <SubAction
              type="sub"
              BID={BID}
              BData={BData}
              setting={setting}
              actions={actions}
              columns={columns}
              Tab={this.props.Tab}
              BID={this.props.BID}
              BData={this.props.BData}
              dict={this.state.dict}
              selectedData={selectedData}
              MenuID={this.props.SupMenuID}
@@ -482,7 +488,6 @@
              loading={this.state.loading}
              refreshdata={this.refreshbytable}
              buttonTrigger={() => {}}
              handleTableId={this.handleTableId}
              chgSelectData={this.changeSelectedData}
            />
          </div> : null