<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="flexc">
        <div class="back-icon" @click="goBack">
          <i class="el-icon el-icon-back"></i>
        </div>
        <div class="section-title">Charging History</div>
      </div>
    </div>
    <el-table
      v-loading="loading"
      :data="tableData.list"
      fit>
      <el-table-column
        :label="item.label"
        align="center"
        class-name="fixed-width"
        v-for="(item, index) in columns"
        :key="index"
        :min-width="item.width"
        :prop="item.prop"/>
      </el-table>
    </el-table>
    <div class="right">
      <Pagination
        v-show="tableData.total > 0"
        :total="tableData.total"
        :page.sync="tableData.pageNo"
        :limit.sync="tableData.pageSize"
        @pagination="getTableData" />
    </div>
  </div>
</template>

<script>
import api from '@/http/api/apiUser.js'
import Pagination from '@/components/Pagination'
export default {
  data() {
    return {
      loading: false,
      tableData: {
        pageSize: 10,
        pageNo: 1,
        total: 0,
        list: []
      },
      columns: [{
        prop: "transactionId",
        label: "Transaction ID",
        width: 120
      },{
        prop: "vehicle",
        label: "Vehicle",
        width: 100
      },{
        prop: "chargeBoxId",
        label: "Station ID",
        width: 120
      },{
        prop: "connectorId",
        label: "Connector",
        width: 90
      },{
        prop: "startDateTime",
        label: "Start Date/Time",
        width: 140
      },{
        prop: "endDateTime",
        label: "End Date/Time",
        width: 140
      },{
        prop: "power",
        label: "Power (kWh)",
        width: 120
      },{
        prop: "rate",
        label: "Rate",
        width: 200
      },{
        prop: "charges",
        label: "Charges",
        width: 100
      }]
    }
  },
  components: { Pagination },
  created() {
    if (this.$route.params.id) {
      this.getTableData()
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
      //this.$router.push({ path: '/user-management'})
      //this.$router.push({ path: '/user-management/update-user/' + this.$route.params.id })
    },
    getTableData() {
      this.loading = true;
      api.pageChargeHistory({
        pageNo: this.tableData.pageNo,
        pageSize: this.tableData.pageSize,
        pageVo: {
          userPk: this.$route.params.id
        }
      }).then(res => {
        this.loading = false;
        if (res.total) {
          this.tableData.list = res.data
          this.tableData.total = res.total
        }
      }).catch(err => {
        this.loading = false;
        this.$message({
          message: err,
          type: 'error',
        })
      })
    }
  }
}
</script>

<style scoped>
  .back-icon {
    width: 44px;
    height: 44px;
    padding: 10px;
    display: flex;
    cursor: pointer;
    font-size: 18px;
    align-items: center;
  }
  .section-title {
    color: #333333;
    font-size: 16px;
    line-height: 24px;
    margin-top: 10px;
    margin-bottom: 10px;
    font-weight: 500;
    font-family: sans-serif;
    text-transform: uppercase;
  }
</style>