<template>
  <div>
    <Project-title></Project-title>
    <div class="content-box">
      <div class="content">
        <template v-if="showlist">
          <div
            class="li"
            v-for="(item, ind) in list"
            :key="item.id"
            :serial="ind"
            @click="getContent(ind)"
          >
            <img :src="item.photo_uri" alt class="head" />
            <div class="li-preview">
              <h2 class="li-title">{{ item.title }}</h2>
              <div>{{ item.updated_time }}</div>
            </div>
          </div>
        </template>
        <template v-else>
          <div class="news-list-content-title">
            <div class="content-back" @click="showList">返回</div>
            <h2 class="title">{{ list[order].title }}</h2>
          </div>
          <div class="news-list-content-time">{{ list[order].updated_time }}</div>
          <div class="news-list-content" v-html="list[order].content"></div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import ProjectTitle from '../../components/ProjectTitle.vue'
import { getNews } from '../../action/axiosService.js'

export default {
  components: {
    ProjectTitle
  },
  data() {
    return {
      // 这个是传给组件的项目列表
      list: [],
      showlist: true,
      content: '',
      order: 0
    }
  },
  mounted() {
    const that = this
    getNews({
      cb: function (obj) {
        that.list = obj
      }
    })
  },
  methods: {
    getContent: function (index) {
      console.log('w', this.list[index])
      this.order = index
      this.showlist = false
    },
    showList() {
      this.showlist = true
    }
  }
}
</script>
<style>
h2,
h3 {
  padding: 0;
  margin: 0;
  list-style: none;
}
</style>
<style lang="scss" scoped>
.content-box {
  width: 100%;
  background-color: #ffffff;
  position: relative;
}
.content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  top: -20px;
  background-color: #ffffff;
  overflow: auto;
  .news-list-content {
    padding: 0 20px;
  }
}
.li {
  display: flex;
  height: 160px;
  width: 100%;
  background-color: #ffffff;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.08);
  margin-bottom: 40px;
  cursor: pointer;
  .head {
    width: 284px;
    height: 160px;
  }
  .li-preview {
    padding-top: 26px;
    padding-left: 20px;
    font-size: 24px;
    font-weight: 300;
    > div {
      font-family: 'PingFangSC-Linght', 'PingFang SC', 'Microsoft Yahei';
    }
  }
  .li-title {
    height: 74px;
    line-height: 32px;
    font-size: 24px;
    font-weight: 500;
    font-family: 'PingFangSC-Semibold', 'PingFang SC', 'Microsoft Yahei';
  }
  .li-title:hover {
    color: #c41230;
  }
}
.news-list-content-title {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  border-bottom: 1px dashed #ccc;
  padding: {
    top: 20px;
  }
  margin: 0 20px;
  height: 60px;
  > .content-back {
    color: #3a8fff;
    font-size: 20px;
    width: 80px;
    cursor: pointer;
  }
  > .title {
    text-align: center;
  }
}
.news-list-content-time {
  height: 40px;
  text-align: center;
}
</style>
