<!--
 * @Author: wally
 * @email: 18603454788@163.com
 * @Date: 2021-01-13 17:21:29
 * @LastEditors: wally
 * @LastEditTime: 2021-01-20 15:17:25
-->
<template>
  <div>
    <div class="inner my-1">
      <bread-crumb :arr="arr" />
    </div>
    <div class="inner">
      <classify @getData="getData" />
      <know-content :list="list" @getData="getData" />
      <a-pagination
        :current="current"
        :page-size="pageSize"
        :total="total"
        @change="onShowSizeChange"
        class="pagination"
        show-less-items
        show-quick-jumper
        v-show="total > 2"
      />
    </div>
  </div>
</template>

<script>
import BreadCrumb from 'components/BreadCrumb/BreadCrumb.vue';
import Classify from './components/classify.vue';
import KnowContent from './components/knowContent.vue';
import { back } from 'config/api';

export default {
  name: 'Knowledge',
  components: { BreadCrumb, Classify, KnowContent },
  data() {
    return {
      str: '知识培训服务平台',
      title: '知识平台',
      typeOfPlatform: '知识平台',
      arr: [{ name: '知识平台', url: '/Knowledge' }],
      list: [],
      current: 1,
      pageSize: 6,
      total: 10,
      bannerNum: [],
      typeNum: '',
      titleText: '',
    };
  },

  created() {
    this.getData();
  },

  methods: {
    /**
     * 查询创业学院内容
     * @param {string} pageNum 页码
     * @param {string} pageSize 每页多少条
     * @param {string} banner 栏目分类
     * @param {string} type 类型 1视频,2音频,3ppt
     * @param {string} title 标题
     */
    async getData(getParam) {
      try {
        const params = {
          param: {
            banner: this.bannerNum,
            type: this.typeNum,
            title: this.titleText,
            pageNum: this.current,
            pageSize: this.pageSize,
          },
        };
        if (getParam) {
          params.param.banner = getParam.bannerNum;
          params.param.type = getParam.typeNum;
          params.param.title = getParam.titleText;
        }
        const res = await back(params);
        const { code, msg, data } = res.data;
        if (code === 200) {
          this.total = parseInt(data.total);
          this.list = data.list;
        } else {
          this.$message.error('查询失败');
        }
      } catch (error) {
        this.$message.error(error);
      }
    },

    // 换页
    onShowSizeChange(current, size) {
      this.current = current;
      this.getData();
    },
  },
};
</script>

<style lang="stylus" scoped>
.inner {
  margin: 20px auto;
}

.pagination {
  margin: 40px 0;
  text-align: right;
}
</style>
