<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>
    <div v-show="statisticVisiable">
      <el-row style="text-align: center;margin-top: 10px;margin-bottom: 10px">
        <el-col :span="8">
          <span class="statistic_number">{{statisticData.departureCount}}</span>
          <br><br>
          <span class="statistic_title">出行次数</span>
        </el-col>
        <el-col :span="8">
          <span class="statistic_number">{{statisticData.departureDay}}</span>
          <br><br>
          <span class="statistic_title">出行天数</span>
        </el-col>
        <el-col :span="8">
          <span class="statistic_number">{{statisticData.departureMileage}}</span>
          <br><br>
          <span class="statistic_title">公里</span>
        </el-col>
      </el-row>
    </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.use}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="使用人">
        <template scope="scope">
          <span>{{scope.row.user}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="使用人电话">
        <template scope="scope">
          <span>{{scope.row.userTel}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="验车人">
        <template scope="scope">
          <span>{{scope.row.checkMan}}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" align="center" label="验车人电话">
        <template scope="scope">
          <span>{{scope.row.checkManTel}}</span>
        </template>
      </el-table-column>
      <el-table-column width="250" align="center" label="出车时间">
        <template scope="scope">
          <span>{{scope.row.departureTime}}</span>
        </template>
      </el-table-column>
      <el-table-column width="250" align="center" label="还车时间">
        <template scope="scope">
          <span>{{scope.row.arrivalTime}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="开始公里数">
        <template scope="scope">
          <span>{{scope.row.mileageStart}}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" align="center" label="结束公里数">
        <template scope="scope">
          <span>{{scope.row.mileageEnd}}</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>

    <!--    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">-->
    <!--      <el-form :model="form" :rules="rules" ref="form" label-width="100px">-->
    <!--        <el-form-item label="姓名" prop="name">-->
    <!--          <el-input v-model="form.name" placeholder="请输入姓名"></el-input>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--      <div slot="footer" class="dialog-footer">-->
    <!--        <el-button @click="cancel('form')">取 消</el-button>-->
    <!--        <el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>-->
    <!--        <el-button v-else type="primary" @click="update('form')">确 定</el-button>-->
    <!--      </div>-->
    <!--    </el-dialog>-->
  </div>
</template>
<style>
  .statistic_number {
    font-size: x-large;
    font-weight: bolder;
  }

  .statistic_title {
    font-size: x-large;
  }
</style>
<script>
  import {mapGetters} from 'vuex';
  import {
    page,
    statistic
  } from '../../../api/vehicle/departureLog';

  export default {
    name: 'vehicleDepartureLog',
    data() {
      return {
        form: {
          id: null,
          numberPlate: null,
          vehicleId: null,
          use: null,
          user: null,
          userTel: null,
          checkMan: null,
          checkManTel: null,
          recycleMan: null,
          recycleManTel: null,
          departureTime: null,
          arrivalTime: null,
          mileageStart: null,
          mileageEnd: null,
          state: null
        },
        rules: {
          name: [
            {
              required: true,
              message: '请输入用户',
              trigger: 'blur'
            }
          ]
        },
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          numberPlate: undefined
        },
        dialogStatus: '',
        textMap: {
          update: '编辑',
          create: '创建'
        },
        tableKey: 0,
        dialogFormVisible: null,
        statisticVisiable: true,
        statisticData: {
          departureCount: null,
          departureDay: null,
          departureMileage: null
        }
      }
    },
    created() {
      const numberPlate = this.$route.query.numberPlate;
      if (numberPlate) {
        this.listQuery.numberPlate = numberPlate;
      }
      this.handleFilter();
    },
    computed: {
      ...mapGetters([
        'elements'
      ])
    },
    methods: {
      handleFilter() {
        this.getList();
        if (this.listQuery.numberPlate) {
          statistic({numberPlate: this.listQuery.numberPlate}).then(response => {
            this.statisticData = response.data;
          });
          this.statisticVisiable = true;
        }
      },
      getList() {
        this.listLoading = true;
        if (!this.listQuery.numberPlate) {
          this.statisticVisiable = false;
        }
        page(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>
