<template>
  <div id="followDetail">
    <el-row>
      <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="main">
          <el-col :span="24" class="back">
            <detailTop @goBack="goBack"></detailTop>
          </el-col>
          <el-col :span="24" class="info">
            <followForm :ruleForm="followForm" :orcredit="finorcredit" @shouxin="shouxin"
                        :dialogFormVisible="dialogFormVisible" :dialogform="dialogform"
                        @queding = "queding" @quxiao="quxiao" @deleteRow="deleteRow"></followForm>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
    <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 detailTop from '@/layout/common/detailTop.vue';
import followForm from '@/layout/follow/followForm.vue';
import { createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: claimneed } = createNamespacedHelpers('claimneed');
const { mapActions: financefollow } = createNamespacedHelpers('follow');
export default {
  name: 'followDetail',
  props: {},
  components: {
    topInfo, //头部导航
    detailTop, //头部返回
    followForm, //关注债权需求详情
  },
  data: () => ({
    display: 'none',
    topTitle: '关注债权需求详情',
    followForm: {},
    charList: {
      name: '10',
    },
    finorcredit: '',
    dialogFormVisible: false,
    dialogform:{},
    deleteVisible:false,
    delForm:{
      delValue: ''
    },
    dellist:[
      '基础信息不符:借款人基础信息如经营年限、相关资质等不符合我行相关产品',
      '信息弄虚作假:填写申请贷款时借款人对资料进行作假',
      '高危禁入行业:本行认定高危禁入行业',
      '法律纠纷:借款人身负法律纠纷，尤其是经济纠纷',
      '不良征信记录:借款人存在不良信贷记录，且不符合我行准入标准',
      '还款能力不足:根据借款人实际经营情况无偿还贷款能力',
      '缺乏担保方式:抵质押物不符合我行标准或不足值',
      '其他原因:除上述外其他原因'
    ],
  }),
  created() {
    this.searchInfo();
    this.setorcredit();
  },
  computed: {
    id() {
      return this.$route.query.id;
    },
    sxid() {
      return this.$route.query.sxid;
    },
    orcredit() {
      return this.$route.query.orcredit;
    },
  },
  methods: {
    ...claimneed(['one']),
    ...financefollow(['credit', 'followlist', 'delete']),
    async searchInfo() {
      if (this.id) {
        const res = await this.one({ id: this.id });
        this.$set(this, `followForm`, res.data);
      }
    },
    setorcredit() {
      this.$set(this, `finorcredit`, this.orcredit);
    },
    // 授信
    async shouxin() {
      if (this.orcredit == 0) {
        this.$confirm('此操作将通过审批, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.finalshenhe("审批通过");
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      } else if (this.orcredit == 2) {
        this.dialogFormVisible = true;
      }
    },
    // async finalSx(value) {
    //   const res = await this.credit({ id: this.sxid, money: value, orcredit: '1' });
    //   this.$checkRes(res, '授信成功', '授信失败');
    //   this.goBack();
    // },
    async finalshenhe(value) {
      const res = await this.credit({ id: this.sxid, senhemessage: value, orcredit: '2' });
      this.$checkRes(res, '审核成功', '审核失败');
      this.goBack();
    },
    // async finaljindiao(value){
    //   const res = await this.credit({id:this.sxid,jindiaomessage:value,orcredit:'3'});
    //   this.$checkRes(res, '尽调成功', '尽调失败');
    //   this.goBack();
    // },
    // 返回
    goBack() {
      this.$router.go(-1);
    },
    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.sxid,  money: data.money,sxcpname:data.sxcpname,sxhowlong:data.sxhowlong,sxcplilue:data.sxcplilue, orcredit: '1' });
      this.$checkRes(res, '授信成功', '授信失败');
      this.dialogform={};
      this.dialogFormVisible = false;
      this.$router.go(-1);
    },
    quxiao() {
      this.dialogform={};
      this.dialogFormVisible = false;
    },
    async deleteRow() {
      this.delForm.delValue = '';
      this.deleteVisible = true;
    },


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

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

<style lang="less" scoped>
.debt {
  padding: 20px;
}
.top {
  border-bottom: 1px solid #ccc;
}
.main {
  border-radius: 10px;
  margin: 20px 0 0 0;
  box-shadow: 0 0 3px #666;
}
.main .back {
  padding: 10px 0 10px 15px;
}
</style>
