// pages/moreReply/moreReply.js var util = require('../../utils/util.js'); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { replyList:[], replyInputFocus:true, replyDesc:'', replyTempInputValue:'', temppostid:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.temppostid=options.showId; this.getReplyList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { console.log('onPullDownRefresh') }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { console.log('onReachBottom') }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, getReplyList:function(){ var that = this; var url = app.globalData.cloudBase + "/cloud/Buy/GetReplyById"; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, data: { postId: this.data.temppostid } , success: function (res) { console.debug(res.data); if (res.data.status === "ok") { that.processReplys(res.data.list); } }, fail: function (error) { console.log(error) } }) }, processReplys:function(list){ if (null === list || list.length <= 0) { return; } var replys = []; var date = new Date(); //年 var NY = ''+date.getFullYear(); //月 var NM = this.PrefixInteger(date.getMonth() + 1,2);// < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); //日 var ND = this.PrefixInteger(date.getDate(),2);// < 10 ? '0' + date.getDate() : date.getDate(); for (var index = 0; index < list.length; index++) { var item = list[index]; var cdate = new Date(item.updateTime); var cy = ''+cdate.getFullYear(); var cm = this.PrefixInteger(cdate.getMonth() + 1,2);// < 10 ? '0' + (cdate.getMonth() + 1) : cdate.getMonth() + 1); var cd = this.PrefixInteger(cdate.getDate(),2);// < 10 ? '0' + cdate.getDate() : cdate.getDate(); var time = ''; if (cy === NY && cm === NM && cd === ND) { var ch = this.PrefixInteger(cdate.getHours(),2); var cm = this.PrefixInteger(cdate.getMinutes(),2); var cs = this.PrefixInteger(cdate.getSeconds(),2); time = '' + ch + ':' + cm + ':' + cs; } else { time = '' + cy + '-' + cm + '-' + cd; } var reply = { id: item.id, openid: item.openid, showBoxId: item.showBoxId, content: item.content, nick: item.nick, headIcon: (item.headIcon != undefined && item.headIcon != null)? app.globalData.imageBase+"/"+ item.headIcon:null, stars: util.convertToStarsArray("" + item.star), score: item.score, time: time } replys.push(reply); } this.setData({ replyList: replys }) }, replyInputHandle:function(e){ this.setData({ replyTempInputValue: e.detail.value }) }, replyClick:function(e){ var openid = wx.getStorageSync('openid'); var that = this; var url = app.globalData.cloudBase + "/cloud/Buy/Post/Reply"; wx.request({ url: url, method: 'GET', data: { openid: openid, showBoxId: this.data.temppostid, content: this.data.replyTempInputValue }, header: { "Content-Type": "json" }, success: function (res) { console.debug(res.data); if (res.data.status === "ok") { that.setData({ replyDesc:'' }) that.getReplyList(); } }, fail: function (error) { console.log(error) } }) } , PrefixInteger: function (num, length) { return (Array(length).join('0') + num).slice(-length); } })