<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="count" placeholder="数量" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"/>
      <el-select v-model="province" placeholder="省份" clearable style="width: 200px" class="filter-item">
        <el-option v-for="item in provinceList" :key="item" :label="item" :value="item"/>
      </el-select>
      <el-select v-model="bank" placeholder="银行" clearable class="filter-item" style="width: 200px">
        <el-option v-for="item in bankList" :key="item" :label="item" :value="item"/>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-view" @click="generate">生成</el-button>
    </div>

    <el-table
      v-loading="listLoading"
      :data="peopleInfo"
      fit
      stripe
      highlight-current-row
      style="width: 100%;">
      border
      @sort-change="sortChange">

      <el-table-column label="姓名" width="65px">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证号" width="165px">
        <template slot-scope="scope">
          <span>{{ scope.row.IDCardNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="Sex" width="46px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.sex }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生日" width="100px">
        <template slot-scope="scope">
          <span>{{ scope.row.birthday }}</span>
        </template>
      </el-table-column>
      <el-table-column label="通信地址">
        <template slot-scope="scope">
          <span>{{ scope.row.address }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" width="110px">
        <template slot-scope="scope">
          <span>{{ scope.row.mobile }}</span>
        </template>
      </el-table-column>
      <el-table-column label="Email" width="150px">
        <template slot-scope="scope">
          <span>{{ scope.row.email }}</span>
        </template>
      </el-table-column>
      <el-table-column label="银行卡号" width="175px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.bankNo }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属银行" width="145px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.bankType }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getAll" /> -->

  </div>
</template>

<script>
import { getAll, getBankList, getProvinceList } from '@/api/testdata'
import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      total: 0,
      listLoading: true,
      provinceList: [],
      bankList: [],
      peopleInfo: null,
      count: 5,
      province: null,
      bank: null
    }
  },
  created() {
    this.getProvinceList()
    this.getBankList()
    this.generate()
  },
  methods: {
    getProvinceList() {
      getProvinceList().then(response => {
        this.provinceList = response.data.data
      })
    },
    getBankList() {
      getBankList().then(response => {
        this.bankList = response.data.data
      })
    },
    getAll(query) {
      this.listLoading = true
      getAll(query).then(res => {
        this.peopleInfo = res.data.data
        this.total = res.data.count
        this.listLoading = false
      })
    },
    generate() {
      if (this.count <= 100) {
        this.getAll({
          count: this.count,
          province: this.province,
          bank: this.bank
        })
      } else {
        this.$message({
          message: '"数量"请输入1到100之间的整数',
          type: 'warning'
        })
      }
    }
  }
}
</script>
