import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Spin, notification, Modal } from 'antd'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import UtilsDM from '@/utils/utils-datamanage.js'
|
import MKEmitter from '@/utils/events.js'
|
import './index.scss'
|
|
const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
|
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
|
const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
|
const CalendarBoard = asyncComponent(() => import('./board'))
|
|
class NormalCalendar extends Component {
|
static propTpyes = {
|
config: PropTypes.object, // 组件配置信息
|
mainSearch: PropTypes.any, // 外层搜索条件
|
}
|
|
state = {
|
BID: '', // 上级ID
|
config: null, // 图表配置信息
|
loading: false, // 数据加载状态
|
data: null, // 数据
|
search: '',
|
BData: ''
|
}
|
|
loaded = false
|
|
/**
|
* @description 初始化处理
|
*/
|
UNSAFE_componentWillMount () {
|
let _config = fromJS(this.props.config).toJS()
|
|
let BData = ''
|
|
if (_config.setting.supModule) {
|
BData = window.GLOB.CacheData.get(_config.setting.supModule)
|
} else {
|
BData = window.GLOB.CacheData.get(_config.$pageId)
|
}
|
|
this.setState({
|
BID: BData ? (BData.$BID || '') : '',
|
BData: BData,
|
config: _config,
|
arr_field: _config.columns.map(col => col.field).join(','),
|
search: Utils.initMainSearch(_config.search) // 搜索条件初始化(含有时间格式,需要转化)
|
}, () => {
|
if (_config.setting.onload === 'true') {
|
setTimeout(() => {
|
this.loadData()
|
}, _config.setting.delay || 0)
|
}
|
})
|
}
|
|
componentDidMount () {
|
const { config } = this.state
|
|
MKEmitter.addListener('reloadData', this.reloadData)
|
MKEmitter.addListener('resetSelectLine', this.resetParentParam)
|
MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
|
|
if (config.$cache && !this.loaded) {
|
Api.getLCacheConfig(config.uuid).then(res => {
|
if (!res || this.loaded) return
|
|
this.setState({data: res.map((item, index) => {
|
item.key = index
|
item.$$uuid = item[config.setting.primaryKey] || ''
|
item.$Index = index + 1 + ''
|
|
return item
|
})})
|
})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('reloadData', this.reloadData)
|
MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
|
MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
|
}
|
|
/**
|
* @description 图表数据更新,刷新内容
|
*/
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
const { config } = this.state
|
|
if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
|
this.setState({}, () => {
|
this.loadData()
|
})
|
}
|
}
|
|
/**
|
* @description 按钮执行完成后页面刷新
|
* @param {*} menuId // 菜单Id
|
* @param {*} position // 刷新位置
|
* @param {*} btn // 执行的按钮
|
*/
|
refreshByButtonResult = (menuId, position, btn) => {
|
const { config, BID } = this.state
|
|
if (config.uuid !== menuId) return
|
|
if (position === 'mainline' && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
|
MKEmitter.emit('reloadData', config.setting.supModule, BID)
|
} else {
|
this.loadData()
|
}
|
}
|
|
resetParentParam = (MenuID, id, data) => {
|
const { config } = this.state
|
|
if (!config.setting.supModule || config.setting.supModule !== MenuID) return
|
if (id !== this.state.BID || id !== '') {
|
this.setState({ BID: id, BData: data }, () => {
|
this.loadData()
|
})
|
}
|
}
|
|
reloadData = (menuId) => {
|
const { config } = this.state
|
|
if (config.uuid !== menuId) return
|
|
this.loadData()
|
}
|
|
async loadData () {
|
const { mainSearch } = this.props
|
const { config, arr_field, BID, search } = this.state
|
|
if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
|
this.setState({
|
data: [],
|
})
|
this.loaded = true
|
return
|
}
|
|
let searches = fromJS(search).toJS()
|
if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 主表搜索条件
|
let keys = searches.map(item => item.key.toLowerCase())
|
mainSearch.forEach(item => {
|
if (!keys.includes(item.key.toLowerCase())) {
|
searches.push(item)
|
}
|
})
|
}
|
|
let requireFields = searches.filter(item => item.required && item.value === '')
|
if (requireFields.length > 0) {
|
return
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
let _orderBy = config.setting.order || ''
|
let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 99999, BID)
|
|
let result = await Api.genericInterface(param)
|
if (result.status) {
|
this.loaded = true
|
if (config.$cache && config.setting.onload !== 'false') {
|
Api.writeCacheConfig(config.uuid, result.data || '')
|
}
|
|
let data = result.data.map((item, index) => {
|
item.key = index
|
item.$$uuid = item[config.setting.primaryKey] || ''
|
item.$$BID = BID || ''
|
|
return item
|
})
|
|
this.setState({
|
data: data,
|
loading: false
|
})
|
|
if (result.message) {
|
if (result.ErrCode === 'Y') {
|
Modal.success({
|
title: result.message
|
})
|
} else if (result.ErrCode === 'S') {
|
notification.success({
|
top: 92,
|
message: result.message,
|
duration: 2
|
})
|
}
|
}
|
} else {
|
this.setState({
|
loading: false
|
})
|
|
if (!result.message) return
|
if (result.ErrCode === 'N') {
|
Modal.error({
|
title: result.message,
|
})
|
} else if (result.ErrCode !== '-2') {
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
}
|
}
|
|
refreshbysearch = (searches) => {
|
this.setState({
|
search: searches
|
}, () => {
|
this.loadData()
|
})
|
}
|
|
render() {
|
const { config, loading, data, BID, BData } = this.state
|
|
return (
|
<div className="normal-calendar-box" id={'anchor' + config.uuid} style={{...config.style}}>
|
{loading ?
|
<div className="loading-mask">
|
{data ? <div className="ant-spin-blur"></div> : null}
|
<Spin />
|
</div> : null
|
}
|
<NormalHeader config={config} />
|
{config.search.length ?
|
<MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
|
}
|
{config.action[0] ?
|
<PopupButton disabled={false} BID={BID} btn={config.action[0]} BData={BData} setting={config.setting} selectedData={[]}/> : null
|
}
|
<CalendarBoard config={config} />
|
</div>
|
)
|
}
|
}
|
|
export default NormalCalendar
|