<template>
    <div>
      <Header></Header>
      <IndexSwiper :bannerList="bannerList"></IndexSwiper>
      <Dynamic :dynamic="dynamic"></Dynamic>
      <IndexService :activityList="activityList"></IndexService>
      <IndexSpecialties :specialties="specialties"></IndexSpecialties>
      <DigitalResource :literature="literature"></DigitalResource>
      <IndexVideo :video="video"></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 IndexSpecialties from './components/IndexSpecialties'
import DigitalResource from './components/DigitalResource'
import IndexVideo from './components/IndexVideo'
import Footer from '@/common/components/Footer'
import axios from 'axios'
export default {
  name: 'Index',
  components: {
    Header,
    IndexSwiper,
    Dynamic,
    IndexService,
    IndexSpecialties,
    DigitalResource,
    IndexVideo,
    Footer
  },
  data () {
    return {
      bannerList: [],
      dynamic: {
        picNews: {},
        news: []
      },
      activityList: [],
      specialties: [],
      video: [],
      literature: [],
      dynamicsPage: {
        page: 1,
        rows: 5
      },
      activityPage: {
        page: 1,
        rows: 8
      }
    }
  },
  methods: {
    getIndexData: function () {
      var self = this
      axios.get('/api/index.json').then(function (res) {
        res = res.data
        const data = res.data
        // 轮播
        self.bannerList = data.banner
        // 地方特色
        self.specialties = data.specialties
        // 数图资源
        // self.resource = data.resource
        // 视听空间
        self.video = data.video
      })
    },
    getDynamicsList: function () {
      var self = this
      axios.get('http://192.168.0.104:8082/news/app/newscontent/listpagenewscontentrelease', {
        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('http://192.168.0.111:8080/culturalactivity/app/activitylibrary/listpageactivitylibraryfornetrelease', {
        params: self.activityPage
      }).then(function (res) {
        self.activityList = res.data.rows
      })
    },
    getLiterature: function () {
      var self = this
      axios.get('http://192.168.0.104:8081/library/app/intangiblelibrarydata/listpageintangiblelibrarydatarelease/48204626-2593-4ab7-9dda-4d6314c12556', {
        params: self.activityPage
      }).then(function (res) {
        self.literature = res.data.rows
      })
    }
  },
  mounted () {
    this.getIndexData()
    this.getDynamicsList()
    this.getActivityList()
    this.getLiterature()
  }
}
</script>

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

</style>
