import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { Select } from 'antd'; import ReactECharts from 'echarts-for-react'; import moment from 'moment' const { Option } = Select; const General = ({ dispatch, actions, stations }) => { const { bigScreen } = actions const [electro, setElectro] = useState({ now: 0, before: 0 }) //用电概况 const [interval, setInterval] = useState('本日') //用电概况区间 useEffect(async () => { let now = 0 let before = 0 let time = interval == '本日' ? "day" : interval == '本月' ? "month" : interval == '本年' ? "year" : "" let pastTime = { begin: interval == '本日' ? moment().day(moment().day() - 1).startOf(time).format('x') : interval == '本月' ? moment().month(moment().month() - 1).startOf(time).format('x') : interval == '本年' ? moment().year(moment().year() - 1).startOf(time).format('x') : "", end: interval == '本日' ? moment().day(moment().day() - 1).endOf(time).format('x') : interval == '本月' ? moment().month(moment().month() - 1).endOf(time).format('x') : interval == '本年' ? moment().year(moment().year() - 1).endOf(time).format('x') : "", } if (stations?.pump) { //现在 await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.pump.join(), begin: moment().startOf(time).format('x'), end: moment().endOf(time).format('x'), aggtype: interval == '本日' ? "h" : "d", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { now += (f?.values?.eMotor_EQ || 0) } }) }) } }) if (interval != '本日') { await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.pump.join(), begin: moment().startOf("day").format('x'), end: moment().endOf("day").format('x'), aggtype: "h", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { now += (f?.values?.eMotor_EQ || 0) } }) }) } }) } //以前 await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.pump?.join(), ...pastTime, aggtype: interval == '本日' ? "h" : "d", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { before += (f?.values?.eMotor_EQ || 0) } }) }) } }) } if (stations?.cabine) { // 现在 await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.cabine?.join(), begin: moment().startOf(time).format('x'), end: moment().endOf(time).format('x'), aggtype: interval == '本日' ? "h" : "d", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { now += (f?.values?.eQF_EQ || 0) } }) }) } }) if (interval != '本日') { await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.cabine?.join(), begin: moment().startOf("day").format('x'), end: moment().endOf("day").format('x'), aggtype: "h", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { now += (f?.values?.eQF_EQ || 0) } }) }) } }) } // 以前 await dispatch(bigScreen.axyData({ type: 'get', url: `stations/data/theme`, params: { query: { stations: stations?.cabine?.join(), ...pastTime, aggtype: interval == '本日' ? "h" : "d", method: 'diff' } } })).then(d => { if (d.success) { d.payload.data[0]?.stations?.map(c => { c.data?.map(f => { if (!f.changData) { before += (f?.values?.eQF_EQ || 0) } }) }) } }) } setElectro({ now: now, before: before }) }, [stations, interval]) return
用电概况
{['本日', "本月", '本年'].map(v =>
{ setInterval(v) }}>{v}
)}
{interval == '本日' ? "当日用电" : interval == '本月' ? "当月用电" : interval == '本年' ? "当年用电" : ""}
{electro?.now.toFixed(2)} kwh
{interval == '本日' ? "昨日用电" : interval == '本月' ? "上月用电" : interval == '本年' ? "上年用电" : ""}
{electro?.before?.toFixed(2)} kwh
用电同比
{electro?.now && electro?.before ? (((electro?.now - electro?.before) / electro?.before) * 100).toFixed(2) : "--"} %
} function mapStateToProps (state) { const { auth, global } = state; return { user: auth.user, clientHeight: global.clientHeight, actions: global.actions, }; } export default connect(mapStateToProps)(General);