<template>
  <view>
    <div class="msg-list" v-for="(item, index) in msgList" :key="index" @click="handleDetail(item)">
      <div class="msg-title">{{ item.noticeName }}</div>
      <div class="msg-time">{{ item.createTime }}</div>
    </div>
  </view>
</template>

<script>
import config from '@/config'

export default {
  data() {
    return {
      userId: uni.getStorageSync('userId'),
      token: uni.getStorageSync('App-Token'),
      // 消息列表
      msgList: []
    }
  },
  onLoad() {
    // this.getMsgList()
  },
  methods: {
    // 获取消息列表
    async getMsgList() {
      uni.request({
        url: config.bmwUrl + '/studentUsers/getNoticeList',
        method: 'post',
        data: {},
        header: {
          Authorization: this.token
        },
        success: res => {
          console.log('🚀 ~ getMsgList ~ res:', res)
          this.msgList = res.data
          console.log('🚀 ~ getMsgList ~ this.msgList:', this.msgList)
        }
      })
    },
    // 跳转消息详情
    handleDetail(item) {
      const params = {
        noticeName: item.noticeName,
        noticeContent: item.noticeContent,
      }
      uni.navigateTo({
        url: `/pages/YNEduApp/user/msgDetail?params=${JSON.stringify(params)}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.msg-list {
  margin: 10px;
  padding: 10px;
  background: #fff;
  border-radius: 5px;
  .msg-title {
    font-size: 16px;
    color: #333;
  }
  .msg-time {
    font-size: 14px;
    color: #999;
    margin-top: 5px;
  }
}
</style>
