Files
sunProduct/src/views/system/statistics-summary/index.vue
2026-10-23 16:11:59 +08:00

169 lines
5.8 KiB
Vue

<template>
<div class="h-full flex flex-col p-2">
<pageheader></pageheader>
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="90px">
<el-form-item label="时间范围">
<el-date-picker
v-model="dateRange"
type="daterange"
value-format="YYYY-MM-DD"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
unlink-panels
@change="handleDateRangeChange"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</transition>
<el-row :gutter="12" class="mb-[10px]">
<el-col v-for="item in summaryCards" :key="item.label" :span="6">
<el-card shadow="hover">
<div class="flex flex-col">
<span class="text-[13px] opacity-60">{{ item.label }}</span>
<span class="mt-1 text-[22px] font-bold">{{ item.value }}</span>
</div>
</el-card>
</el-col>
</el-row>
<el-card class="flex-1" shadow="never">
<template #header>
<el-row justify="end">
<el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
</el-row>
</template>
<el-table v-loading="loading" border :data="list">
<el-table-column label="房屋名称" prop="houseName" align="center" show-overflow-tooltip />
<el-table-column label="承租方" align="center" >
<template #default="scope">{{ scope.row.lesseeName || '--' }}</template>
</el-table-column>
<el-table-column label="联系电话" align="center" >
<template #default="scope">{{ scope.row.lesseePhone || '--' }}</template>
</el-table-column>
<el-table-column label="设备编码" prop="deviceCodes" align="center" show-overflow-tooltip />
<el-table-column label="设备数量" prop="deviceCount" align="center" />
<el-table-column label="房屋用电量(度)" align="center" >
<template #default="scope">{{ formatNumber(scope.row.usageEnergy) }}</template>
</el-table-column>
<el-table-column label="公摊用电量(度)" align="center" >
<template #default="scope">{{ formatNumber(scope.row.shareUsageEnergy) }}</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</el-card>
</div>
</template>
<script setup name="StatisticsSummary" lang="ts">
import { listStatisticsSummary, getStatisticsSummaryTotal } from '@/api/system/statisticsSummary';
import { StatisticsSummaryVO, StatisticsSummaryTotal } from '@/api/system/statisticsSummary/types';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const loading = ref(false);
const showSearch = ref(true);
const list = ref<StatisticsSummaryVO[]>([]);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const getInitSummary = (): StatisticsSummaryTotal => ({
houseCount: 0,
houseUsageTotal: '0',
shareUsageTotal: '0',
totalUsage: '0'
});
const queryParams = ref({
pageNum: 1,
pageSize: 10,
beginTime: undefined as string | undefined,
endTime: undefined as string | undefined
});
/** 查询时间段 */
const dateRange = ref<[string, string] | null>(null);
const summary = ref<StatisticsSummaryTotal>(getInitSummary());
/** 时间段变化 */
const handleDateRangeChange = (val: [string, string] | null) => {
queryParams.value.beginTime = val?.[0];
queryParams.value.endTime = val?.[1];
};
/** 数值格式化(保留两位小数) */
const formatNumber = (value?: string | number | null) => {
if (value === null || value === undefined || value === '') return '--';
const num = Number(value);
return Number.isNaN(num) ? String(value) : num.toFixed(2);
};
/** 顶部合计卡片 */
const summaryCards = computed(() => [
{ label: '房屋数量', value: summary.value.houseCount ?? 0 },
{ label: '房屋用电合计', value: formatNumber(summary.value.houseUsageTotal) },
{ label: '公摊用电合计', value: formatNumber(summary.value.shareUsageTotal) },
{ label: '用电总计', value: formatNumber(summary.value.totalUsage) }
]);
/** 查询统计汇总列表 */
const getList = async () => {
loading.value = true;
try {
const [listRes, totalRes] = await Promise.all([
listStatisticsSummary(queryParams.value),
getStatisticsSummaryTotal({ beginTime: queryParams.value.beginTime, endTime: queryParams.value.endTime })
]);
list.value = listRes.rows || [];
total.value = listRes.total || 0;
summary.value = totalRes.data || getInitSummary();
} finally {
loading.value = false;
}
};
/** 导出按钮操作 */
const handleExport = () => {
proxy?.download(
'statisticsSummary/export',
{
beginTime: queryParams.value.beginTime,
endTime: queryParams.value.endTime
},
`statisticsSummary_${new Date().getTime()}.xlsx`
);
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
dateRange.value = null;
queryParams.value.beginTime = undefined;
queryParams.value.endTime = undefined;
handleQuery();
};
onMounted(() => {
getList();
});
</script>