<template>
  <div>
    <Header></Header>
    <div class="location">
      当前位置: <router-link to="/">首页</router-link> > 培训机构
    </div>
    <div class="main">
      <Menu></Menu>
      <div class="right">
        <div class="table">
          <h3>培训机构</h3>
          <p>呼和浩特市安全生产培训机构信息汇总表（排名不分先后）</p>
          <table>
            <tr>
              <th width="5%">序号</th>
              <th width="15%">机构名称</th>
              <th width="30%">机构描述</th>
              <th width="15%">联系方式</th>
              <th width="10%">负责人</th>
              <th width="25%">地址</th>
            </tr>
            <tr v-for="(list,idx) in orgList">
              <td>{{ ((page.page-1) *page.rows) + idx +1 }}</td>
              <td>{{ list.institutionName }}</td>
              <td v-html="list.institutionDesc"></td>
              <td>{{ list.institutionContact }}</td>
              <td>{{ list.institutionPrincipal }}</td>
              <td>{{ list.institutionAddress }}</td>
            </tr>
          </table>
        </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
.location
  width 1200px
  margin 15px auto
  font-size 18px
  color #333
  a
    color #333
.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 15px
  overflow hidden
  .right
    float right
    width 940px
    padding 0 10px
    box-sizing border-box
    border 1px solid #f1f1f1
    .table
      text-align center
      min-height 500px
      h3
        font-size 30px
        color #000
        font-weight normal
        margin 20px 0
      p
        font-size 14px
        color #333
      table
        table-layout fixed
        width 100%
        margin 15px 0
        border-collapse separate;
        border-spacing 0 30px
        th
          height 30px
          text-align center
          font-size 14px
          color #333
        td
          text-align center
          font-size 14px
          color #333
          word-break break-all
          &:nth-child(3)
            text-align left
</style>
