// pages/buyer/talkToBuyer/talkToBuyer.js var util = require('../../../utils/util.js'); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { HeadIcon: null, nick: '', stars: [1, 0, 0, 0, 0], score: 80, postList: [], hiddenmodalput: true, replyTex: '', replyTempInputValue: '', temppostid: 0, openid:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var headIcon = options.headIcon; var nick = (options.nick==null||options.nick==undefined)?'':options.nick; var stars = util.convertToStarsArray("" + options.star); var score = options.score; this.data.openid = options.openid; this.setData({ stars: stars, score: score, HeadIcon: app.globalData.imageBase + "/" + headIcon, nick: nick }) this.getPostList(); }, replyMsg: function(e) { wx.navigateTo({ url: "/pages/msg/submitMsg" }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, workStreamHandle: function(e) { // var openid = wx.getStorageSync('openid'); var that = this; var url = app.globalData.cloudBase + "/cloud/Buy/BindWorkToMe"; wx.request({ url: url, method: 'GET', data: { openid: this.data.openid, showBoxId: e.currentTarget.dataset.postid }, header: { "Content-Type": "json" }, success: function(res) { console.debug(res.data); if (res.data.status === "ok") { } }, fail: function(error) { console.log(error) } }) }, postReplyHandle: function(e) { console.log("+++++" + e.currentTarget.dataset.postid); this.setData({ replyTempInputValue: '', replyTex: '', hiddenmodalput: false, temppostid: e.currentTarget.dataset.postid }); }, replyCancelHandle: function() { this.setData({ hiddenmodalput: true }); }, replyConfirmHandle: function() { this.setData({ hiddenmodalput: true }) 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.getPostList(); } }, fail: function(error) { console.log(error) } }) }, bindReplyInputHandle: function(e) { this.setData({ replyTempInputValue: e.detail.value }) }, viewAllReplyHandle: function(e) { wx.navigateTo({ url: "../../moreReply/moreReply?showId=" + e.currentTarget.dataset.postid }) }, getPostList: function(e) { var that = this; var openid = this.data.openid;//wx.getStorageSync('openid'); var url = app.globalData.cloudBase + "/cloud/Buy/GetPostList"; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, data: { openid: openid }, success: function(res) { console.debug(res.data); if (res.data.status === "ok") { that.processData(res.data.list); } }, fail: function(error) { console.log(error) } }) }, processData: function(list) { if (null === list || list.length <= 0) { return; } var postList = []; 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 post = list[index]; var cdate = new Date(post.updateTime); var cy = '' + cdate.getFullYear(); var cm = this.PrefixInteger(cdate.getMonth() + 1, 2); // (cdate.getMonth() + 1 < 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(date.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 replys = []; for (var i = 0; i < post.replys.length && i < 2; i++) { var item = post.replys[i]; var reply = { id: item.id, openid: item.openid, showBoxId: item.showBoxId, content: item.content, name: item.nick } replys.push(reply); } var photos = []; for (var j = 0; j < post.photos.length; j++) { var item = post.photos[j]; var photo = { id: item.id, showBoxId: item.showBoxId, photo: item.photo, large: app.globalData.imageBase + "/" + item.photo, middle: app.globalData.imageBase + "/mid_" + item.photo, small: app.globalData.imageBase + "/thumb_" + item.photo } photos.push(photo); } var temp = { id: post.id, nick: post.nick, headIcon: app.globalData.imageBase + "/" + post.headIcon, updateTime: time, title: post.desc, stars: util.convertToStarsArray("" + post.star), score: post.score, replyList: replys, photoList: photos, replySize: post.replys.length } postList.push(temp); } this.setData({ postList: postList }) } , PrefixInteger: function(num, length) { return (Array(length).join('0') + num).slice(-length); } })