Files
SaaS-lib/hx-ai-intelligent/src/view/carbonEmissionManage/carbonPlanning/all/index.vue
2024-08-05 15:20:16 +08:00

312 lines
7.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="totalContant">
<div class="ns-form-title">
<div class="title">
<span>查询</span>
<a-date-picker
v-if="selectedTime"
style="margin-left: 5%"
valueFormat="YYYY"
:value="selectYear"
picker="year" />
<a-date-picker
v-else
style="margin-left: 5%"
valueFormat="YYYY-MM"
:value="selectMonth"
picker="month" />
</div>
<div class="operation">
<div class="month" :style="monthStyles" @click="changeToMonth"><span></span></div>
<div class="year" :style="yearStyles" @click="changeToYear"><span></span></div>
</div>
</div>
<div class="contant">
<div class="chartsPart">
<template v-for="(item, index) in data" :key="index">
<div class="electricityConsumption">
<div :id="'ydlChart_' + index" style="height: 100%; width: 100%"></div>
</div>
</template>
</div>
<div class="tablePart">
<a-table :columns="columns" :data-source="data" bordered :pagination="false"> </a-table>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, defineExpose } from 'vue';
import dayjs, { Dayjs } from 'dayjs';
import * as echarts from 'echarts';
import { http } from '/nerv-lib/util/http';
import { carbonPlanning } from '/@/api/carbonEmissionFactorLibrary';
defineOptions({
energyType: 'all', // 与页面路由name一致缓存才可生效
});
const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
const fetch = (api, params = { orgId }) => {
return http.post(api, params);
};
const selectYear = ref<Dayjs>(dayjs(new Date().getFullYear().toString()));
const selectMonth = ref<Dayjs>();
// 年/月切换
const monthStyles = ref('background: #f2f2f2');
const yearStyles = ref('background: #2778ff');
const selectedTime = ref(true);
const changeToMonth = () => {
monthStyles.value = 'background: #2778ff';
yearStyles.value = 'background: #f2f2f2';
queryParams.value.yearAndMonth = 'month';
queryParams.value.year = selectMonth.value;
columns.value[2].title = '月份';
columns.value[2].dataIndex = 'month';
selectedTime.value = false;
getTableData();
};
const changeToYear = () => {
monthStyles.value = 'background: #f2f2f2';
yearStyles.value = 'background: #2778ff';
queryParams.value.yearAndMonth = 'year';
queryParams.value.year = selectYear.value;
columns.value[2].title = '年份';
columns.value[2].dataIndex = 'year';
selectedTime.value = true;
getTableData();
};
// 用电量
const ydlChart = ref({});
let chartInstance: echarts.ECharts | null = null;
const drawEcharts = () => {
data.value.forEach((item, index) => {
const chart = echarts.init(document.getElementById(`ydlChart_${index}`)!);
const handred = 100;
let point = parseInt(item.budgetAchievement.replace("%", ""));
const option = {
backgroundColor: 'transparent',
title: [
{
text: point + '%',
x: 'center',
y: '35%',
textStyle: {
fontSize: 14,
fontWeight: 'normal',
fontStyle: 'normal',
},
},
{
text: item.budgetAchievementName,
x: 'center',
y: '85%',
textStyle: {
fontSize: 14,
fontWeight: 'normal',
fontStyle: 'normal',
},
},
],
// tooltip: {
// formatter: function (params) {
// return params.name + '' + params.percent + ' %';
// },
// },
series: [
{
name: 'circle',
type: 'pie',
clockWise: true,
radius: ['40%', '50%'],
center: ['50%', '40%'],
itemStyle: {
normal: {
label: {
show: false,
},
labelLine: {
show: false,
},
},
},
hoverAnimation: false,
data: [
{
value: point,
name: '占比',
itemStyle: {
normal: {
color: '#4FADFD',
label: {
show: false,
},
labelLine: {
show: false,
},
},
},
},
{
name: '剩余',
value: handred - point,
itemStyle: {
normal: {
color: '#E1E8EE',
},
},
},
],
},
],
};
chart.setOption(option);
});
};
// 表格
const queryParams = ref({
orgId: orgId.value,
year: selectYear.value.format('YYYY'),
yearAndMonth: 'year',
});
const getTableData = () => {
fetch(carbonPlanning.whole, queryParams.value).then((res) => {
data.value = res.data;
setTimeout(() => {
drawEcharts();
}, 500);
});
};
const columns = ref([
{
title: '序号',
customRender: (text: any) => {
return text.index + 1;
},
},
{
title: '名称',
dataIndex: 'itemizeName',
},
{
title: '年份',
dataIndex: 'year',
},
{
title: '计量单位',
dataIndex: 'name',
},
{
title: '总实际用量',
dataIndex: 'actualUsage',
},
{
title: '总预算量',
dataIndex: 'budget',
},
{
title: '基准值',
dataIndex: 'referenceValue',
},
{
title: '节能量',
dataIndex: 'energyConservation',
},
{
title: '预算达成率',
dataIndex: 'budgetAchievement',
},
]);
const data = ref([]);
getTableData();
defineExpose({
getTableData,
});
</script>
<style lang="less" scoped>
.totalContant {
height: 100%;
padding: 12px;
}
:deep(.ant-tabs-content) {
padding: 16px;
}
.ns-form-title {
font-weight: bold;
user-select: text;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 5vh;
.title {
text-align: left;
height: 32px;
line-height: 32px;
font-weight: bold;
user-select: text;
position: relative;
padding-left: 9px;
width: 50%;
}
.title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 13px;
width: 3px;
border-radius: 1px;
background-color: #2778ff;
}
.operation {
display: flex;
margin-right: 10px;
font-weight: 400;
height: 70%;
cursor: pointer;
width: 10%;
}
.month {
width: 70px;
display: flex;
align-items: center;
justify-content: center;
// background: #f2f2f2;
}
.year {
width: 70px;
display: flex;
align-items: center;
justify-content: center;
// background: #2778ff;
}
}
.contant {
width: 100%;
height: calc(100% - 5vh);
.chartsPart {
width: 100%;
height: 35%;
display: flex;
justify-content: space-between;
.electricityConsumption {
width: 19%;
height: 100%;
background: rgba(39, 120, 255, 0.05);
}
}
.tablePart {
height: calc(65% - 20px);
margin-top: 20px;
}
}
</style>