1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
  <div class="app-container">
    <el-form :inline="true" :model="filters">
      <el-form-item label="查看模式">
        <el-radio-group v-model="mode" @change="buildColumns">
          <el-radio-button :value="'month'">按月</el-radio-button>
          <el-radio-button :value="'year'">按年</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="mode === 'month' || mode === 'year'" label="年份">
        <el-date-picker v-model="year" type="year" value-format="YYYY" format="YYYY" placeholder="请选择年份" @change="refresh" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="refresh">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
 
    <div class="table_list">
      <PIMTable
        rowKey="deviceId"
        :column="columns"
        :tableData="tableData"
        :page="{ current: 1, size: tableData.length || 10, total: tableData.length }"
      />
    </div>
  </div>
</template>
 
<script setup>
import { ref, computed } from "vue";
 
defineOptions({ name: "金额汇总" });
 
const mode = ref("month");
const year = ref(new Date().getFullYear().toString());
const filters = ref({});
 
const columns = ref([]);
const tableData = ref([]);
 
const buildColumns = () => {
  const base = [{ label: "设备名称", align: "center", prop: "deviceName", width: 180 }];
  if (mode.value === "month") {
    const monthCols = Array.from({ length: 12 }, (_, i) => ({
      label: `${i + 1}月`,
      align: "center",
      prop: `m${i + 1}`,
    }));
    columns.value = [
      ...base,
      ...monthCols,
      { label: "总计", align: "center", prop: "total" },
    ];
  } else {
    columns.value = [
      ...base,
      { label: "金额", align: "center", prop: "yearAmount" },
    ];
  }
};
 
const refresh = async () => {
  buildColumns();
  tableData.value = [];
};
 
const reset = () => {
  mode.value = "month";
  year.value = new Date().getFullYear().toString();
  refresh();
};
 
buildColumns();
refresh();
</script>
 
<style scoped>
.table_list {
  margin-top: 10px;
}
</style>