123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- // 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: '菜品评论列表'
- }
- }
- })
|