<template>
  <div id="intelligentDockingFollow">
    <el-row>
      <el-col :span="24">
        <el-col :span="24">
          <topInfo :topTitle="topTitle" :display="display"></topInfo>
        </el-col>
        <el-col :span="24">
          <searchInfo @clickBtn="clickBtn"></searchInfo>
        </el-col>
        <el-col :span="24">
          <intelligentDockingFollowList
            :debtTable="debtTable"
            :total="total"
            @pagechange="pagechange"
            :dockForm="dockForm"
            @deleteRow="deleteRow"
            @dockDormBtn="dockDormBtn"
            @dockOut="dockOut"
            :dialogFormVisible2="dialogFormVisible2"
            :dialogform="dialogform"
            @queding = "queding"
            @tongguosp="tongguosp"
            @quxiao="quxiao"
          ></intelligentDockingFollowList>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/intelligentDocking/searchInfo.vue';
import intelligentDockingFollowList from '@/layout/intelligentDocking/intelligentDockingFollowList.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: intelligentFollow } = createNamespacedHelpers('intelligentFollow');
const { mapActions: intelligentDocking } = createNamespacedHelpers('intelligentDocking');

export default {
  name: 'intelligentDockingFollow',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //查询
    intelligentDockingFollowList, //列表
  },
  data: () => ({
    topTitle: '银企对接关注',
    display: 'none',
    debtTable: [],
    total: 0,
    dockForm: {},
    // 拒绝当前数据
    jujueInfo: {},
    dialogFormVisible2: false,
    dialogform:{},
    zhuangtaiid:'',
  }),
  created() {
    this.searchInfo();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...intelligentFollow(['credit', 'getFollowList']),
    ...intelligentDocking(['refuseDocking']),
    async searchInfo({ skip = 1, limit = 10, userid = this.user.uid } = {}) {
      const res = await this.getFollowList({ skip, limit, userid });
      this.$set(this, `debtTable`, res.data.res);
      this.$set(this, `total`, res.data.total);
    },
    // 查询
    async clickBtn(message) {
      var skip = 0;
      var limit = 10;
      var userid = this.user.uid;
      var creditStatus = message;
      const res = await this.getFollowList({ skip, limit, userid, creditStatus });
      this.$set(this, `debtTable`, res.data.res);
      this.$set(this, `total`, res.data.total);
    },
    // 拒接按钮
    deleteRow(val) {
      console.log('jujue', val)
      this.$set(this, `jujueInfo`, val);
    },
    // 拒绝提交按钮
    async dockDormBtn({ data }) {
      data.guanzhuid = this.jujueInfo._id;
      data.intelligentId = this.jujueInfo.intelligentId;
      data.userid = this.jujueInfo.intelligent.uid;
      if (this.jujueInfo.intelligent.refuse_times == '3') {
        data.creditStatus = 3;
      }
      const res = await this.refuseDocking(data);
      if (res.errcode === 0) {
        this.$message({
          message: '拒绝成功',
          type: 'success',
        });
        this.dockOut();
        this.searchInfo();
      } else {
        this.$message.error('拒绝失败');
      }
    },
    // 取消
    dockOut() {
      this.dockForm = {};
    },
    // 通过
    async tongguosp(creditStatus,followid) {
      this.zhuangtaiid=followid;
      if (creditStatus == 0) {
        this.$confirm('此操作将通过审批, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.finalshenhe("审批通过");
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      } else if (creditStatus == 2) {
        this.dialogFormVisible2 = true;
      }
    },
    // 取消
    quxiao() {
      this.dialogform={};
      this.dialogFormVisible2 = 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, creditStatus: '1' });
      this.$checkRes(res, '授信成功', '授信失败');
      this.dialogform={};
      this.dialogFormVisible2 = false;
      this.searchInfo();
    },
    async finalshenhe(value) {
      const res = await this.credit({ id: this.zhuangtaiid, senhemessage: value, creditStatus: '2' });
      this.$checkRes(res, '通过成功', '通过失败');
      this.searchInfo();
    },
    // 分頁
    async pagechange(data) {
      var skip = data.skip;
      var limit = 10;
      var userid = this.user.uid;
      const res = await this.getFollowList({ skip, limit, userid });
      this.$set(this, `debtTable`, res.data.res);
      this.$set(this, `total`, res.data.total);
    },
  },
};
</script>

<style lang="less" scoped></style>
