<template>
    <div>
      <Header></Header>
      <Notice :firstNotice="firstNotice" :noticeList="noticeList"></Notice>
      <MidLink v-if="!token"></MidLink>
      <info :ticketList="ticketList" :resultList="resultList" :certificateList="certificateList"></info>
      <Policy :firstPolicy="firstPolicy" :policyList="policyList"></Policy>
      <Footer></Footer>
    </div>
</template>

<script>
import Header from '@/assets/components/Header'
import Footer from '@/assets/components/Footer'
import Notice from './components/Notice'
import MidLink from './components/MidLink'
import Policy from './components/Policy'
import Info from './components/Info'
import url from '@/assets/public/url'
import axios from "axios";
export default {
    name: 'Index',
    components: {
      Header,
      Footer,
      Notice,
      MidLink,
      Policy,
      Info
    },
    data () {
        return {
          newsUrl: url.signUrl,
          noticeList: [],
          firstNotice: {},
          policyList: [],
          firstPolicy: {},
          ticketList: [],
          resultList: [],
          certificateList: [],
          token: window.sessionStorage.getItem('token'),
        }
    },
    methods: {
      // 获取最新公告
      getNotice: function () {
        var self = this
        axios.get(self.newsUrl + 'app/contentrelease/listpage', {
          params: {
            page: 1,
            rows: 5,
            categoryId: '87a51bb1-451b-4b49-903b-4d847ba9c730'
          }
        }).then(function (res) {
          self.firstNotice = res.data.rows[0]
          self.firstNotice.coverPhotos = self.firstNotice.coverPhotos.split(',')[0]
          res.data.rows.splice(0,1)
          self.noticeList = res.data.rows
        })
      },
      // 获取考试政策
      getPolicy: function () {
        var self = this
        axios.get(self.newsUrl + 'app/contentrelease/listpage', {
          params: {
            page: 1,
            rows: 4,
            categoryId: '92737534-c2ef-487c-b763-4d1fb597388f'
          }
        }).then(function (res) {
          self.firstPolicy = res.data.rows[0]
          self.firstPolicy.coverPhotos = self.firstPolicy.coverPhotos.split(',')[0]
          res.data.rows.splice(0,1)
          for (let i = 0; i < res.data.rows.length; i++) {
            var year = res.data.rows[i].publishDate.split('-')[0]
            var date = res.data.rows[i].publishDate.split('-')[1] + '-' + res.data.rows[i].publishDate.split('-')[2]
            res.data.rows[i].publishDate = date
            res.data.rows[i]['year'] = year
          }
          self.policyList = res.data.rows
        })
      },
      // 获取准考证
      getTicket: function () {
        var self = this
        axios.get(self.newsUrl + 'app/contentrelease/listpage', {
          params: {
            page: 1,
            rows: 5,
            categoryId: '929c283e-53be-4aa2-a8d2-785d28485e8d'
          }
        }).then(function (res) {
          self.ticketList = res.data.rows
        })
      },
      // 获取成绩
      getResult: function () {
        var self = this
        axios.get(self.newsUrl + 'app/contentrelease/listpage', {
          params: {
            page: 1,
            rows: 5,
            categoryId: 'f7252c11-6bf6-494e-89fa-44baa6b685a6'
          }
        }).then(function (res) {
          self.resultList = res.data.rows
        })
      },
      // 获取证书
      getCertificate: function () {
        var self = this
        axios.get(self.newsUrl + 'app/contentrelease/listpage', {
          params: {
            page: 1,
            rows: 5,
            categoryId: '0a424e44-9d7a-4a48-9942-7b5ccfe4a3aa'
          }
        }).then(function (res) {
          self.certificateList = res.data.rows
        })
      }
    },
    mounted: function () {
      this.getNotice()
      this.getPolicy()
      this.getResult()
      this.getCertificate()
      this.getTicket()
    }
}
</script>

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

</style>
