// pages/comments/comments.js const getReq = require('./../../config.js').getReq Page({ /** * 页面的初始数据 */ data: { comments: [], hasmore: '', curpage: 1, common_id: '', addtimes: [], show_carousel: false, carouselImgs: [], current: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ common_id: options.common_id }) this.getDatas(options.common_id, this.data.curpage) }, getDatas(common_id, curpage) { wx.showLoading({ title: '加载中' }) var self = this getReq({ act: 'goods_common', op: 'comments', goods_commonid: common_id, curpage, page: 10 }, function (res) { if (res.code == 200) { wx.hideLoading() self.getAddTimes(res.datas.comments) self.setData({ comments: self.data.comments.concat(res.datas.comments), hasmore: res.datas.mobile_page.hasmore }) } else { wx.showToast({ icon: 'none', title: res.message, duration: 2000 }) } }) }, getAddTimes(comments) { let arr = [] comments.map(item => { let addtime = item.addtime || '' if (addtime) { let date = new Date(addtime * 1000); let year = date.getFullYear(); let month = date.getMonth() + 1; let day = date.getDate(); addtime = `${year}.${month}.${day}` } arr.push(addtime) }) this.setData({ addtimes: this.data.addtimes.concat(arr) }) }, showCarousel(e) { let carouselImgs = e.currentTarget.dataset.images let current = e.currentTarget.dataset.current this.setData({ show_carousel: true, carouselImgs, current }) }, hideCarousel() { this.setData({ show_carousel: false }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if (!this.data.hasmore) { return } this.data.curpage++ this.getDatas(this.data.common_id, this.data.curpage) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })