<template>
  <div id="index">
    <el-row>
      <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="search">
          <searchInfo @sousuo="sousuo"></searchInfo>
        </el-col>
        <el-col :span="24" class="list">
          <newsInfo
            :debtTable="debtTable"
            @handleCurrentChange="handleCurrentChange"
            @deleteRow="deleteRow"
            :total="total"
            :totals="totals"
            :totalss="totalss"
            @handleClick="handleClick"
          ></newsInfo>
        </el-col>
      </el-col>
    </el-row>
  </div>
  <!--
  <template>
    <div id="index">
      <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="search">  <searchInfo></searchInfo>  </el-col> 
          <el-col :span="24" class="main">  <newsInfo :debtTable="debtTable" :total="total" @handleClick="handleClick"></newsInfo> // </el-col> //
        </el-col>
      </el-row>
    </div>
  </template> -->
</template>
<script>
import topInfo from '@/layout/common/topInfo.vue';
import searchInfo from '@/layout/common/searchInfo.vue';
import newsInfo from '@/layout/institution/newsInfo.vue';
import { createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('institution');
export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部导航
    searchInfo, //搜素
    newsInfo, //
  },
  data: () => ({
    // display: 'none',
    display: 'block',
    topTitle: '金融机构',
    debtTable: [],
    total: 0,
    totals: 0,
    totalss: 0,
    type: '',
    skip: '',
    info: {},
  }),
  created() {
    // this.search();
    // this.searchstatus1();
    // this.searchelse();
  },
  computed: {
    status() {
      return this.$route.params.status;
    },
  },
  watch: {
    // status(news) {
    //   if (news == 1) {
    //     this.search();
    //   }
    // },
    status: {
      handler(oval) {
        console.log(oval);
        this.debtTable = [];
        console.log(this.debtTable);

        if (oval == 0) {
          console.log('if');
          this.skip = '';
          this.info = {};
          this.search();
        } else if (oval == 1) {
          this.skip = '';
          this.info = {};
          console.log('elseif');
          this.searchstatus1();
        } else {
          console.log('else');
          this.skip = '';
          this.info = {};
          this.searchelse();
        }
      },
      //立刻
      immediate: true,
      deep: true,
    },
  },
  methods: {
    ...mapActions(['query', 'delete']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      // console.log(this.info.name);
      let type = { type: 0, name: this.info.name };
      this.$set(this, `type`, type.type);
      skip = this.skip;
      info = type;
      const res = await this.query({ skip, limit, ...info });
      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },

    async deleteRow(id) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.search();
    },
    async searchstatus1({ skip = 0, limit = 10, ...info } = {}) {
      let type = { type: 1, name: this.info.name };
      this.$set(this, `type`, type.type);
      info = type;
      skip = this.skip;
      const res = await this.query({ skip, limit, ...info });

      this.$set(this, `debtTable`, res.data);
      this.$set(this, `total`, res.total);
    },
    async searchelse({ skip = 0, limit = 10, ...info } = {}) {
      let type = { type: 2, name: this.info.name };
      this.$set(this, `type`, type.type);
      skip = this.skip;
      info = type;

      const res = await this.query({ skip, limit, ...info });

      this.$set(this, `debtTable`, res.data);

      this.$set(this, `total`, res.total);
    },
    async handleCurrentChange({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      console.log(this.type);
      if (this.type == 0) {
        this.search();
      } else if (this.type == 1) {
        this.searchstatus1();
      } else if (this.type == 2) {
        this.searchelse();
      }
    },
    //搜索
    async sousuo(search) {
      this.$set(this, `info`, search);
      if (this.type == 0) {
        this.search();
      } else if (this.type == 1) {
        this.searchstatus1();
      } else if (this.type == 2) {
        this.searchelse();
      }
    },
    handleClick(newid) {
      this.$router.push({ path: '/institution/detail', query: { id: newid } });
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  height: 50px;
  margin: 0 0 10px 0;
}
.main {
  height: 765px;
  background: #ffffff;
}
.search {
  width: 97%;
  height: 35px;
  margin: 20px;
}
.list {
  padding: 0 20px;
}
</style>
