king
2021-08-26 e9c48bd7356462ba9257540b130a47a65ad1861d
src/tabviews/custom/components/card/balcony/index.jsx
@@ -1,10 +1,9 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Spin, notification } from 'antd'
import { Spin, notification, Checkbox } from 'antd'
import Api from '@/api'
// import Utils from '@/utils/utils.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
@@ -15,7 +14,6 @@
class BalconyComponent extends Component {
  static propTpyes = {
    BID: PropTypes.any,
    menu: PropTypes.object,
    data: PropTypes.array,
    config: PropTypes.object,
    menuType: PropTypes.any,
@@ -28,11 +26,14 @@
    loading: false,
    sync: false,
    data: {},
    show: true
    BData: null,
    syncData: [],
    show: true,
    checked: false
  }
  UNSAFE_componentWillMount () {
    const { data, BID, menu } = this.props
    const { data, BID } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
@@ -75,32 +76,11 @@
    let show = true
    let syncConfig = null
    if (_config.wrap.linkType === 'sync') {
      _config.wrap.syncModule = _config.wrap.syncModule.pop()
      let filterComponent = (components) => {
        components.forEach(item => {
          if (syncConfig) return
          if (item.type === 'tabs') {
            item.subtabs.forEach(tab => {
              filterComponent(tab.components)
            })
          } else if (item.type === 'group') {
            filterComponent(item.components)
          } else if (_config.wrap.syncModule === item.uuid) {
            syncConfig = {
              uuid: item.uuid,
              wrap: item.wrap,
              setting: item.setting,
              columns: item.columns
            }
          }
        })
      }
      syncConfig = _config.syncConfig
      filterComponent(menu.components)
      _config.elements = _config.elements.map(item => {
        if (item.eleType === 'button') {
          item.$syncModule = _config.wrap.syncModule
        if (item.eleType === 'button' || item.eleType === 'formula') {
          item.$sync = true
        }
        return item
      })
@@ -128,6 +108,7 @@
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('syncBalconyData', this.syncBalconyData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
  }
@@ -141,6 +122,7 @@
      return
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('syncBalconyData', this.syncBalconyData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
@@ -201,14 +183,22 @@
    }
  }
  resetParentParam = (MenuID, id) => {
  syncBalconyData = (menuId, data, checked) => {
    const { syncConfig } = this.state
    if (!syncConfig || syncConfig.uuid !== menuId) return
    this.setState({syncData: data, checked})
  }
  resetParentParam = (MenuID, id, data) => {
    const { config, syncConfig } = this.state
    if (syncConfig) {
      if (!syncConfig.setting.supModule || syncConfig.setting.supModule !== MenuID) return
  
      if (id !== this.state.BID) {
        this.setState({ BID: id }, () => {
        this.setState({ BID: id, BData: data }, () => {
          this.loadData()
        })
      }
@@ -220,7 +210,7 @@
      }
  
      if (id !== this.state.BID) {
        this.setState({ BID: id }, () => {
        this.setState({ BID: id, BData: data }, () => {
          this.loadData()
        })
      }
@@ -237,16 +227,16 @@
  async loadData () {
    const { menuType } = this.props
    const { config, arr_field, BID } = this.state
    const { config, arr_field, BID, BData } = this.state
    if (config.wrap.datatype === 'static') {
      this.setState({
        data: {$$BID: BID || ''},
        data: {$$BID: BID || '', $$BData: BData},
      })
      return
    } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: {$$BID: BID || ''},
        data: {$$BID: BID || '', $$BData: BData},
      })
      return
    }
@@ -264,6 +254,7 @@
    if (result.status) {
      let _data = result.data && result.data[0] ? result.data[0] : {}
      _data.$$BID = BID || ''
      _data.$$BData = BData
      this.setState({
        data: _data,
@@ -281,8 +272,14 @@
    }
  }
  checkAll = (e) => {
    const { syncConfig } = this.state
    MKEmitter.emit('mkCheckAll', syncConfig.uuid, e.target.checked)
  }
  render() {
    const { config, loading, data, show, syncConfig } = this.state
    const { config, loading, data, show, syncConfig, syncData, checked } = this.state
    return (
      <div className={'custom-balcony-box' + (!show ? ' hidden' : '')} style={config.style}>
@@ -292,7 +289,8 @@
            <Spin />
          </div> : null
        }
        <CardCellComponent data={data} cards={syncConfig || config} cardCell={config} elements={config.elements}/>
        {config.wrap.checkAll === 'show' ? <div className="check-all"><Checkbox checked={checked} onChange={this.checkAll}>全选</Checkbox></div> : null}
        <CardCellComponent data={data} syncData={syncData || []} cards={syncConfig || config} cardCell={config} elements={config.elements}/>
      </div>
    )
  }