<template>
  <div>
    <el-card>
      手机号：<el-input v-model="riskControlParams.phoneNo" placeholder="请输入手机号" maxlength="11"></el-input>
      授信结果： <el-select v-model="riskControlParams.result" placeholder="请选择授信状态">
        <el-option v-for="item in riskStatus" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      授信金额：<el-input v-model="riskControlParams.amount" placeholder="请输入授信金额"></el-input>
      <el-button type="primary" @click="doVccRiskControl">开始回调</el-button>
      <el-table :data="dataTable" border style="width: 100%">
        <el-table-column prop="phoneNo" label="手机号" width="120px"></el-table-column>
        <el-table-column prop="userId" label="userId" width="100px"></el-table-column>
        <el-table-column prop="uuid" label="uuid" width="320px"></el-table-column>
        <el-table-column prop="registeredFrom" label="注册渠道" width="100px"></el-table-column>
        <el-table-column prop="nextApplyTime" label="过期时间" width="180px"></el-table-column>
        <el-table-column prop="createdAt" label="创建时间" width="180px"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { vccRiskControl } from '@/api/genVccData'
import { queryUserData } from '@/api/checkVccData'
export default {
  data() {
    return {
      riskControlParams: {
        namespace: window.sessionStorage.getItem('env'),
        phoneNo: '',
        result: '',
        amount: 10000
      },
      queryUserDataParams: {
        namespace: window.sessionStorage.getItem('env'),
        phoneNo: ''
      },
      riskStatus: [
        {
          label: '授信成功',
          value: true
        },
        {
          label: '授信失败',
          value: false
        }
      ],
      dataTable: []
    }
  },
  methods: {
    doVccRiskControl() {
      if (this.riskControlParams.phoneNo === '') {
        return this.$message.error('手机号不允许为空！')
      }
      vccRiskControl(this.riskControlParams)
        .then((resp) => {
          if (resp.data.success === true) {
            this.queryUserDataParams.phoneNo = this.riskControlParams.phoneNo
            queryUserData(this.queryUserDataParams).then((resp) => {
              this.dataTable.push(resp.data.data)
            })
            return this.$message.success('手动授信回调成功！')
          } else {
            return this.$message.error(resp.data.msg)
          }
        })
        .catch((error) => {
          this.$message({ type: 'error', message: error })
        })
    }
  }
}
</script>

<style lang="less" scoped>
.el-input {
  width: 200px;
  margin-right: 20px;
}
.el-select {
  margin-right: 20px;
}
.el-table {
  margin-top: 20px;
}
</style>
