| | |
| | | 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' |
| | |
| | | class BalconyComponent extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, |
| | | menu: PropTypes.object, |
| | | data: PropTypes.array, |
| | | config: PropTypes.object, |
| | | menuType: PropTypes.any, |
| | |
| | | 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() |
| | | |
| | |
| | | let show = true |
| | | let syncConfig = null |
| | | if (_config.wrap.linkType === 'sync') { |
| | | _config.wrap.syncModule = _config.wrap.syncModule.pop() |
| | | syncConfig = _config.syncConfig |
| | | |
| | | 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 |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | 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 |
| | | }) |
| | |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('reloadData', this.reloadData) |
| | | MKEmitter.addListener('syncBalconyData', this.syncBalconyData) |
| | | MKEmitter.addListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | } |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('reloadData', this.reloadData) |
| | | MKEmitter.removeListener('syncBalconyData', this.syncBalconyData) |
| | | MKEmitter.removeListener('resetSelectLine', this.resetParentParam) |
| | | MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | 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() |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | if (id !== this.state.BID) { |
| | | this.setState({ BID: id }, () => { |
| | | this.setState({ BID: id, BData: data }, () => { |
| | | this.loadData() |
| | | }) |
| | | } |
| | |
| | | |
| | | 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 |
| | | } |
| | |
| | | if (result.status) { |
| | | let _data = result.data && result.data[0] ? result.data[0] : {} |
| | | _data.$$BID = BID || '' |
| | | _data.$$BData = BData |
| | | |
| | | this.setState({ |
| | | data: _data, |
| | |
| | | } |
| | | } |
| | | |
| | | 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}> |
| | |
| | | <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> |
| | | ) |
| | | } |