<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>
      <!-- namespace下拉框 -->
      <div class="filter">
        <p>
          Namespace:
          <el-select v-model="selectNamespace" placeholder="请选择namespace">
            <el-option
              v-for="item in namespaceOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </p>
        <!-- 借款状态下拉框 -->
        <p>
          借款状态：
          <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>
        </p>
        <!-- 查询数据按钮 -->
        <p>
          <el-button type="primary" style="margin-left:20px" @click="getTableData">查询数据</el-button>
        </p>
      </div>
      <!-- 数据表格 -->
      <div class="dataTable">
        <el-table :data="dataTable" border style="width: 100%">
          <el-table-column prop="phoneNo" label="phone_no" width="150px"></el-table-column>
          <el-table-column prop="userId" label="user_id" width="100px"></el-table-column>
          <el-table-column prop="uuid" label="uuid" width="330px"></el-table-column>
          <el-table-column prop="enable" label="enable" width="100px">
            <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-column prop="registeredFrom" label="注册渠道" width="100px"></el-table-column>
          <el-table-column prop="createdAt" label="创建时间" width="200px"></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>
export default {
  data() {
    return {
      namespaceOptions: [],
      statusOptions: [],
      dataTable: [],
      selectNamespace: 'qa',
      selectStatus: '',
      totalNum: 0,
      queryInfo: {
        status: '',
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  created() {},
  methods: {
    // 获取namespace选项
    getNamespaceOptions() {
      this.$axios
        .get('/allEnvInfo')
        .then(response => {
          this.namespaceOptions = response['data']['data']
        })
        .catch(error => console.log(error))
    },
    // 获取状态选项
    getStatusOptions() {
      this.$axios
        .get('/allUserLoanStatus')
        .then(response => {
          this.statusOptions = response['data']['data']
        })
        .catch(error => console.log(error))
    },
    // 获取表格数据
    getTableData() {
      this.dataTable = []
      this.$axios
        .get('/getLoanUserData', { params: 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))
    },
    selectStatusChange() {
      this.queryInfo.status = this.selectStatus
    },
    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;
}

.filter {
  display: flex;
  p {
    margin-right: 20px;
  }
}
</style>
