<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 class="filter-item" type="primary" icon="el-icon-view" @click="generate">生成</el-button>
    </div>

    <el-table :data="peopleInfo" highlight-current-row fit style="width: 100%;">
      <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>

  </div>
</template>

<script>
import { getAll, getBankList, getProvinceList } from '@/api/testdata'

export default {
  data() {
    return {
      tableKey: 0,
      total: 0,
      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) {
      getAll(query).then((res) => {
        this.peopleInfo = res.data.data
        this.total = res.data.count
      })
    },
    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>

<style lang="less" scoped>
.app-container {
  padding: 20px;
}
.filter-container {
  padding-bottom: 10px;

  .filter-item {
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 10px;
  }
}
</style>
