<template>
  <div id="financeClaimIndex">
    <el-col :span="24" class="debt">
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle" :display="display" @addfinclaim="addfinclaim"></topInfo>
      </el-col>
      <el-col :span="24" class="search">
        <financeClaimIndexInfo @clickBtn="clickBtn"></financeClaimIndexInfo>
      </el-col>
      <el-col :span="24" class="main">
        <financeclaimsList :debtTable="debtTable" :total="total" @pagechange="pagechange" @ljdelete="ljdelete"></financeclaimsList>
      </el-col>
    </el-col>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import financeClaimIndexInfo from '@/layout/financeclaims/financeClaimInfo.vue';
import financeclaimsList from '@/layout/financeclaims/financeclaimsList.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: financeclaims } = createNamespacedHelpers('financeclaim');
export default {
  name: 'financeClaimIndex',
  props: {},
  components: {
    topInfo, //头部导航
    financeClaimIndexInfo, //搜素
    financeclaimsList, //债权产品列表
  },
  data: () => ({
    topTitle: '债权产品列表',
    display: 'block',
    debtTable: [],
    total: '',
    cpname: '',
    jgname: '',
  }),
  created() {
    this.financeclaimsList();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...financeclaims(['fclaimsList', 'orUpdate', 'one', 'dupdate', 'fetch', 'update']),
    async financeclaimsList({ skip = 1, limit = 10, uid = this.user.userid, type = 1 } = {}) {
      const res = await this.fclaimsList({ skip, limit, uid, type });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    //添加
    addfinclaim() {
      this.$router.push({ path: '/financeclaims/financeClaimDetail' });
    },
    async pagechange(data) {
      var skip = data.skip;
      var limit = 10;
      var innewname = this.jgname;
      var name = this.cpname;
      var uid = this.user.userid;
      var type = 1;
      const res = await this.fclaimsList({ skip, limit, uid, type, innewname, name });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },
    //查询
    async clickBtn(data) {
      var innewname = data.innewname;
      var name = data.name;
      this.cpname = data.name;
      this.jgname = data.innewname;
      var skip = 0;
      var limit = 10;
      var uid = this.user.userid;
      var type = 1;
      const res = await this.fclaimsList({ skip, limit, uid, type, innewname, name });
      this.$set(this, `debtTable`, res.res);
      this.$set(this, `total`, res.total);
    },

    async ljdelete(data) {
      var finid = data.delid;
      let finalres;
      let res = await this.fetch(finid);
      finalres = res.data;
      finalres.status = '2';
      var delres = await this.update(finalres);
      if (delres.errcode === 0) {
        this.$message({
          message: '删除信息成功',
          type: 'success',
        });
      } else {
        this.$message({
          message: '删除信息失败',
          type: 'error',
        });
      }
      this.financeclaimsList();
    },
  },
};
</script>

<style lang="less" scoped>
.debt {
  padding: 20px;
}
.top {
  border-bottom: 1px solid #ccc;
}
.search {
  width: 97%;
  height: 35px;
  margin: 20px;
}
</style>
