<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="车牌号"
                v-model="listQuery.numberPlate"></el-input>
      <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row
              style="width: 100%">
      <el-table-column align="center" label="车牌号" width="120">
        <template scope="scope">
          <span>{{scope.row.numberPlate}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="保养人">
        <template scope="scope">
          <span>{{scope.row.operator}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="保养日期">
        <template scope="scope">
          <span>{{scope.row.date}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="公里数">
        <template scope="scope">
          <span>{{scope.row.mileage}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="总费用">
        <template scope="scope">
          <span>{{scope.row.amount}}</span>
        </template>
      </el-table-column>
      <el-table-column width="250" align="center" label="审批人">
        <template scope="scope">
          <span>{{scope.row.approvers}}</span>
        </template>
      </el-table-column>
      <el-table-column width="250" align="center" label="保养分公司">
        <template scope="scope">
          <span>{{scope.row.branchCompanyName}}</span>
        </template>
      </el-table-column>
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                     layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </div>
  </div>
</template>
<script>
  import {
    logPage
  } from '../../../api/vehicle/upkeep';

  export default {
    name: 'vehicleUpkeepLog',
    data() {
      return {
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          numberPlate: undefined
        },
        tableKey: 0
      }
    },
    created() {
      this.getList();
    },
    methods: {
      handleFilter() {
        this.getList();
      },
      getList() {
        this.listLoading = true;
        logPage(this.listQuery).then(response => {
          this.list = response.data.list;
          this.total = response.data.total;
          this.listLoading = false;
        });
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      }
    }
  }
</script>
