123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- // 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)
- }
- })
|