<template>
  <div>
    <!-- 头部导航栏 -->
    <!-- <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>现金分期</el-breadcrumb-item>
      <el-breadcrumb-item>已有数据查询</el-breadcrumb-item>
    </el-breadcrumb> -->

    <!-- 卡片视图 -->
    <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>
        手机号：
        <el-input v-model="queryInfo.phone" clearable placeholder="手机号" style="width: 200px;"></el-input>
        金额：
        <el-input v-model="queryInfo.salary" clearable placeholder="金额" style="width: 200px;"></el-input>
        期数：
        <el-input v-model="queryInfo.termNo" clearable placeholder="期数" style="width: 200px;"></el-input>
      </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="userId" 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="channelName" label="注册渠道名" width="120px"></el-table-column> -->
          <el-table-column prop="fundId" label="资方id" width="120px"></el-table-column>
          <!-- <el-table-column prop="fundName" label="资方名称" 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 === 1" type="success">启用</el-tag>
              <el-tag v-else-if="scope.row.enable === 0" 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 {
  inject: ['reload'],
  data() {
    return {
      baseUrl: '',
      // namespaceOptions: [],
      statusOptions: [],
      dataTable: [],
      // selectNamespace: '',
      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.content
          this.totalNum = response.data.data.totalNum
          console.log(this.dataTable)
        })
        .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>
