<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="月份查询" prop="month">
        <el-date-picker v-model="queryParams.month" type="month" placeholder="选择月份" value-format="yyyy-MM" @change="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="序号" width="60" align="center" />
      <el-table-column prop="date" label="月份" width="120" align="center" />
      <el-table-column prop="areaname" label="名称" width="150" align="center" />
      <el-table-column prop="num" label="月能耗(KWh)" width="150" align="center" />
      <el-table-column prop="total" label="累计能耗(KWh)" width="150" align="center" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { getPowerConsumptionList } from '@/api/tyler/PowerConsumptionAnalysis';
export default {
  name: 'PowerConsumptionAnalysis',
  data() {
    return {
      // 查询参数
      queryParams: {
        month: '',
        pageNum: 1,
        pageSize: 10,
      },
      // 表格数据
      tableData: [],
      // 总条数
      total: 0,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    getList() {
      getPowerConsumptionList(this.queryParams).then(response => {
        this.tableData = response.rows.map(item => {
          return {
            ...item,
            date: new Date(item.date).toISOString().slice(0, 7),
          };
        });

        this.total = response.total;
      });
    },
    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
      this.queryParams.month = '';
      this.handleQuery();
    },
  },
};
</script>

<style scoped lang="scss">
.app-container {
}
</style>
