<template>
    <div class="sefCarRec_container">
      <div class="title">
        <el-row>
          <el-col :span="24">
            <div class="top">
              <el-input  placeholder="公司名称" class="input-demo" v-model="companyName"></el-input>
              <el-input  placeholder="车牌号" class="input-demo" v-model="carNum"></el-input>
              <el-date-picker v-model="startTime" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="备案时间始" end-placeholder="备案时间止"></el-date-picker>
               <el-button type="success" style="margin-left: 1%;" @click="firstLoadData">查询</el-button>
               <el-button type="primary" style="margin-left: 1%;" @click="exportExcel">导出报表</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- 表格部分 -->
        <template>
        <el-table
          class="table"
          v-loading="loading"
          ref="multipleTable"
          :data="nocarRecCarTable"
         :height="heightt"
          border
          tooltip-effect="dark">
          <el-table-column
            label="客户名称"
            prop="customerName"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="companyName"
            label="公司名称"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="businessType"
            label="业务类型"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.businessType == 0">自有车</span>
              <span v-if="scope.row.businessType == 1">外协车</span>
              <span v-if="scope.row.businessType == 2">无车</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="carNum"
            label="车牌号"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="carColor"
            label="车辆颜色"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.carColor == 0" style="color: green">蓝色</span>
              <span v-else-if="scope.row.carColor == 1" >黄色</span>
              <span v-else-if="scope.row.carColor == 2" >黑色</span>
              <span v-else-if="scope.row.carColor == 3" >白色</span>
              <span v-else-if="scope.row.carColor == 4" >渐变绿色</span>
              <span v-else-if="scope.row.carColor == 5" >黄绿渐变色</span>
              <span v-else-if="scope.row.carColor == 6" >蓝白渐变色</span>
              <span v-else-if="scope.row.carColor == 7" >未确定</span>
              <span v-else-if="scope.row.carColor == 8" >未确定</span>
              <span v-else-if="scope.row.carColor == 9" >未确定</span>
            </template>
          </el-table-column>
           <el-table-column
            prop="custPhone"
            label="手机号"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="etcNum"
            label="ETC卡号"
            show-overflow-tooltip>
          </el-table-column>
           <el-table-column
            prop="interType"
            label="对接方式"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.interType == 0">接口</span>
              <span v-else-if="scope.row.interType == 1">平台</span>
              <span v-else-if="scope.row.interType == 3">迁移数据</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="recStatus"
            label="备案状态"
            show-overflow-tooltip>
             <template slot-scope="scope">
              <span v-if="scope.row.recStatus == 1" style="color: green">备案成功</span>
              <span v-else-if="scope.row.recStatus == 0" style="color: red">备案失败</span>
            </template>
          </el-table-column>
           <el-table-column
            prop="succTime"
            label="成功时间"
            show-overflow-tooltip>

          </el-table-column>
          <el-table-column
            prop="failTime"
            label="失败时间"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="failReason"
            label="失败原因"
            show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </template>
      <!-- 分页 -->
      <div class="block">
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[6, 8, 10, 20, 50, 100]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
      </div>
    </div>
</template>
<script type="text/javascript">
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
export default {
  data() {
    return {
      nocarRecCarTable: [],
      companyName: ``,
      carNum: ``,
      startTime: ``,
      hightt: `0px`,
      current: 1,
      pagesize: 8,
      total: ``
    }
  },
  created() {
    this.heightt = tableHeight  // eslint-disable-line
    this.loadData()
  },
  methods: {
    firstLoadData() {
      this.current = 1
      this.pagesize = 8
      this.loadData()
    },
    // 列表展示
    async loadData() {
      const formData = new FormData()
      formData.append(`current`, this.current)
      formData.append(`size`, this.pagesize)
      formData.append(`companyName`, this.companyName)
      formData.append(`carNum`, this.carNum)
      formData.append(`startTime`, this.startTime)
      formData.append(`businessType`, 2)
      const response = await this.$http.post(`noCar/findCarRec`, formData)
      if (response.data.code === 0) {
        this.nocarRecCarTable = response.data.data.records
        this.total = response.data.data.total
      }
    },
    // 分页方法
    handleSizeChange(val) {
      this.pagesize = val
      this.loadData()
    },
    handleCurrentChange(val) {
      this.current = val
      this.loadData()
    },
    async    exportExcel() {
      const loading = this.$loading({
        lock: true,
        text: `系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...`,
        spinner: `el-icon-loading`,
        background: `rgba(0, 0, 0, 0.7)`
      })
      let curr = this.current
      let pagesize1 = this.pagesize
      this.current = 1
      this.pagesize = this.total
      await this.loadData()
      // 设置当前日期
      let time = new Date()
      let year = time.getFullYear()
      let month = time.getMonth() + 1
      let day = time.getDate()
      let name = `无车车辆备案查询列表_` + year + `` + month + `` + day
      /* generate workbook object from table */
      //  .table要导出的是哪一个表格
      var wb = XLSX.utils.table_to_book(document.querySelector(`.table`), { raw: true })
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: `xlsx`,
        bookSST: true,
        type: `array`
      })
      try {
        //  name+'.xlsx'表示导出的excel表格名字
        FileSaver.saveAs(
          new Blob([wbout], { type: `application/octet-stream` }),
          name + `.xlsx`
        )
      } catch (e) {
      }
      this.current = curr
      this.pagesize = pagesize1
      this.loadData()
      loading.close()
      return wbout
    }
  }
}
</script>
<style>
.sefCarRec_container {
  border: 1px solid #d9d9d9;
  border-radius: 10px;
}
.sefCarRec_container .title {
  font-size: 5px;
  margin-bottom: 20px;
}
.sefCarRec_container .top {
  padding-top: 20px;
  padding-left: 20px;
}
.sefCarRec_container .text {
  display: inline-block;
  color: #000;
  font-size: 16px ;
  margin-left: 1%;
}
.sefCarRec_container .input-demo {
  display: inline-block;
  width: 20%;
  margin-left: 1%;
}
.sefCarRec_container .block {
  font-size: 5px;
  text-align: center;
  margin-top: 25px;
  margin-bottom: 25px;
}
.sefCarRec_container .el-dialog {
  width: 60%;
}
.sefCarRec_container .el-dialog__header, .el-dialog__body {
  padding: 0 20px;
}
.sefCarRec_container .tou {
  font-size: 20px;
  height: 30px;
  line-height: 30px;
  padding-top: 15px;
}
.sefCarRec_container .line {
  margin-top: 15px;
  margin-bottom: 15px;
  width: 100%;
  height: 2px;
  background-color: #d9d9d9;
}
.sefCarRec_container .xinxi {
  text-align: center;
  margin: 15px auto;
  font-size: 18px;
}
</style>