<template>
  <div id="claimDetail">
    <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">
            <!--<claimForm :ruleForm="ruleForm"  @submitForm="submitForm" @resetForm="resetForm"></claimForm>-->
            <claimForm
              :ruleForm="claimForm"
              :saw="saw"
              @fallow="fallow"
              :jlList="jlList"
              :dialogFormVisible="dialogFormVisible"
              :zhipaiform="zhipaiform"
              @zhipaiformBtn="zhipaiformBtn"
              @quxiao="quxiao"
            ></claimForm>
          </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 claimForm from '@/layout/businessneed/claimForm.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: claimneed } = createNamespacedHelpers('claimneed');
const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
export default {
  name: 'claimDetail',
  props: {},
  components: {
    topInfo, //头部导航
    detailTop, //头部返回
    claimForm, //债权需求详情
  },
  data: () => ({
    display: 'none',
    topTitle: '债权信息详情',
    claimForm: {},
    charList: {
      name: '10',
    },
    saw: '1', //1是显示 0是显示已关注
    dialogFormVisible: false,
    zhipaiform: {},
    jlList: [],
  }),
  created() {
    this.searchInfo();
    this.safollow();
    this.setjlList();
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  methods: {
    ...claimneed(['followclaim', 'fclaim', 'one', 'beforFollow']),
    ...otheruser(['fetch', 'query']),
    async searchInfo() {
      if (this.id) {
        const res = await this.one({ id: this.id });
        this.$set(this, `claimForm`, res.data);
      }
    },
    async safollow() {
      if (this.id) {
        var userid = this.user.userid;
        const ress = await this.beforFollow({ finceId: this.id, userid: userid });
        if (ress.data.finstatus == 'SUCCESS') {
          this.$set(this, `saw`, '0');
        } else {
          this.$set(this, `saw`, '1');
        }
      }
    },
    async setjlList() {
      var userid = this.user.uid;
      const res = await this.query({ pid: userid });
      this.$set(this, `jlList`, res.data);
    },

    fallow() {
      this.dialogFormVisible = true;
    },
    quxiao() {
      this.dialogFormVisible = false;
    },
    // 指派
    async zhipaiformBtn({ data }) {
      console.log(this.id);
      console.log(data.uuid);
      let finceId = this.id;
      let userid = this.user.userid;
      let uuid = data.uuid;
      const res = await this.beforFollow({ finceId: finceId, userid: userid });
      if (res.data.finstatus == 'SUCCESS') {
        this.$message({
          message: '您已分配成功',
          type: 'success',
        });
      } else {
        const followres = await this.followclaim({ finceId: finceId, userid: userid, uuid: uuid });
        if (followres.errcode === 0) {
          this.$message({
            message: '分配成功',
            type: 'success',
          });
        } else {
          this.$message({
            message: '分配失败',
            type: 'error',
          });
        }
      }
      this.goBack();
    },
    // 返回
    goBack() {
      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>
