| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- // 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);
- }
- })
|