Files

232 lines
5.3 KiB
Vue
Raw Normal View History

2024-07-12 16:59:33 +08:00
<template>
<div>
2024-07-25 14:18:37 +08:00
<a-table
:columns="column"
:data-source="data"
2024-08-20 15:40:08 +08:00
:bordered="true"
2024-07-12 16:59:33 +08:00
:pagination="false"
2024-08-23 15:45:42 +08:00
:scroll="{ x: 1700, y: 480 }">
2024-07-12 16:59:33 +08:00
<template #title>
2024-08-20 15:40:08 +08:00
<a-date-picker v-model:value="selectYear" picker="year" valueFormat="YYYY" />
<span style="margin-left: 30px">
<a-button type="primary" @click="changeYearData">查询</a-button>
<a-button type="primary" ghost style="margin-left: 6px" @click="reset">重置</a-button>
</span>
2024-07-12 16:59:33 +08:00
</template>
</a-table>
2024-08-23 15:45:42 +08:00
<!-- <a-pagination
2024-07-22 15:25:41 +08:00
:current="queryParams.pageNum"
:total="total"
:page-size="queryParams.pageSize"
2024-07-25 14:18:37 +08:00
style="display: flex; justify-content: center; margin-top: 16px"
2024-07-22 15:25:41 +08:00
:show-size-changer="true"
:show-quick-jumper="true"
2024-08-23 15:45:42 +08:00
@change="onChange" /> -->
2024-07-12 16:59:33 +08:00
</div>
</template>
<script lang="ts" setup>
2024-07-31 15:52:08 +08:00
import { ref, defineExpose } from 'vue';
2024-07-12 16:59:33 +08:00
import { http } from '/nerv-lib/util/http';
import { Pagination } from 'ant-design-vue';
2024-07-17 15:54:10 +08:00
import dayjs, { Dayjs } from 'dayjs';
import { carbonEmission } from '/@/api/carbonEmissionFactorLibrary';
2024-07-12 16:59:33 +08:00
defineOptions({
energyType: 'CarbonEmissions', // 与页面路由name一致缓存才可生效
components: {
'a-pagination': Pagination,
},
});
const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
2024-07-25 14:18:37 +08:00
const fetch = (api, params = { orgId }) => {
2024-07-12 16:59:33 +08:00
return http.post(api, params);
};
2024-07-17 15:54:10 +08:00
const data = ref([]);
2024-07-25 14:18:37 +08:00
const selectYear = ref<Dayjs>(dayjs(new Date().getFullYear().toString()));
const total = ref<number>();
2024-07-17 15:54:10 +08:00
const queryParams = ref({
pageNum: 1,
pageSize: 10,
year: selectYear.value.format('YYYY'),
2024-07-25 14:18:37 +08:00
orgId: orgId.value,
});
2024-07-12 16:59:33 +08:00
// 年份选择改变触发
const changeYearData = () => {
2024-07-25 14:18:37 +08:00
queryParams.value.year = selectYear.value;
getTableList();
};
2024-08-20 15:40:08 +08:00
const reset = () => {
selectYear.value = dayjs(new Date().getFullYear().toString());
queryParams.value.year = selectYear.value.format('YYYY');
getTableList();
};
2024-07-17 15:54:10 +08:00
// 表头
2024-07-25 14:18:37 +08:00
const column: TableColumnsType[] = [
2024-07-17 15:54:10 +08:00
{
title: '排放类型',
dataIndex: 'cnValue',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
customCell: (record, rowIndex) => {
if (rowIndex == undefined) {
return {
rowSpan: 0,
colSpan: 0,
};
}
const rowSpan = getRowSpan('cnValue', record, data.value);
2024-07-24 15:17:34 +08:00
if (rowIndex != 0 && data.value[rowIndex - 1].cnValue == record.cnValue) {
2024-07-17 15:54:10 +08:00
return {
rowSpan: 0,
colSpan: 0,
};
}
return {
rowSpan: rowSpan,
};
},
},
{
title: '能源种类',
dataIndex: 'energyType',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '计量单位',
2024-07-18 15:14:25 +08:00
dataIndex: 'unitName',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '加权平均',
dataIndex: 'averageFactorValue',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '全年',
dataIndex: 'carbonYearly',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '1月',
dataIndex: 'jan',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '2月',
dataIndex: 'feb',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '3月',
dataIndex: 'mar',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '4月',
dataIndex: 'apr',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '5月',
dataIndex: 'may',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '6月',
dataIndex: 'jun',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '7月',
dataIndex: 'jul',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '8月',
dataIndex: 'aug',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '9月',
dataIndex: 'sep',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '10月',
dataIndex: 'oct',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '11月',
dataIndex: 'nov',
2024-08-23 15:45:42 +08:00
width: 100,
2024-07-17 15:54:10 +08:00
},
{
title: '12月',
2024-08-23 15:45:42 +08:00
dataIndex: 'dece',
width: 100,
2024-07-17 15:54:10 +08:00
},
];
// 合并单元格
const getRowSpan = (dataIndex: string, record: any, data: any, dependents: string[] = []) => {
let rowSpan = 1;
for (let i = data.indexOf(record) + 1; i < data.length; i++) {
let shouldMerge = true;
for (const dependent of dependents) {
if (data[i][dependent] !== record[dependent]) {
shouldMerge = false;
break;
}
}
if (shouldMerge && data[i][dataIndex] === record[dataIndex]) {
rowSpan++;
} else {
break;
}
}
return rowSpan;
};
2024-07-12 16:59:33 +08:00
// 获取表格数据
const getTableList = () => {
2024-07-25 14:18:37 +08:00
fetch(carbonEmission.carbonEmissionStatistics, queryParams.value).then((res) => {
data.value = res.data;
total.value = res.data.length;
2024-07-12 16:59:33 +08:00
});
};
2024-07-31 15:52:08 +08:00
defineExpose({
getTableList,
});
2024-07-12 16:59:33 +08:00
// 分页器
2024-07-25 14:18:37 +08:00
const onChange = (pageNumber: number, size: number) => {
2024-07-12 16:59:33 +08:00
queryParams.value.pageNum = pageNumber;
queryParams.value.pageSize = size;
2024-07-25 14:18:37 +08:00
getTableList();
2024-07-12 16:59:33 +08:00
};
</script>
<style scoped lang="less">
2024-07-25 14:18:37 +08:00
:deep(.ant-table-title) {
2024-07-12 16:59:33 +08:00
display: flex;
}
2024-07-25 14:18:37 +08:00
:deep(.ant-table-container) {
2024-08-23 15:45:42 +08:00
margin: 0px 16px;
2024-07-12 16:59:33 +08:00
}
2024-08-20 15:40:08 +08:00
// :deep(.ant-table-cell) {
// border: 1px solid #f0f0f0;
// }
// :deep(.ant-table-cell::before) {
// display: none;
// }
2024-07-12 16:59:33 +08:00
</style>
<style scoped>
th.column-money,
td.column-money {
text-align: right !important;
}
2024-08-23 15:45:42 +08:00
.custom-cell {
display: flex;
align-items: center;
padding: 8px;
}
2024-07-25 14:18:37 +08:00
</style>