<template>
  <div class="news-content">
    <tab />
    <div class="news-content-box">
      <img src="https://webapp-pub.ezijing.com/www/pc/news/news.png" alt="" class="banner" />
      <ul class="list-content">
        <template v-for="(item, index) in listData">
          <li :key="index">
            <app-link :item="{ news: { data: item, path: '/about/message' } }">
              <img :src="item.web_img_uri" alt="" />
              <div class="right-con">
                <div class="time">{{ formatDate(item.start_time) }}</div>
                <div class="title">{{ item.title }}</div>
                <div class="text">{{ item.abstract }}</div>
              </div>
            </app-link>
          </li>
        </template>
      </ul>
      <div class="pages-box">
        <el-pagination
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :page-size="limit"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import appLink from '@/components/Link'
import tab from '@/components/about/tabNav'
export default {
  components: { tab, appLink },
  data() {
    return {
      listData: [],
      currentPaeg: 1,
      total: 0,
      limit: 10
    }
  },
  async fetch() {
    const params = {
      project_id: process.env.projectId,
      type_tag: this.$route.query.type || 'img_text_school',
      page: this.currentPaeg,
      limit: 10
    }
    this.listData = await this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => {
      this.total = res.data.total
      return res.data.data
    })
  },
  methods: {
    handleCurrentChange(num) {
      this.initData(num)
    },
    initData(num) {
      const params = {
        project_id: process.env.projectId,
        type_tag: this.$route.query.type || 'img_text_school',
        page: num,
        limit: 10
      }
      this.listData = this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => {
        this.total = parseInt(res.data.total)
        this.listData = res.data.data
      })
    },
    formatDate(value) {
      const date = new Date(value * 1000)
      return date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()
    }
  }
}
</script>
<style lang="scss" scoped>
.pages-box {
  display: flex;
  padding-bottom: 50px;
  background: #fff;
  justify-content: center;
}
.news-content {
  width: 1200px;
  margin: 0 auto;
  padding-top: 63px;
  display: flex;
  justify-content: space-between;
}
.news-content-box {
  width: 1000px;
  padding-bottom: 100px;
  display: block;
  .banner {
    width: 100%;
    display: block;
  }
  .list-content {
    width: 1000px;
    padding: 50px;
    background: #fff;
    li {
      border-bottom: 1px solid #e6e6e6;
      margin-bottom: 20px;
      padding-bottom: 36px;
      cursor: pointer;
      ::v-deep a {
        display: flex;
        flex-wrap: wrap;
        height: fit-content;
      }
      &:hover {
        .right-con {
          background: rgba(241, 241, 241, 0.6);
          .text {
            color: #141414;
          }
        }
      }
      img {
        width: 320px;
        height: 100%;
        display: block;
      }
      .right-con {
        width: 550px;
        margin-left: 15px;
        padding-left: 15px;
        .time {
          font-size: 16px;
          font-weight: 300;
          line-height: 100%;
          color: #aa1941;
          // padding-top: 13px;
        }
        .title {
          font-size: 22px;
          font-weight: bold;
          line-height: 32px;
          color: #141414;
          margin-top: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .text {
          font-size: 14px;
          font-weight: 300;
          line-height: 24px;
          color: #666666;
          margin-top: 15px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
    }
  }
}
</style>
