// pages/commentList/commentList.js import { imgUrl } from "../api/request" import { request, baseUrl } from "../api/canteen-request.js" Page({ /** * 页面的初始数据 */ data: { // 图片前缀 imgUrl: imgUrl, // 服务器地址 baseUrl: baseUrl + '/', // 评论次数 commentCount: '', // 点赞次数 compliment: '', // 评论列表 commentList: [], // 评论页数 page: 1, // 餐厅ID canteenId: '', // 食品ID dishesId: '', height: '93vh' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.commentCount != undefined && options.compliment != undefined) { this.setData({ commentCount: options.commentCount, compliment: options.compliment, canteenId: options.canteenId, dishesId: options.dishesId }) } else { this.setData({ canteenId: options.canteenId, dishesId: options.dishesId, height: '100vh' }) } this.getCommentById(); }, imageError(e) { let temp = this.data.commentList; temp[e.currentTarget.dataset.index].imgUrl = ''; this.setData({ commentList: temp }) }, getCommentById() { wx.showToast({ title: '加载中', icon: 'loading', duration: 1500 }) request({ url: '/mini/canteen/getDetailByDishesId?canteenId=' + this.data.canteenId + '&dishesId=' + this.data.dishesId + "&limit=10&page=" + this.data.page, method: 'GET' }).then(res => { if (res.data.length > 0) { let temp = res.data; temp = this.data.commentList.concat(temp); this.setData({ commentList: temp }) wx.hideToast(); } else { wx.showToast({ title: '已加载全部数据', icon: 'success', duration: 1000 }) } }) }, // 触底 scrollBottom(e) { this.setData({ page: this.data.page + 1 }) this.getCommentById() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: '菜品评论列表' } } })