<template>
  <div id="claim">
    <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">
        <claimList
          :debtTable="debtTable"
          :total="total"
          :jlList="jlList"
          :dialogFormVisible="dialogFormVisible"
          :zhipaiform="zhipaiform"
          @pagechange="pagechange"
          @zhipai="zhipai"
          @zhipaiformBtn="zhipaiformBtn"
          @quxiao="quxiao"
        ></claimList>
      </el-col>
    </el-col>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/common/needSearchInfo.vue';
import claimList from '@/layout/businessneed/claimList.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: claimneed } = createNamespacedHelpers('claimneed');
const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
export default {
  name: 'claim',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //搜素
    claimList, //债权需求列表
  },
  data: () => ({
    topTitle: '|债权需求|',
    display: 'none',
    debtTable: [],
    total: '',
    jgpro: '0',
    jlList: '',
    zpid: '',
    dialogFormVisible: false,
    zhipaiform: {},
  }),
  created() {
    this.claimList();
    this.setjlList();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...claimneed(['followclaim', 'fclaim', 'one', 'beforFollow']),
    ...otheruser(['fetch', 'query']),
    async claimList({ skip = 1, limit = 10, jg_id = this.user.userid } = {}) {
      const res = await this.fclaim({ skip, limit, jg_id });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    async setjlList() {
      var userid = this.user.uid;
      const res = await this.query({ pid: userid });
      this.$set(this, `jlList`, res.data);
    },
    async pagechange(data) {
      var skip = data.skip;
      var limit = 10;
      var jg_id;
      if (this.jgpro == '0') {
        jg_id = this.user.userid;
      } else {
        jg_id = '0';
      }
      const res = await this.fclaim({ skip, limit, jg_id });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    async clickBtn(message) {
      //查询
      this.jgpro = message;
      var skip = 1;
      var limit = 10;
      if (message == 1) {
        var jg_id = '0';
        const res = await this.fclaim({ skip, limit, jg_id });
        this.$set(this, `debtTable`, res.res);
        this.$set(this, `total`, res.total);
      } else {
        var jg_id = this.user.userid;
        const res = await this.fclaim({ skip, limit, jg_id });
        this.$set(this, `debtTable`, res.res);
        this.$set(this, `total`, res.total);
      }
    },
    quxiao() {
      this.dialogFormVisible = false;
    },
    //指派
    async zhipai(valid) {
      this.zpid = valid;
      let userid = this.user.userid;
      const res = await this.beforFollow({ finceId: valid, userid: userid });
      if (res.data.finstatus == 'SUCCESS') {
        this.$message({
          message: '您已分配过该需求',
          type: 'success',
        });
      } else {
        this.dialogFormVisible = true;
      }
    },
    async zhipaiformBtn({ data }) {
      let finceId = this.zpid;
      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.dialogFormVisible = false;
    },
  },
};
</script>

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