<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="genDataBody.type" placeholder="请选择类型">
          <el-option
            v-for="item in typeOptions"
            :key="item.type"
            :label="item.typeName"
            :value="item.type"
          ></el-option>
        </el-select>
        <!-- 渠道 -->
        渠道：
        <el-select v-model="genDataBody.channel" placeholder="请选择渠道">
          <el-option
            v-for="item in channelList"
            :key="item.channel"
            :label="item.channelName"
            :value="item.channel"
          ></el-option>
        </el-select>
        <!-- 资方 -->
        资方：
        <el-input v-model="genDataBody.fundID" clearable placeholder="资方id" style="width: 200px;"></el-input>
      </div>
      <div>
        手机号：
        <el-input v-model="genDataBody.phoneNo" clearable placeholder="手机号" style="width: 200px;"></el-input>
        期数：
        <el-input v-model="genDataBody.termNo" clearable placeholder="期数" style="width: 200px"></el-input>金额：
        <el-input v-model="genDataBody.amount" clearable placeholder="金额" style="width: 200px"></el-input>
        <!-- 数据个数 -->
        数据个数：
        <el-input-number
          v-model="expectNum"
          @change="handleExpectNumChange"
          :min="1"
          :max="100"
          label="数据个数"
        ></el-input-number>
        <!-- 查询数据按钮 -->
        <el-button type="primary" style="margin-left:20px" @click="genData">生成数据</el-button>
      </div>
      <!-- 数据表格 -->
      <div class="dataTable">
        <el-table :data="dataTable" border style="width: 100%">
          <el-table-column type="phoneNo" label="phone_no" width="100px"></el-table-column>
          <el-table-column prop="userId" label="user_id" width="100px"></el-table-column>
          <el-table-column prop="uuid" label="uuid" width="250px"></el-table-column>
          <el-table-column prop="channel" label="注册渠道" width="100px"></el-table-column>
          <el-table-column prop="3" label="资方" width="100px"></el-table-column>
          <el-table-column prop="riskStatus" label="授信状态" width="100px"></el-table-column>
          <el-table-column prop="loanStatus" label="放款状态" width="100px"></el-table-column>
          <el-table-column prop="loanID" label="放款ID" width="100px"></el-table-column>
          <el-table-column prop="createdAt" label="创建时间"></el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      namespaceOptions: [],
      typeOptions: [],
      fundList: [],
      channelList: [],
      selectNamespace: '',
      expectNum: '1',
      // 生成数据接口的body
      genDataBody: {
        channel: '',
        termNo: '',
        amount: '',
        fundID: '',
        type: ''
      }
    }
  },
  created() {
    this.setBaseUrl()
  },
  methods: {
    setBaseUrl() {
      this.$axios.defaults.baseURL =
        'https://boss-' +
        window.sessionStorage.getItem('env') +
        '.liangkebang.net'
    },
    // 获取类型和渠道
    getTypeOptions() {
      this.$axios
        .get('/oneclickdate/v1/channelCode')
        .then((response) => {
          this.typeOptions = response['data']['data']['typeList']
          this.channelList = response['data']['data']['channelCodeList']
        })
        .catch((error) => {
          console.log(error)
          return this.$$message.error('获取类型和渠道失败！')
        })
    },
    // 渠道变化
    // selectChannelChange() {
    //   this.genDataBody.channel = this.selectChannel
    // },
    // 造数据
    genData() {
      if (this.genDataBody.type === '') {
        return this.$message.error('借款状态不能为空')
      }
      this.$axios
        .post('/oneclickdate/v1/type', this.genDataBody)
        .then((response) => {
          console.log(response)
        })
        .catch((error) => {
          console.log(error)
          return this.$message.error('数据生成失败！')
        })
    }
  },
  mounted() {
    this.getTypeOptions()
  }
}
</script>

<style lang="less" scoped>
.dataTable {
  margin-top: 20px;
}

.el-select {
  margin-right: 15px;
  margin-bottom: 10px;
}

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