moreReply.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // pages/moreReply/moreReply.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. replyList:[],
  10. replyInputFocus:true,
  11. replyDesc:'',
  12. replyTempInputValue:'',
  13. temppostid:0
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.data.temppostid=options.showId;
  20. this.getReplyList();
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面隐藏
  34. */
  35. onHide: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面卸载
  39. */
  40. onUnload: function () {
  41. },
  42. /**
  43. * 页面相关事件处理函数--监听用户下拉动作
  44. */
  45. onPullDownRefresh: function () {
  46. console.log('onPullDownRefresh')
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function () {
  52. console.log('onReachBottom')
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. getReplyList:function(){
  60. var that = this;
  61. var url = app.globalData.cloudBase + "/cloud/Buy/GetReplyById";
  62. wx.request({
  63. url: url,
  64. method: 'GET',
  65. header: {
  66. "Content-Type": "json"
  67. },
  68. data: {
  69. postId: this.data.temppostid
  70. }
  71. ,
  72. success: function (res) {
  73. console.debug(res.data);
  74. if (res.data.status === "ok") {
  75. that.processReplys(res.data.list);
  76. }
  77. },
  78. fail: function (error) {
  79. console.log(error)
  80. }
  81. })
  82. },
  83. processReplys:function(list){
  84. if (null === list || list.length <= 0) {
  85. return;
  86. }
  87. var replys = [];
  88. var date = new Date();
  89. //年
  90. var NY = ''+date.getFullYear();
  91. //月
  92. var NM = this.PrefixInteger(date.getMonth() + 1,2);// < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  93. //日
  94. var ND = this.PrefixInteger(date.getDate(),2);// < 10 ? '0' + date.getDate() : date.getDate();
  95. for (var index = 0; index < list.length; index++) {
  96. var item = list[index];
  97. var cdate = new Date(item.updateTime);
  98. var cy = ''+cdate.getFullYear();
  99. var cm = this.PrefixInteger(cdate.getMonth() + 1,2);// < 10 ? '0' + (cdate.getMonth() + 1) : cdate.getMonth() + 1);
  100. var cd = this.PrefixInteger(cdate.getDate(),2);// < 10 ? '0' + cdate.getDate() : cdate.getDate();
  101. var time = '';
  102. if (cy === NY && cm === NM && cd === ND) {
  103. var ch = this.PrefixInteger(cdate.getHours(),2);
  104. var cm = this.PrefixInteger(cdate.getMinutes(),2);
  105. var cs = this.PrefixInteger(cdate.getSeconds(),2);
  106. time = '' + ch + ':' + cm + ':' + cs;
  107. } else {
  108. time = '' + cy + '-' + cm + '-' + cd;
  109. }
  110. var reply = {
  111. id: item.id,
  112. openid: item.openid,
  113. showBoxId: item.showBoxId,
  114. content: item.content,
  115. nick: item.nick,
  116. headIcon: (item.headIcon != undefined && item.headIcon != null)? app.globalData.imageBase+"/"+ item.headIcon:null,
  117. stars: util.convertToStarsArray("" + item.star),
  118. score: item.score,
  119. time: time
  120. }
  121. replys.push(reply);
  122. }
  123. this.setData({
  124. replyList: replys
  125. })
  126. },
  127. replyInputHandle:function(e){
  128. this.setData({
  129. replyTempInputValue: e.detail.value
  130. })
  131. },
  132. replyClick:function(e){
  133. var openid = wx.getStorageSync('openid');
  134. var that = this;
  135. var url = app.globalData.cloudBase + "/cloud/Buy/Post/Reply";
  136. wx.request({
  137. url: url,
  138. method: 'GET',
  139. data: {
  140. openid: openid,
  141. showBoxId: this.data.temppostid,
  142. content: this.data.replyTempInputValue
  143. },
  144. header: {
  145. "Content-Type": "json"
  146. },
  147. success: function (res) {
  148. console.debug(res.data);
  149. if (res.data.status === "ok") {
  150. that.setData({
  151. replyDesc:''
  152. })
  153. that.getReplyList();
  154. }
  155. },
  156. fail: function (error) {
  157. console.log(error)
  158. }
  159. })
  160. }
  161. ,
  162. PrefixInteger: function (num, length) {
  163. return (Array(length).join('0') + num).slice(-length);
  164. }
  165. })