<template>
  <div id="followindex">
    <el-col :span="24" class="debt">
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle" :display="display"></topInfo>
      </el-col>
      <el-col :span="24" class="search">
        <searchInfo @clickBtn="clickBtn"></searchInfo>
      </el-col>
      <el-col :span="24" class="main">
        <followList :debtTable="debtTable" :total="total"  :dialogFormVisible="dialogFormVisible" :dialogform="dialogform"
                    @queding = "queding" @tongguosp="tongguosp" @quxiao="quxiao" @pagechange="pagechange" @deleteRow="deleteRow"></followList>
      </el-col>
    </el-col>
    <el-col :span="24">
      <el-dialog title="拒绝" :visible.sync="deleteVisible" :show-close="false">
        <el-form :model="delForm">
          <el-form-item label="拒绝理由">
            <el-select v-model="delForm.delValue" placeholder="请选择拒绝理由" style="width:100%">
              <el-option v-for="(item, index) in dellist" :key="index" :value="item"> </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="quxiaodel">取 消</el-button>
          <el-button type="primary" @click="quedingdel(delForm)">确 定</el-button>
        </div>
      </el-dialog>
    </el-col>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import followList from '@/layout/follow/followList.vue';
import searchInfo from '@/layout/common/followztInfo.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: financefollow } = createNamespacedHelpers('follow');
export default {
  name: 'followindex',
  props: {},
  components: {
    topInfo, //头部导航
    followList, //债权需求列表
    searchInfo,
  },
  data: () => ({
    topTitle: '授信债权需求',
    display: 'none',
    debtTable: [],
    total: '',
    jgpro: '0',
    orcredit: 'SUCC',
    dialogFormVisible: false,
    dialogform:{},
    zhuangtaiid:'',
    deleteVisible:false,
    delid:'',
    delForm:{
      delValue: ''
    },
    dellist:[
      '基础信息不符:借款人基础信息如经营年限、相关资质等不符合我行相关产品',
      '信息弄虚作假:填写申请贷款时借款人对资料进行作假',
      '高危禁入行业:本行认定高危禁入行业',
      '法律纠纷:借款人身负法律纠纷，尤其是经济纠纷',
      '不良征信记录:借款人存在不良信贷记录，且不符合我行准入标准',
      '还款能力不足:根据借款人实际经营情况无偿还贷款能力',
      '缺乏担保方式:抵质押物不符合我行标准或不足值',
      '其他原因:除上述外其他原因'
    ],
  }),
  created() {
    this.followList();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...financefollow(['credit', 'followlist', 'delete']),
    async followList({ skip = 1, limit = 10, userid = this.user.uid, finceType = this.jgpro } = {}) {
      const res = await this.followlist({ skip, limit, userid, finceType });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    // 删除
    async deleteRow(id,deleteRow) {
      this.delForm.delValue = deleteRow;
      this.delid = id;
      this.deleteVisible = true;
    },

    async pagechange(data) {
      var skip = data.skip;
      var limit = 10;
      var userid = this.user.uid;
      var finceType = this.jgpro;
      var res;
      if (this.orcredit == 'SUCC') {
        res = await this.followlist({ skip, limit, userid, finceType });
      } else {
        var finalorc = this.orcredit;
        res = await this.followlist({ skip, limit, userid, finceType, finalorc });
      }
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    async clickBtn(message) {
      //查询
      this.orcredit = message;
      var skip = 0;
      var limit = 10;
      var userid = this.user.uid;
      var finceType = this.jgpro;
      var finalorc = message;
      const res = await this.followlist({ skip, limit, userid, finceType, finalorc });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    async tongguosp(orcredit,followid) {
      this.zhuangtaiid=followid;
      if (orcredit == 0) {
        this.$confirm('此操作将通过审批, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.finalshenhe("审批通过");
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      } else if (orcredit == 2) {
        this.dialogFormVisible = true;
      }
    },
    quxiao() {
      this.dialogform={};
      this.dialogFormVisible = false;
    },

    async queding({ data }) {
      if(!data.money){
        alert("请输入金额");
        return;
      }
      if(!data.sxcpname){
        alert("产品名称");
        return;
      }
      if(!data.sxhowlong){
        alert("请输入产品期限");
        return;
      }
      if(!data.sxcplilue){
        alert("请输入产品利率");
        return;
      }
      const res = await this.credit({ id: this.zhuangtaiid, money: data.money,sxcpname:data.sxcpname,sxhowlong:data.sxhowlong,sxcplilue:data.sxcplilue, orcredit: '1' });
      this.$checkRes(res, '授信成功', '授信失败');
      this.dialogform={};
      this.dialogFormVisible = false;
      this.followList();
    },

    async finalshenhe(value) {
      const res = await this.credit({ id: this.zhuangtaiid, senhemessage: value, orcredit: '2' });
      this.$checkRes(res, '通过成功', '通过失败');
      this.followList();
    },

    quxiaodel() {
      this.deleteVisible = false;
    },

    async quedingdel(data) {
      const res = await this.credit({id:this.delid,jindiaomessage:data.delValue,orcredit:'3'});
      this.$checkRes(res, '拒绝成功', '拒绝失败');
      this.followList();
      this.deleteVisible = false;
    },
  },
};
</script>

<style lang="less" scoped>
.debt {
  padding: 20px;
}
.top {
  border-bottom: 1px solid #ccc;
}
</style>
