// pages/notice/notice.js

import request from '../../utils/request'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        noticeList:''  //公告标题
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad:async function(options) {
        let result = await request('/front/notificationFront')  //获取公告列表
        // console.log(result);
        // 按id降序排序(即按发布时间从近到远排序)
        for(let i = 0;i < result.length-1;i++){
            for(let j = 0;j < result.length-1-i;j++){
                if(result[j].id < result[j+1].id){
                    let temp = result[j]
                    result[j] = result[j+1]
                    result[j+1] = temp
                }
            }                
        }
        
        this.setData({
            noticeList:result
        })
    },

    // 点击跳转到公告详情
    toNoticeDetail(e){
        // console.log(e);
        let noticeId = e.currentTarget.dataset.item.id
        wx.navigateTo({
          url: '/pages/noticeDetail/noticeDetail?id=' + noticeId,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})