<template>
  <div class="layout_com_page">
    <vue-lazy-component>
      <div class="layout_com_page_banner recent-news-header" :style="{height: 364 + 'px'}">
        <span>最新动态</span>
      </div>
    </vue-lazy-component>
    <vue-lazy-component>
      <div class="recent-news-body">
        <div
          v-loading="isloading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          class="recent-news-body-list"
          v-for="(item, index) in listData"
          :key="index"
          @click="details(item)"
          @mouseover="item.hover = true"
          @mouseleave="item.hover = false"
          :class="{'riht-bg': (index + 1) % 2 === 0, 'hover-bg': item.hover}"
        >
          <div class="list" v-if="(index + 1) % 2 !== 0">
            <div class="list-time">
              <span class="font-size-30">{{item.created_time | formatDate}}</span>
              <span class="font-size-15">{{item.created_time | formatDate(item.created_time, true)}}</span>
            </div>
            <img :src="item.photo_uri" />
            <div class="list-title">
              <span class="font-size-30">{{item.title}}</span>
              <span class="font-size-15">{{item.summary}}</span>
            </div>
          </div>
          <div class="list" v-else>
            <div class="list-title">
              <span class="font-size-30">{{item.title}}</span>
              <span class="font-size-15">{{item.summary}}</span>
            </div>
            <img :src="item.photo_uri" />
            <div class="list-time">
              <span class="font-size-30">{{item.created_time | formatDate}}</span>
              <span class="font-size-15">{{item.created_time | formatDate(item.created_time, true)}}</span>
            </div>
          </div>
        </div>
        <div class="list-down">
          <span @click="manyList" v-if="!showMany">查看更多</span>
          <span @click="manyList" v-else>暂无更多</span>
          <img @click="manyList" :src="require('@/assets/images/apply-for/bg_down.png')" />
        </div>
      </div>
    </vue-lazy-component>
    <vue-lazy-component>
      <page-footer />
    </vue-lazy-component>
  </div>
</template>

<script>
import PageFooter from '@/components/page-footer/index.vue'
import cAction from '@action'

export default {
  name: 'recent-news',
  components: {
    PageFooter
  },
  filters: {
    formatDate(data, state = null) {
      const date = new Date(data.replace(/-/g, '/'))
      const y = date.getFullYear()
      let m = date.getMonth() + 1
      m = m < 10 ? '0' + m : m
      let d = date.getDate()
      d = d < 10 ? '0' + d : d
      if (state) {
        return y
      }
      return m + '.' + d + '/'
    }
  },
  data() {
    return {
      listData: [],
      showMany: false,
      quiuse: {
        page: 1,
        per_page: 4,
        project_id: 1005
      }
    }
  },
  methods: {
    details(item) {
      this.$router.push({
        name: 'details-recent-news',
        params: { id: item.id }
      })
    },
    manyList() {
      this.quiuse.per_page += 8
      this.setDate()
    },
    setDate() {
      this.isloading = true
      cAction.News.newsList(this.quiuse)
        .then(data => {
          if (this.listData.length === data.length) {
            this.showMany = true
            this.isloading = false
            return
          }
          this.listData = data.map(k => {
            k.hover = false
            return k
          })
          this.showMany = false
          this.isloading = false
        })
        .catch(e => {
          this.isloading = false
          console.log(e)
        })
    }
  },
  created() {
    this.setDate()
  }
}
</script>

<style lang="scss" scoped>
.recent-news-header {
  width: 100%;
  position: relative;
  background: url('~@/assets/images/apply-for/hear.png') no-repeat center center;
  background-size: cover;
  display: flex;
  justify-content: center;
  span {
    position: absolute;
    font-size: 40px;
    font-family: Helvetica;
    color: rgba(255, 255, 255, 1);
    top: 50%;
    cursor: pointer;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}
.recent-news-body {
  width: 100%;
  .recent-news-body-list {
    min-height: 388px;
    display: flex;
    min-height: 388px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0 50px;
    box-sizing: border-box;
    background: #fff;
    .list {
      display: flex;
      .list-title,
      .list-time {
        display: flex;
        flex-direction: column;
        max-width: 400px;
        span {
          padding: 2px 0px;
        }
        .font-size-30 {
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(34, 34, 34, 1);
          max-width: 400px;
        }
        .font-size-15 {
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #666666ff;
        }
      }
      .list-time {
        align-items: flex-end;
      }
      img {
        height: 308px;
        width: 510px;
        padding: 0px 20px;
      }
    }
  }
  .list-down {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: #af1b40ff;
    padding: 20px;
    span {
      padding: 0px 20px;
      cursor: pointer;
    }
    img {
      cursor: pointer;
    }
  }
  .riht-bg {
    background: rgba(241, 241, 241, 1);
  }
  .hover-bg {
    background: #a61a3dff;
    transition: 0.5s;
    span {
      color: #fff !important;
    }
  }
}
</style>
