<template>
  <div id="intelligent">
    <el-col :span="24" class="debt">
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle" :display="display"></topInfo>
      </el-col>

      <el-col :span="24">
        <intelligentDockingList
          :debtTable="debtTable"
          :total="total"
          :jlList="jlList"
          :dialogFormVisible="dialogFormVisible"
          @pagechange="pagechange"
          :zhipaiform="zhipaiform"
          @zhipai="zhipai"
          @zhipaiformBtn="zhipaiformBtn"
          @quxiao="quxiao"
        ></intelligentDockingList>
      </el-col>
    </el-col>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import intelligentDockingList from '@/layout/intelligentDocking/intelligentDockingList.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: intelligent } = createNamespacedHelpers('intelligentDocking');
const { mapActions: intelligentFollow } = createNamespacedHelpers('intelligentFollow');
const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
export default {
  name: 'intelligent',
  props: {},
  components: {
    topInfo, //头部导航
    intelligentDockingList, //需求列表
  },
  data: () => ({
    topTitle: '银企对接需求',
    display: 'none',
    debtTable: [ ],
    total: 0,
    jgpro: '0',
    jlList: '',
    zpid: '',
    dialogFormVisible: false,
    zhipaiform: {},
  }),
  created() {
    this.intelligentDockingList();
    this.setjlList();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...intelligent(['dockingSearch', 'update']), // 列表,修改关注状态
    ...intelligentFollow(['beforFollow', 'followIntelligent']),
    ...otheruser(['fetch', 'query']),
    async intelligentDockingList({ skip = 1, limit = 10, jg_id = this.user.userid } = {}) {
      const res = await this.dockingSearch({ skip, limit, jg_id });
      this.$set(this, `debtTable`, res.result);
      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 = this.user.userid;
      const res = await this.dockingSearch({ skip, limit, jg_id });
      this.$set(this, `debtTable`, res.result);
      this.$set(this, `total`, res.total);
    },
    async clickBtn(message) {
      //查询
      this.jgpro = message;
      var skip = 0;
      var limit = 10;
      if (message == 1) {
        var jg_id = '0';
        const res = await this.dockingSearch({ skip, limit, jg_id });
        this.$set(this, `debtTable`, res.result);
        this.$set(this, `total`, res.total);
      } else {
        var jg_id = this.user.userid;
        const res = await this.dockingSearch({ skip, limit, jg_id });
        this.$set(this, `debtTable`, res.result);
        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({ xqid: valid, userid: userid });
      if (res.data.finstatus == 'SUCCESS') {
        this.$message({
          message: '您已分配过该需求',
          type: 'success',
        });
      } else {
        this.dialogFormVisible = true;
      }
    },
    async zhipaiformBtn({ data }) {
      let xqid = this.zpid;
      let userid = this.user.userid;
      let uuid = data.uuid;
      const res = await this.beforFollow({ xqid: xqid, userid: userid });
      if (res.data.finstatus == 'SUCCESS') {
        this.$message({
          message: '您已分配成功',
          type: 'success',
        });
      } else {
        console.log('data=======', data);
        const followres = await this.followIntelligent({ xqid: xqid, 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>
