import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Spin, notification, Checkbox } from 'antd'
|
|
import Api from '@/api'
|
import UtilsDM from '@/utils/utils-datamanage.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
const CardCellComponent = asyncComponent(() => import('../cardcellList'))
|
|
class BalconyComponent extends Component {
|
static propTpyes = {
|
BID: PropTypes.any,
|
data: PropTypes.array,
|
config: PropTypes.object,
|
menuType: PropTypes.any,
|
}
|
|
state = {
|
BID: '',
|
config: null,
|
syncConfig: null,
|
loading: false,
|
sync: false,
|
data: {},
|
BData: null,
|
syncData: [],
|
show: true,
|
checked: false
|
}
|
|
UNSAFE_componentWillMount () {
|
const { data, BID } = this.props
|
let _config = fromJS(this.props.config).toJS()
|
let _cols = new Map()
|
|
let _data = {}
|
let _sync = false
|
|
if (_config.setting && _config.wrap.datatype !== 'static') {
|
_sync = _config.setting.sync === 'true'
|
|
if (_sync && data) {
|
_data = data[_config.dataName] || {}
|
if (_data && Array.isArray(_data)) {
|
_data = _data[0] || {}
|
}
|
_sync = false
|
}
|
} else {
|
_data = {}
|
}
|
|
if (_data) {
|
_data.$$BID = BID || ''
|
}
|
|
_config.columns.forEach(item => {
|
_cols.set(item.field, item)
|
})
|
|
if (_config.wrap.position === 'fixed') {
|
_config.style.position = 'fixed'
|
_config.style.zIndex = 2
|
_config.style.left = _config.wrap.left || ''
|
_config.style.right = _config.wrap.right || ''
|
_config.style.top = _config.wrap.top || ''
|
_config.style.bottom = _config.wrap.bottom || ''
|
_config.style.transform = _config.wrap.transform || ''
|
_config.style.width = _config.wrap.realwidth || ''
|
}
|
|
let show = true
|
let syncConfig = null
|
if (_config.wrap.linkType === 'sync') {
|
syncConfig = _config.syncConfig
|
|
_config.elements = _config.elements.map(item => {
|
if (item.eleType === 'button' || item.eleType === 'formula') {
|
item.$sync = true
|
}
|
return item
|
})
|
} else if (_config.wrap.linkType === 'sup') {
|
_config.wrap.supModule = _config.wrap.supModule.pop()
|
if (_config.wrap.supControl === 'hidden') {
|
show = false
|
}
|
}
|
|
this.setState({
|
show,
|
syncConfig,
|
sync: _sync,
|
data: _data,
|
BID: BID || '',
|
config: _config,
|
arr_field: _config.columns.map(col => col.field).join(','),
|
}, () => {
|
if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
|
this.loadData()
|
}
|
})
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('reloadData', this.reloadData)
|
MKEmitter.addListener('syncBalconyData', this.syncBalconyData)
|
MKEmitter.addListener('resetSelectLine', this.resetParentParam)
|
MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('reloadData', this.reloadData)
|
MKEmitter.removeListener('syncBalconyData', this.syncBalconyData)
|
MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
|
MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
|
}
|
|
/**
|
* @description 图表数据更新,刷新内容
|
*/
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
const { sync, config, BID } = this.state
|
|
if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
|
let _data = {}
|
if (nextProps.data && nextProps.data[config.dataName]) {
|
_data = nextProps.data[config.dataName]
|
if (_data && Array.isArray(_data)) {
|
_data = _data[0]
|
}
|
}
|
|
if (_data) {
|
_data.$$BID = BID || ''
|
}
|
|
this.setState({sync: false, data: _data})
|
}
|
}
|
|
/**
|
* @description 按钮执行完成后页面刷新
|
* @param {*} menuId // 菜单Id
|
* @param {*} position // 刷新位置
|
* @param {*} btn // 执行的按钮
|
*/
|
refreshByButtonResult = (menuId, position, btn) => {
|
const { config, BID, syncConfig } = this.state
|
|
if (config.uuid !== menuId) return
|
|
this.loadData() // 数据刷新
|
|
let supModule = config.wrap.supModule
|
|
if (syncConfig) {
|
supModule = syncConfig.setting.supModule
|
|
MKEmitter.emit('refreshByButtonResult', syncConfig.uuid, position, btn)
|
}
|
|
if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== supModule) {
|
MKEmitter.emit('reloadData', btn.syncComponentId) // 同级标签刷新
|
}
|
|
if (position === 'mainline' && supModule) { // 主表行刷新
|
MKEmitter.emit('reloadData', supModule, (BID || 'empty'))
|
} else if (position === 'popclose') { // 标签关闭刷新
|
supModule && MKEmitter.emit('reloadData', supModule, (BID || 'empty'))
|
btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
|
}
|
}
|
|
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, BData: data }, () => {
|
this.loadData()
|
})
|
}
|
} else {
|
if (!config.wrap.supModule || config.wrap.supModule !== MenuID) return
|
|
if (config.wrap.supControl === 'hidden') {
|
this.setState({ show: id ? true : false })
|
}
|
|
if (id !== this.state.BID) {
|
this.setState({ BID: id, BData: data }, () => {
|
this.loadData()
|
})
|
}
|
}
|
}
|
|
reloadData = (menuId) => {
|
const { config } = this.state
|
|
if (menuId !== config.uuid) return
|
|
this.loadData()
|
}
|
|
async loadData () {
|
const { menuType } = this.props
|
const { config, arr_field, BID, BData } = this.state
|
|
if (config.wrap.datatype === 'static') {
|
this.setState({
|
data: {$$BID: BID || '', $$BData: BData},
|
})
|
return
|
} else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
|
this.setState({
|
data: {$$BID: BID || '', $$BData: BData},
|
})
|
return
|
}
|
|
let searches = []
|
|
this.setState({
|
loading: true
|
})
|
|
let _orderBy = config.setting.order || ''
|
let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
|
|
let result = await Api.genericInterface(param)
|
if (result.status) {
|
let _data = result.data && result.data[0] ? result.data[0] : {}
|
_data.$$BID = BID || ''
|
_data.$$BData = BData
|
|
this.setState({
|
data: _data,
|
loading: false
|
})
|
} else {
|
this.setState({
|
loading: false,
|
})
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
}
|
|
checkAll = (e) => {
|
const { syncConfig } = this.state
|
|
MKEmitter.emit('mkCheckAll', syncConfig.uuid, e.target.checked)
|
}
|
|
render() {
|
const { config, loading, data, show, syncConfig, syncData, checked } = this.state
|
|
return (
|
<div className={'custom-balcony-box' + (!show ? ' hidden' : '')} style={config.style}>
|
{loading ?
|
<div className="loading-mask">
|
<div className="ant-spin-blur"></div>
|
<Spin />
|
</div> : null
|
}
|
{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>
|
)
|
}
|
}
|
|
export default BalconyComponent
|