var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); var app = getApp(); Page({ data: { evalList: [], page: 1, limit: 10, goodsId:'' }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 if(options.id){ this.setData({ goodsId:options.id }); this.getEvalList(); } }, getEvalList() { wx.showLoading({ title: '加载中', }); util.request(api.getGoodsComment, { goodsId: this.data.goodsId, page: this.data.page, limit: this.data.limit }).then(res=> { wx.hideLoading(); if (res.errno === 0) { console.log(res.data); let list=res.data.list.map(item=>{ if(item.commentImgs==null||item.commentImgs==''){ item.commentImg=[]; }else{ item.commentImg=item.commentImgs.split(','); } item.date=item.createTime.substr(0,10); return item; }); this.setData({ evalList: this.data.evalList.concat(list), totalPages: res.data.pages }); } }); }, onReachBottom() { if (this.data.totalPages > this.data.page) { this.setData({ page: this.data.page + 1 }); this.getEvalList(); } else { wx.showToast({ title: '没有更多评价了', icon: 'none', duration: 2000 }); return false; } }, previewImg(e){ let img=e.currentTarget.dataset.img; let imgs=e.currentTarget.dataset.imgs; wx.previewImage({ current:img, urls: imgs }) }, onReady: function() { // 页面渲染完成 }, onShow: function() { // 页面显示 }, onHide: function() { // 页面隐藏 }, onUnload: function() { // 页面关闭 } })