<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="form" v-model="form">
        <el-row>
          <el-col :span="5">
            <el-form-item label="车牌号:">
              <el-input v-model="form.LICENCE_NO" placeholder="搜索" class="filter-item" style="width: 200px;"/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">搜索</el-button>
            <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="reset">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        :reserve-selection="true"
        type="selection"
        width="55"
        align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="LICENCE_NO" label="车牌号"/>
      <el-table-column label="车牌类型" align="center">
        <template slot-scope="{row}">
          {{ translateLicenceType(row.LICENCE_TYPE) }}
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" align="center">
        <template slot-scope="{row}">
          {{ translateVehicleType(row.VEHICLE_TYPE) }}
        </template>
      </el-table-column>
      <el-table-column prop="vehicle_arrival_barrier" label="车辆入港闸口"/>
      <el-table-column prop="vehicle_arrival_time" label="车辆入港时间"/>
      <el-table-column prop="vehicle_departure_barrier" label="车辆离岗闸口"/>
      <el-table-column prop="vehicle_departure_time" label="车辆离岗时间"/>
    </el-table>
    <div class="page-btn-group">
      <div/><div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
export default{
  components: { Pagination },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      licenceTypeList: [
        // { ID: '', NAME: '请选择' },
        { ID: '0', NAME: '白牌' },
        { ID: '1', NAME: '蓝牌' },
        { ID: '2', NAME: '黄牌' },
        { ID: '3', NAME: '绿牌' },
        { ID: '4', NAME: '黑牌' }
      ],
      // 车辆类型列表
      vehicleTypeList: [
        // { ID: '', NAME: '请选择' },
        { ID: '0', NAME: '货车' },
        { ID: '1', NAME: '轿车' },
        { ID: '2', NAME: '大巴客车' }
      ],
      areaList: [], // 省市县列表
      placeList: [],
      listLoading: true,
      varList: [],
      total: 0,
      title: '',
      isShow: false,
      form: {
        LICENCE_NO: '',
        PHONE: '',
        ID_CARD: '',
        CORPINFO_NAME: '',
        DEPARTMENT_NAME: '',
        VISIT_START_TIME: '',
        VISIT_END_TIME: '',
        DOOR_NAME: '',
        TEMPORARY_TYPE: '2',
        CORPINFO_ID: JSON.parse(sessionStorage.getItem('user')).CORPINFO_ID
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    translateLicenceType(id) {
      for (var i = 0; i < this.licenceTypeList.length; i++) {
        if (this.licenceTypeList[i].ID == id) return this.licenceTypeList[i].NAME
      }
    },
    translateVehicleType(id) {
      for (var i = 0; i < this.vehicleTypeList.length; i++) {
        if (this.vehicleTypeList[i].ID == id) return this.vehicleTypeList[i].NAME
      }
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    // 重置
    reset() {
      this.form.LICENCE_NO = ''
      this.getList()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/mkmj/management/getCarExitRecords?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page, this.form
      ).then((data) => {
        console.log(data)
        this.listLoading = false
        this.varList = data.recordList
        this.total = data.page.totalResult
        this.hasButton()
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    }
  }

}
</script>

