<template>
  <div>
    <Header></Header>
    <div class="main">
      <Menu></Menu>
      <div class="right">
        <div class="main-list">
          <ul>
            <li v-for="news in orgList">
              <div class="info">
                <h3>{{ news.institutionName }}</h3>
                <p><span>机构描述：</span>{{ news.institutionDesc }}</p>
                <p><span>联系方式：</span>{{ news.institutionContact }} | <span>联系人：</span>{{ news.institutionPrincipal }}</p>
                <p><span>机构地址：</span>{{ news.institutionAddress }}</p>
              </div>
            </li>
          </ul>
        </div>
        <div class="pager" v-if="page.totalPage > 1">
          <span @click="paging(1)">首页</span>
          <span @click="paging(page.page - 1)" v-if="page.page > 1">上一页</span>
          <ul v-if="page.totalPage > 0 && page.totalPage <= 5">
            <li v-for="cpage in page.totalPage" :class="{'active': page.page == cpage}" :key="cpage" @click="paging(cpage)">
              {{cpage}}
            </li>
          </ul>
          <ul v-if="page.totalPage > 5">
            <li v-if="page.page < 3" v-for="cpage in 5" :class="{'active': page.page == cpage}" :key="cpage" @click="paging(cpage)">
              {{cpage}}
            </li>
            <li v-if="page.page > page.totalPage - 2" v-for="cpage in 5" :class="{'active': page.page == (page.totalPage - 5 + cpage)}" :key="cpage" @click="paging(page.totalPage - 5 + cpage)">
              {{page.totalPage - 5 + cpage}}
            </li>
            <li v-if="page.page >= 3 && page.page <= page.totalPage - 2" v-for="cpage in 5" :class="{'active': page.page == (page.page - (3 - cpage))}" :key="cpage" @click="paging(page.page - (3 - cpage))">
              {{page.page - (3 - cpage)}}
            </li>
          </ul>
          <span @click="paging(page.page + 1)" v-if="page.page < page.totalPage">下一页</span>
          <span @click="paging(page.totalPage)">尾页</span>
        </div>
      </div>
    </div>
    <div class="loading" v-if="isLoading">
      <img src="@/assets/images/loading.gif" alt="">
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from '@/assets/components/Header'
import Footer from '@/assets/components/Footer'
import Menu from '@/assets/components/Menu'
import url from '@/assets/public/url'
import axios from 'axios'
export default {
  name: 'Notice',
  components: {
    Header,
    Footer,
    Menu
  },
  data () {
    return {
      page: {
        page: 1,
        rows: 10,
        totalPage: 10
      },
      url: url.signUrl,
      orgList: [],
      isLoading: false
    }
  },
  methods: {
    paging: function (page) {
      this.page.page = page
      this.getOrgList()
    },
    getOrgList: function () {
      var self = this
      self.isLoading = true
      axios.get(self.url + 'app/traininginstitution/listpagerelease', {
        params: self.page
      }).then(function (res) {
        self.isLoading = false
        self.orgList = res.data.rows
        self.page.page = res.data.page
        self.page.totalPage = Math.ceil(res.data.total / self.page.rows)
      })
    }
  },
  mounted: function () {
    this.getOrgList()
  }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.loading
  position fixed
  top 50%
  left 50%
  transform translate(-50%, -50%)
  background rgba(255,255,255,0.6)
  padding 30px
  border-radius 10px
  box-shadow 0 0 17px #DEDEDE
.pager
  text-align center
  font-size 0
  margin-bottom 15px
  span
    display inline-block
    padding 0 15px
    line-height 30px
    color #333
    font-size 14px
    margin 0 5px
    vertical-align middle
    cursor pointer
    border 1px solid #CCCCCC
  ul
    display inline-block
    overflow hidden
    vertical-align middle
    li
      width 30px
      line-height 30px
      float left
      margin-right 10px
      cursor pointer
      text-align center
      font-size 14px
      color #333
      border 1px solid #CCCCCC
      &.active
        color: #0d6ec0
        border 1px solid #0d6ec0
        box-sizing border-box
      &:last-child
        margin 0
.main
  width 1200px
  margin 0 auto
  box-sizing border-box
  .main-list
    min-height 500px
    ul
      li
        overflow hidden
        padding 20px
        box-shadow 0 0 10px #EEE
        border-radius 3px
        margin-bottom 25px
        h3
          white-space nowrap
          overflow hidden
          text-overflow ellipsis
          font-size 18px
          color #333
          margin-bottom 10px
        p
          font-size 14px
          color #999
          line-height 35px
          display -webkit-box
          overflow hidden
          -webkit-line-clamp 2
          -webkit-box-orient vertical
        span
          font-size 14px
          color #4184dd
        .info
          width 100%
</style>
