<template>
  <div>
    <el-card>
      <div>
        <!-- 借款状态下拉框 -->
        借款状态：
        <el-select v-model="selectStatus" placeholder="请选择借款状态" @change="selectStatusChange">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <!-- 渠道 -->
        渠道：
        <el-input v-model="queryInfo.channel" clearable placeholder="渠道id" style="width: 200px;"></el-input>
        <!-- 资方 -->
        资方：
        <el-input v-model="queryInfo.fundId" clearable placeholder="资方id" style="width: 200px;"></el-input>
        <el-button type="primary" style="margin-left:20px" @click="checkData">查询数据</el-button>
      </div>
      <!-- 数据表格 -->
      <div class="dataTable">
        <el-table :data="dataTable" border style="width: 100%">
          <el-table-column prop="phoneNo" label="手机号" width="150px"></el-table-column>
          <el-table-column prop="id" label="userId" width="100px"></el-table-column>
          <el-table-column prop="uuid" label="uuid" width="330px"></el-table-column>
          <el-table-column prop="registeredFrom" label="注册渠道" width="120px"></el-table-column>
          <el-table-column prop="fundId" label="资方id" width="120px"></el-table-column>
          <el-table-column prop="createdAt" label="创建时间" width="200px"></el-table-column>
          <el-table-column prop="enable" label="enable">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.enable === true" type="success">启用</el-tag>
              <el-tag v-else-if="scope.row.enable === false" type="danger">停用</el-tag>
            </template>
          </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 { getAllStatus, queryLoanUser } from '@/api/getXyqbData'
export default {
  data() {
    return {
      baseUrl: '',
      statusOptions: [],
      dataTable: [],
      selectStatus: '',
      totalNum: 0,
      queryInfo: {
        namespace: window.sessionStorage.getItem('env'),
        status: '',
        channel: '',
        fundId: '',
        phone: '',
        salary: '',
        termNo: '',
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    // 获取状态选项
    getStatusOptions() {
      getAllStatus()
        .then((response) => {
          this.statusOptions = response['data']['data']
        })
        .catch((error) => console.log(error))
    },
    // 获取表格数据
    getTableData() {
      if (this.selectNamespace === '') {
        return this.$message.error('namespace不能为空！')
      }
      if (this.selectStatus === '' || this.selectStatus === null) {
        return this.$message.error('状态不能为空！')
      }
      this.dataTable = []
      queryLoanUser(this.queryInfo)
        .then((response) => {
          this.dataTable = response.data.data.list
          this.totalNum = response.data.data.total
        })
        .catch((error) => console.log(error))
    },
    checkData() {
      this.queryInfo.pageNum = 1
      this.queryInfo.pageSize = 10
      this.getTableData()
    },
    // 用户状态改变
    selectStatusChange() {
      this.queryInfo.status = this.selectStatus
    },
    // namespace改变
    selectNamespaceChange() {
      this.queryInfo.namespace = this.selectNamespace
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
      this.getTableData()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
      this.getTableData()
    }
  },
  mounted() {
    // this.getNamespaceOptions()
    this.getStatusOptions()
  }
}
</script>

<style lang="less" scoped>
.dataTable {
  margin-top: 20px;
}
.el-select {
  margin-right: 15px;
  margin-bottom: 10px;
}

.el-input {
  margin-right: 15px;
}
</style>
