<template>
    <div>
      <Header></Header>
      <IndexSwiper :swiperList="swiperList"></IndexSwiper>
      <Dynamic :dynamic="dynamic"></Dynamic>
      <IndexService :activityList="activityList"></IndexService>
      <DigitalResource></DigitalResource>
      <IndexVideo :exhibition="exhibition"></IndexVideo>
      <Footer></Footer>
    </div>
</template>

<script>
import Header from '@/common/components/Header'
import IndexSwiper from './components/Swiper'
import Dynamic from './components/IndexDynamic'
import IndexService from './components/IndexService'
import DigitalResource from './components/DigitalResource'
import IndexVideo from './components/IndexVideo'
import Footer from '@/common/components/Footer'
import axios from 'axios'
import common from '@/common/components/common.js'

export default {
  name: 'Index',
  components: {
    Header,
    IndexSwiper,
    Dynamic,
    IndexService,
    DigitalResource,
    IndexVideo,
    Footer
  },
  data () {
    return {
      bannerList: [],
      dynamic: {
        picNews: {},
        news: []
      },
      activityList: [],
      specialties: [],
      exhibition: [],
      literature: [],
      dynamicsPage: {
        page: 1,
        rows: 5,
        newsDirectoriesParentId: 'f497904b-7727-4832-891c-604c36ae4167'
      },
      activityPage: {
        page: 1,
        rows: 8
      },
      exhibitionPage: {
        page: 1,
        rows: 8,
        totalPage: 1,
        newsDirectoriesId: '',
        newsDirectoriesParentId: 'f1d5d313-f728-4dda-9843-1116d97e17b0'
      },
      literaturePage: {
        page: 1,
        rows: 8,
        totalPage: 1,
        newsDirectoriesId: '',
        newsDirectoriesParentId: '98c74389-2088-499b-a046-8611bdc57ea4'
      },
      swiperList: [],
      url: common.url
    }
  },
  methods: {
    getDynamicsList: function () {
      var self = this
      axios.get(self.url + 'app/newscontent/listpagenewscontentrelease/' + common.area.areaCode, {
        params: self.dynamicsPage
      }).then(function (res) {
        var picNews = res.data.rows.splice(0, 1)[0]
        picNews.newsContentCoverList = picNews.newsContentCoverList[0].contentCoverId
        for (var i = 0; i < res.data.rows.length; i++) {
          var date = res.data.rows[i].newsContentPublishTime.split('-')[2]
          self.$set(res.data.rows[i], 'date', date)
          res.data.rows[i].newsContentPublishTime = res.data.rows[i].newsContentPublishTime.split('-')[0] + '-' + res.data.rows[i].newsContentPublishTime.split('-')[1]
        }
        var result = {
          picNews: picNews,
          news: res.data.rows
        }
        self.dynamic = result
      })
    },
    getActivityList: function () {
      var self = this
      axios.get(self.url + 'app/activitylibrary/listpageactivitylibraryfornetrelease/' + common.area.areaCode, {
        params: self.activityPage
      }).then(function (res) {
        self.activityList = res.data.rows
      })
    },
    getLiterature: function () {
      var self = this
      axios.get(self.url + 'app/newscontent/listpagenewscontentrelease/' + common.area.areaCode, {
        params: self.literaturePage
      }).then(function (res) {
        for (var i = 0; i < res.data.rows.length; i++) {
          res.data.rows[i].newsContentCoverList = res.data.rows[i].newsContentCoverList[0].contentCoverId
        }
        self.literature = res.data.rows
      })
    },
    getExhibition: function () {
      var self = this
      axios.get(self.url + 'app/newscontent/listpagenewscontentrelease/' + common.area.areaCode, {
        params: self.exhibitionPage
      }).then(function (res) {
        for (var i = 0; i < res.data.rows.length; i++) {
          res.data.rows[i].newsContentCoverList = res.data.rows[i].newsContentCoverList[0].contentCoverId
        }
        self.exhibition = res.data.rows
      })
    },
    // 轮播图
    getSwiper: function () {
      var self = this
      axios.get(self.url + 'app/newscontent/listpagenewscontentrelease/' + common.area.areaCode, {
        params: {
          page: 1,
          rows: 3,
          newsDirectoriesId: 'eab0ca3c-d35d-4c02-9397-ace2bdd10fc1'
        }
      }).then(function (res) {
        for (var i = 0; i < res.data.rows.length; i++) {
          res.data.rows[i].newsContentCoverList = res.data.rows[i].newsContentCoverList[0].contentCoverId
        }
        self.swiperList = res.data.rows
      })
    }
  },
  mounted () {
    this.getDynamicsList()
    this.getActivityList()
    // this.getLiterature()
    this.getExhibition()
    this.getSwiper()
  }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>

</style>
