<template>
  <div>
    <el-card>
      <div class="filter">
        用户状态：
        <el-select v-model="userStatus" @change="selectUserStatusChange" placeholder="请选择用户状态">
          <el-option v-for="item in statusOption" :key="item.label" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-button type="primary" style="margin-left: 20px" icon="el-icon-search" @click="searchVccData">查询</el-button>
      </div>
      <!-- 数据表格 -->
      <div class="dataTable">
        <el-table :data="dataTable" border style="width: 100%">
          <el-table-column prop="phoneNo" label="手机号" width="120px"></el-table-column>
          <el-table-column prop="userId" label="userId" width="80px"></el-table-column>
          <el-table-column prop="uuid" label="uuid" width="330px"></el-table-column>
          <el-table-column prop="enableAmount" label="可用额度" width="100px"></el-table-column>
          <el-table-column prop="riskAmount" label="用户总额度" width="100px"></el-table-column>
          <el-table-column prop="registeredFrom" label="注册渠道" width="100px"></el-table-column>
          <el-table-column prop="nextApplyTime" label="过期时间" width="200px"></el-table-column>
          <el-table-column prop="createdAt" label="创建时间"></el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page.sync="queryInfo.pageNum" :page-size="queryInfo.pageSize" layout="total, prev, pager, next"
        :total="totalNum"></el-pagination>

    </el-card>
  </div>
</template>

<script>
import { getVccData } from '@/api/getVccData'
export default {
  data() {
    return {
      userStatus: '',
      queryInfo: {
        namespace: window.sessionStorage.getItem('env'),
        status: '',
        pageNum: 1,
        pageSize: 10
      },
      totalNum: 0,
      statusOption: [
        { label: '初始状态', value: 0 },
        { label: '授信成功未开户', value: 1 },
        { label: '授信失败', value: 2 },
        { label: '禁用', value: 3 },
        { label: '审核中', value: 4 },
        { label: '冻结', value: 5 },
        { label: '开户成功', value: 6 },
        { label: '开户失败', value: 7 }
      ],
      dataTable: []
    }
  },
  methods: {
    selectUserStatusChange() {
      this.queryInfo.status = this.userStatus
    },
    getVccData() {
      getVccData(this.queryInfo)
        .then((resp) => {
          if (resp.data.success === true) {
            this.dataTable = resp.data.data.list
            this.totalNum = resp.data.data.total
          } else {
            return this.$message.error(resp.data.msg)
          }
        })
        .catch((error) => {
          this.$message({ type: 'error', message: error })
        })
    },
    // 查询vcc数据
    searchVccData() {
      this.queryInfo.namespace = window.sessionStorage.getItem('env')
      this.getVccData()
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
      this.getVccData()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
      this.getVccData()
    }
  }
}
</script>

<style lang="less" scoped>
.filter {
  margin-bottom: 15px;
  font-size: 14px;
}
</style>
