<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.phone" 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="channel" label="注册渠道id" width="100px"></el-table-column>
          <el-table-column prop="fundId" label="资方id" width="100px"></el-table-column>
          <el-table-column prop="amount" label="金额" width="100px"></el-table-column>
          <el-table-column prop="term" label="期数" width="100px"></el-table-column>
          <el-table-column prop="status" label="状态" width="100px"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" @click="retryToGen(scope.row.phoneNo)">重试</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      namespaceOptions: [],
      typeOptions: [],
      fundList: [],
      channelList: [],
      selectNamespace: '',
      expectNum: '1',
      // 生成数据接口的body
      genDataBody: {
        phone: '',
        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('借款状态不能为空')
      }
      if (this.genDataBody.channel === '') {
        return this.$message.error('渠道不能为空')
      }
      if (this.genDataBody.fundID === '') {
        return this.$message.error('资方不能为空')
      }
      this.$axios
        .post('/oneclickdate/v1/type', this.genDataBody)
        .then((resp) => {
          console.log(resp)
          return this.$message.success('开始生成数据...')
        })
        .catch((error) => {
          console.log(error)
          return this.$message.error('数据生成失败！')
        })
    },
    retryToGen(phoneNo) {}
  },
  mounted() {
    this.getTypeOptions()
  }
}
</script>

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

// .filter {
//   margin-bottom: 10px;
// }

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

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