<template>
  <div id="intelligentDockingFollowDetail">
    <el-row>
      <el-col :span="24">
        <el-col :span="24">
          <topInfo :topTitle="topTitle" :display="display"></topInfo>
        </el-col>
        <el-col :span="24" class="main">
          <el-col :span="24">
            <detailTop @goBack="goBack"></detailTop>
          </el-col>
          <el-col :span="24">
            <intelligentDockingFollowDetails
                    :form="form"
                    :creditStatus="finorcredit"
                    @shouxin="shouxin"
                    :dialogFormVisible2="dialogFormVisible2"
                    :dialogform="dialogform"
                    @queding = "queding"
                    @quxiao="quxiao"
                    @deleteRow="deleteRow"
                    :dockForm="dockForm"
                    @dockDormBtn="dockDormBtn"
                    @dockOut="dockOut"
            ></intelligentDockingFollowDetails>
            <!--<intelligentDockingFollowDetails-->
            <!--:form="form"-->
            <!--:shenheForm="shenheForm"-->
            <!--@shenheBtns="shenheBtns"-->
            <!--@shenheOut="shenheOut"-->
            <!--@shenheBtn="shenheBtn"-->
            <!--:shouxinForm="shouxinForm"-->
            <!--:shouxinDialog="shouxinDialog"-->
            <!--@shouxinBtns="shouxinBtns"-->
            <!--@shouxinOut="shouxinOut"-->
            <!--@shouxinBtn="shouxinBtn"-->
            <!--&gt;</intelligentDockingFollowDetails>-->
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import topInfo from '@/layout/common/topInfo.vue';
  import detailTop from '@/layout/common/detailTop.vue';
  import intelligentDockingFollowDetails from '@/layout/intelligentDocking/intelligentDockingFollowDetails.vue';
  import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
  const { mapActions: intelligentDocking } = createNamespacedHelpers('intelligentDocking');
  const { mapActions: intelligentFollow } = createNamespacedHelpers('intelligentFollow');
  export default {
    name: 'intelligentDockingFollowDetail',
    props: {},
    components: {
      topInfo, //头部
      detailTop, //返回
      intelligentDockingFollowDetails, //详情
    },
    data: () => ({
      topTitle: '银企对接关注详情',
      display: 'none',
      form: {
        company: {},
        dictionary: {},
        finance_claims: {},
        when: {},
        follow: {},
      },
      // shenheForm: {},
      // shouxinDialog: false,
      // shouxinForm: {},

      finorcredit: '',
      dialogFormVisible2: false,
      dialogform:{},

      dialogFormVisible: false,
      dockForm: {},
      // 拒绝当前数据
      jujueInfo: {},
    }),
    created() {
      this.searchInfo();
      this.setorcredit();
    },
    computed: {
      ...mapState(['user']),
      intelligentId() {
        return this.$route.query.intelligentId;
      },
      creditStatus() {
        return this.$route.query.creditStatus;
      },
    },
    methods: {
      ...intelligentDocking(['dockingSearch','refuseDocking']),
      ...intelligentFollow(['credit']),
      // 查询详情
      async searchInfo() {
        if (this.intelligentId) {
          const res = await this.dockingSearch({ id: this.intelligentId });
          for (const val of res.result) {
            this.$set(this, `form`, val);
          }
        }
      },
      setorcredit() {
        this.$set(this, `finorcredit`, this.creditStatus);
      },
      // 授信
      async shouxin() {
        if (this.creditStatus == 0) {
          this.$confirm('此操作将通过审批, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.finalshenhe("审批通过");
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        } else if (this.creditStatus == 2) {
          this.dialogFormVisible2 = true;
        }
      },
      async finalshenhe(value) {
        const res = await this.credit({ id: this.form.follow._id, senhemessage: value, creditStatus: '2' });
        this.$checkRes(res, '审核成功', '审核失败');
        this.goBack();
      },
      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.form.follow._id,  money: data.money,sxcpname:data.sxcpname,sxhowlong:data.sxhowlong,sxcplilue:data.sxcplilue, creditStatus: '1' });
        this.$checkRes(res, '授信成功', '授信失败');
        this.dialogform={};
        this.dialogFormVisible2 = false;
        this.$router.go(-1);
      },
      quxiao() {
        this.dialogform={};
        this.dialogFormVisible2 = false;
      },
      // 拒接按钮
      deleteRow(val) {
        console.log('jujue', val)
        this.$set(this, `jujueInfo`, val);
      },
      // 拒绝提交按钮
      async dockDormBtn({ data }) {
        data.guanzhuid = this.jujueInfo.fid;
        data.intelligentId = this.jujueInfo.intelligentId;
        data.userid = this.jujueInfo.uid;
        if (this.jujueInfo.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 = {};
      },
      goBack() {
        this.$router.go(-1);
      },
      // // 打开审核
      // shenheBtns() {
      //   // this.shenheDialog = true;
      // },
      // // 取消审核
      // shenheOut() {
      //   // this.shenheDialog = false;
      //   this.shenheForm = {};
      // },
      // 提交审核
      // async shenhe({ data }) {
      //   data.id = this.form.follow._id;
      //   data.creditStatus = 2;
      //   const res = await this.credit(data);
      //   if (res.errcode === 0) {
      //     this.$message({
      //       message: '审核成功',
      //       type: 'success',
      //     });
      //     this.goBack();
      //     this.searchInfo();
      //   } else {
      //     this.$message.error('审核失败');
      //   }
      // },
      // 打开授信
      // shouxinBtns() {
      //   this.shouxinDialog = false;
      // },
      // // 取消授信
      // shouxinOut() {
      //   this.shouxinDialog = false;
      //   this.shouxinForm = {};
      // },
      // 提交授信
      // async shouxinBtn({ data }) {
      //   data.id = this.form.follow._id;
      //   data.creditStatus = 1;
      //   const res = await this.credit(data);
      //   if (res.errcode === 0) {
      //     this.$message({
      //       message: '授信成功',
      //       type: 'success',
      //     });
      //     this.goBack();
      //     this.searchInfo();
      //   } else {
      //     this.$message.error('授信失败');
      //   }
      // },
      // 返回

    },
  };
</script>

<style lang="less" scoped>
  .main {
    float: left;
    width: 100%;
    min-height: 780px;
    box-shadow: 0 0 5px #999;
    border-radius: 10px;
    padding: 20px;
  }
</style>
