<template>
  <el-popover placement="bottom"
              width="350"
              trigger="click">

    <!--<el-tabs v-model="activeName">
      <el-tab-pane label="邮件(1)"
                   name="first"></el-tab-pane>
      <el-tab-pane label="消息(2)"
                   name="second"></el-tab-pane>
      <el-tab-pane label="通知"
                   name="third"></el-tab-pane>
    </el-tabs>-->
    <el-scrollbar style="height:300px">
      <avue-notice :data="data"
                   :option="option"
                   @click="handleClick"
                   @page-change="pageChange"></avue-notice>
    </el-scrollbar>
    <div slot="reference">
      <el-badge :value="count" v-if="count > 0">
        <i class="el-icon-bell"></i>
      </el-badge>
      <el-badge v-else>
        <i class="el-icon-bell"></i>
      </el-badge>
    </div>
  </el-popover>
</template>

<script>
  import Bus from "../../../util/bus";
  import {getNoticeList} from "../../../api/desk/notice";

  let _this = this;

export default {
  name: "top-notice",
  data () {
    return {
      time10: 0,
      count: 0,
      activeName: 'first',
      option: {
        props: {
          title: 'title',
          subtitle: 'createTime',
        },
      },
      data: [],
    }
  },
  created () {
    _this = this;
  },
  mounted() {
    let _this = this;
    Bus.$on('notice',function(data){
      _this.time10 = data;
    })
  },
  watch: {
    time10: (newVal, oldVal) => {
      if (!newVal)  return;
      // console.log("newVal", newVal)
      _this.getData();
    }
  },
  methods: {
    handleClick(row){
      this.$router.push({
        path: "/desk/mynotice",
        query: {id: row.id}
      });
    },
    pageChange (page, done) {
      /*setTimeout(() => {
        this.$message.success('頁码' + page)
        this.data = this.data.concat(list);
        done();
      }, 1000)*/
      this.$router.push({
        path: "/desk/mynotice"
      });
      done();
      document.getElementById("notice").click();
    },
    getData(){
      getNoticeList(1, 10, {hadRead: 0}).then(res => {
        const data = res.data.data;
        this.data = data.records;
        this.count = data.total;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
