
<template>
    <div id="loanProIndex">
        <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">
                <loanproInfo @clickBtn="clickBtn"></loanproInfo>
            </el-col>
            <el-col :span="24" class="main">
                <loanproLists :debtTable="debtTable" :total="total" @pagechange="pagechange" @ljdelete="ljdelete"></loanproLists>
            </el-col>
        </el-col>
    </div>
</template>

<script>
  import topInfo from '@/layout/common/topInfoloan.vue';
  import loanproInfo from '@/layout/financeclaims/loanproInfo.vue';
  import loanproLists from '@/layout/financeclaims/loanproList.vue';
  import { createNamespacedHelpers, mapGetters,mapState } from 'vuex';
  const { mapActions: loanpro} = createNamespacedHelpers('loanpro');
  export default {
    name: 'loanProIndex',
    props: {},
    components: {
      topInfo, //头部导航
      loanproInfo, //搜素
      loanproLists, //贷款产品列表
    },
    data: () => ({
      topTitle: '小微数贷产品列表',
      display: 'block',
      debtTable: [],
      total: '',
      cpname: '',

    }),
    created() {
      this.loanProList();
    },
    computed: {
      ...mapState(['user']),
    },
    methods: {
      ...loanpro(['loanproList', 'dupdate','fetch','update']),
      async loanProList({ skip = 1, limit = 10, jkid= this.user.userid } = {}) {//this.user.userid
        const res = await this.loanproList({ skip, limit, jkid });
        this.$set(this, `debtTable`, res.res);
        this.$set(this, `total`, res.total);
      },
      //添加
      addfinclaim() {
        this.$router.push({ path: '/financeclaims/loanProDetail' });
      },
      async pagechange(data) {
        var skip = data.skip;
        var limit = 10;
        var name = this.cpname ;
        var  jkid =this.user.userid;
        const res = await this.loanproList({ skip, limit, jkid ,name});
        this.$set(this, `debtTable`, res.res);
        this.$set(this, `total`, res.total);
      },
      //查询
      async clickBtn(data) {
        var name = data.name;
        this.cpname = data.name;
        var skip = 0;
        var limit = 10;
        var  jkid =this.user.userid;
        const res = await this.loanproList({ skip, limit, jkid ,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="1";
        var delres = await this.update(finalres);
        if (delres.errcode === 0) {
          this.$message({
            message: '删除信息成功',
            type: 'success',
          });
        }else{
          this.$message({
            message: '删除信息失败',
            type: 'error',
          });
        }
        this.loanProList();
      }
    },
  };
</script>

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