<template>
  <div>
    <div class="con-title">公告通知</div>
    <div class="con-box">
      <el-collapse accordion v-model="activeNames" @change="handleChange">
        <template v-for="(item, index) in msgList">
          <el-collapse-item v-bind:key="index" :name="index">
            <template slot="title">
              <template v-if="!item.isShow">
                <el-badge is-dot class="item">{{ item.title }}</el-badge>
              </template>
              <template v-if="item.isShow">{{ item.title }}</template>
            </template>
            <div v-html="item.text"></div>
          </el-collapse-item>
        </template>
      </el-collapse>
      <div style="height: 0.3rem;"></div>
      <el-pagination
        :current-page.sync="page.page"
        :page-size="page.page_size"
        layout="total, prev, pager, next, jumper"
        :total="page.total"
        @current-change="handleCurrentChange"
        :hide-on-single-page="true"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import cAction from '@action'

export default {
  components: {},
  data() {
    return {
      activeNames: [],
      msgList: [],
      page: {
        page: 1,
        total: 0,
        page_size: 20
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    handleChange(val) {
      if (typeof val === 'number' && this.msgList[val].isShow === 0) {
        cAction.Other.setMsgWmp(this.msgList[val].id)
          .then(json => {
            this.getData()
          })
          .catch(e => {
            this.$message.error(e.message)
          })
      }
    },
    getData() {
      const pageParam = {
        page: this.page.page,
        page_size: this.page.page_size
      }
      cAction.Other.getMyMsg(pageParam)
        .then(json => {
          this.msgList = json.list
          this.page.total = json.count
          this.$store.commit('myMsg', json.countNum)
        })
        .catch(e => {
          this.$message.error(e.message)
        })
    },
    handleCurrentChange() {
      this.getData()
    }
  }
}
</script>

<style lang="scss">
.el-collapse-item__header {
  line-height: 15px;
}
.total-core,
.compulsory-core,
.elective-core {
  margin-top: 0.1rem;
  font-size: 16px;
  line-height: 36px;
  .title {
    float: left;
    // margin-left: 5px;
  }
  .core {
    float: right;
    margin-right: 3px;
    font-size: 12px;
  }
}
.color-box {
  padding: 0.1rem 0 0.2rem 0;
  text-align: right;
  .color {
    display: inline-block;
    vertical-align: text-bottom;
    width: 14px;
    height: 14px;
  }
  .txt {
    display: inline-block;
    padding: 0 0.2rem 0 0.1rem;
    font-size: 14px;
    line-height: 36px;
  }
}
</style>
