|
@@ -0,0 +1,116 @@
|
|
|
+// pages/comments/comments.js
|
|
|
+const getReq = require('./../../config.js').getReq
|
|
|
+Page({
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ comments: [],
|
|
|
+ hasmore: '',
|
|
|
+ curpage: 1,
|
|
|
+ common_id: '',
|
|
|
+ addtimes: []
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ 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: 3398,
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ 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)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () {
|
|
|
+ if (!this.data.hasmore) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.data.curpage++
|
|
|
+ this.getDatas(3398, this.data.curpage)
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
+
|
|
|
+ }
|
|
|
+})
|