// 核心库
import React from 'react'
import { connect } from 'dva'
// 组件库
import { FullDatePicker, LocalSearch, LayoutCard } from '@woowalker/feui'
import { Row, Col, Table, Icon, message } from 'antd'
import CommonChart from '../../Chart/CommonChart'
import EnergyKpiModal from './EnergyKpiModal'
import EnergyKpiDetailModal from './EnergyKpiDetailModal'
// 工具库
import moment from 'moment'
class EDEnergyKpiPage extends React.Component {
constructor (props) {
super(props)
this.state = {
dateType: '0',
dateString: moment().format('YYYY'),
rankChartData: {},
rankChartChangeData: {},
trendChartData: {},
chartLine: {},
columns: [],
dataSource: [],
selectedRowKeys: []
}
}
onModalRef = (ref) => {
this.modalChild = ref
}
onDetailModalRef = (ref) => {
this.detailModalChild = ref
}
showModal = () => {
this.modalChild.showModal(this.props.data.TreeSelected.join(','))
}
showDetailModal = (key, parentId) => {
const { dateType, dateString } = this.state
this.detailModalChild.showModal(key, parentId, dateType, dateString)
}
onSelectChange = selectedRowKeys => {
if (selectedRowKeys.length == 0) {
message.error("至少选中1个计量点")
} else {
this.setState({ selectedRowKeys }, this.chartLineSetValue)
}
}
chartLineSetValue = () => {
const { chartLine, selectedRowKeys } = this.state
const data = []
chartLine.Data.forEach(item => {
selectedRowKeys.indexOf(item.Key) !== -1 && data.push(item)
})
this.setState({
trendChartData: {
xAxis: chartLine?.XAxis[0].Data,
yAxis: [{ Name: '' }],
data
}
})
}
handleSearch = () => {
const { dateType, dateString } = this.state
const json = {
Keyword: this.props.data.TreeSelected.join(','),
OrgId: this.props.login.OrgId,
Parameter1: dateType,
Parameter2: dateString,
}
if (dateType == '0' && moment(dateString) > moment().startOf('year')) {
message.error("选中的年份不能大于当前月!")
this.setState({ dateString: moment().format('YYYY') })
return
}
if (dateType == '1' && moment(dateString) > moment().startOf('month')) {
message.error("选中的月份不能大于当前月!")
this.setState({ dateString: moment().format('YYYY-MM') })
return
}
this.props.dispatch({
type: 'app/getDataByPost',
url: 'ED/Calculate/GetMarkItemData',
payload: json
}).then(res => {
if (res && res.chartLine) {
const { data: dataSource, selectedRowKeys, chartLine, chartKpiModel, chartKpiChangeModel } = res
// table 的列配置
const columns = [
{ title: '序号', dataIndex: 'Index' },
{ title: '名称', dataIndex: 'Name' },
{ title: '最大值', dataIndex: 'Max' },
{ title: '最小值', dataIndex: 'Min' },
{ title: '平均值', dataIndex: 'Avg' }
]
columns.forEach(item => {
item.render = (text, record, index) => {
const color = this.state.selectedRowKeys.indexOf(record.key) !== -1 ? 'inherit' : '#bfbfbf'
return {text}
}
})
columns.push({
title: '操作',
dataIndex: 'action',
render: (text, record) => {
return this.showDetailModal(record.key, record.ParentId)}>