<template>
  <div class="client-newsInfor-page">
    <div :style="{backgroundImage: 'url(' + bannerDefault + ')'}" class="client-banner-box"></div>
    <!-- 新闻资讯 -->
    <h4 class="client-title">新闻中心</h4>
    <div class="client-container newsInfor-content-box">
      <ul class="newsInfor-content-ul" style="width:100%">
        <template >
          <new-list
            v-for="(item,index) in newsList"
            :newsData="item"
            :key="index"></new-list>
        </template>
      </ul>
      <div class="client-el-pagination">
        <el-pagination
          background
          small
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          :total="totalLists">
        </el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
  import NewList from '~/components/news/NewsList';
  const defaultNewsClassifyId = 0;
  export default {
    name:       'news',
    layout:     'templateB',
    components: {
      NewList
    },
    async asyncData({ $axios, store }) {
      // 设置选中菜单
      store.commit('setActiveNav', '/news');
      try {
        const url2 = '/common/client/web/news/list';
        const opt = {
          page:           1,
          size:           10,
        };

        const res2 = await $axios.post(url2, opt);
        const { data: { data: data2 } } = res2;
        return {
          newsList:          data2.data || [],
          totalLists:        data2.total || defaultNewsClassifyId,
        };
      } catch (e) {
        return {
          newsList:          [],
          totalLists:        0,
        };
      }

    },
    data() {
      return {
        clicked:          0,
        newsClassifyId:   null,
        homeNewsClassify: [],
        totalLists:       0,
        currentPage:      1,
        pageSize:         10,
        // 新闻数据
        newsList:         [],
        activeIndex:      1,
        // banner图
        bannerDefault:   require(`~/static/images/website/banner/cx-banner-xwzx.png`),
      };
    },
    head(){
      return {
        title: '家政学',
      }
    },
    methods:    {
      clickBanner(data){
        if(data){
          window.open(data)
        }
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.getMessage();
      },
      async getMessage() {
        let opt = {
          page:           this.currentPage,
          size:           this.pageSize,
        };
        const url2 = '/common/client/web/news/list';
        const res2 = await this.$axios.post(url2, opt);
        this.newsList = res2.data.data;
        this.totalLists = res2.data.total || defaultNewsClassifyId;
      },
      btnClick(data, index) {
        this.activeIndex = index;
        console.log(data);
        this.currentPage = 1;
        this.getMessage();
      },
    },
    mounted() {

    }
  };
</script>
<style>

</style>
