<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.USER_NAME" 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="USER_NAME" label="访问人姓名"/>
      <el-table-column prop="PHONE" label="手机号"/>
      <el-table-column prop="CORPINFO_NAME" label="企业名称"/>
      <el-table-column prop="DEPARTMENT_NAME" label="部门名称"/>
      <el-table-column prop="CAR_NO" label="车牌号"/>
      <el-table-column label="车牌类型" align="center" width="120">
        <template slot-scope="{row}">
          {{ getCarPlantType(row.CAR_PLANT_TYPE) }}
        </template>
      </el-table-column>
      <el-table-column label="车辆类型" align="center" width="120">
        <template slot-scope="{row}">
          {{ getCarType(row.CAR_TYPE) }}
        </template>
      </el-table-column>
      <el-table-column prop="VISIT_START_TIME" label="访问起始时间"/>
      <el-table-column prop="VISIT_END_TIME" label="访问结束时间"/>
      <el-table-column prop="DOOR_NAME" label="访问口门名称"/>
      <el-table-column label="操作" align="left" width="110">
        <template slot-scope="{row}">
          <el-button type="primary" icon="el-icon-view" size="mini" @click="getAuditInfo(row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div/><div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
    <flow-step ref="flowStep" append-to-body @refresh="getList"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import FlowStep from '../../preson/components/flowStep.vue'
export default{
  components: { FlowStep, Pagination },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      areaList: [], // 省市县列表
      placeList: [],
      listLoading: true,
      varList: [],
      total: 0,
      title: '',
      isShow: false,
      form: {
        USER_NAME: '',
        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: {
    // 获取车牌类型
    getCarPlantType(CAR_PLANT_TYPE) {
      if (CAR_PLANT_TYPE === '0') {
        return '白牌'
      } else if (CAR_PLANT_TYPE === '1') {
        return '蓝牌'
      } else if (CAR_PLANT_TYPE === '2') {
        return '黄牌'
      } else if (CAR_PLANT_TYPE === '3') {
        return '绿牌'
      } else if (CAR_PLANT_TYPE === '4') {
        return '黑牌'
      }
    },

    getCarType(CAR_TYPE) {
      if (CAR_TYPE === '0') {
        return '货车'
      } else if (CAR_TYPE === '1') {
        return '轿车'
      } else if (CAR_TYPE === '2') {
        return '大巴客车'
      }
    },
    // 判断审核按钮权限
    showFirstButton(FIRST_AUDIT_USER_ID, AUDIT_TYPE) {
      return FIRST_AUDIT_USER_ID === JSON.parse(sessionStorage.getItem('user')).USER_ID && AUDIT_TYPE === '1'
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    // 重置
    reset() {
      this.form = {
        USER_NAME: '',
        PHONE: '',
        ID_CARD: '',
        CORPINFO_NAME: '',
        DEPARTMENT_NAME: '',
        VISIT_START_TIME: '',
        VISIT_END_TIME: '',
        DOOR_NAME: ''
      }
      this.getList()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/mkmj/management/getZgAccessList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page, this.form
      ).then((data) => {
        console.log(data)
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
        this.hasButton()
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getAuditInfo(row) {
      this.$refs.flowStep.init(row)
    }
  }

}
</script>

