talkToBuyer.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // pages/buyer/talkToBuyer/talkToBuyer.js
  2. var util = require('../../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. HeadIcon: null,
  10. nick: '',
  11. stars: [1, 0, 0, 0, 0],
  12. score: 80,
  13. postList: [],
  14. hiddenmodalput: true,
  15. replyTex: '',
  16. replyTempInputValue: '',
  17. temppostid: 0,
  18. openid:''
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function(options) {
  24. var headIcon = options.headIcon;
  25. var nick = (options.nick==null||options.nick==undefined)?'':options.nick;
  26. var stars = util.convertToStarsArray("" + options.star);
  27. var score = options.score;
  28. this.data.openid = options.openid;
  29. this.setData({
  30. stars: stars,
  31. score: score,
  32. HeadIcon: app.globalData.imageBase + "/" + headIcon,
  33. nick: nick
  34. })
  35. this.getPostList();
  36. },
  37. replyMsg: function(e) {
  38. wx.navigateTo({
  39. url: "/pages/msg/submitMsg"
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady: function() {
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow: function() {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide: function() {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload: function() {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function() {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function() {
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function() {
  76. },
  77. workStreamHandle: function(e) {
  78. // var openid = wx.getStorageSync('openid');
  79. var that = this;
  80. var url = app.globalData.cloudBase + "/cloud/Buy/BindWorkToMe";
  81. wx.request({
  82. url: url,
  83. method: 'GET',
  84. data: {
  85. openid: this.data.openid,
  86. showBoxId: e.currentTarget.dataset.postid
  87. },
  88. header: {
  89. "Content-Type": "json"
  90. },
  91. success: function(res) {
  92. console.debug(res.data);
  93. if (res.data.status === "ok") {
  94. }
  95. },
  96. fail: function(error) {
  97. console.log(error)
  98. }
  99. })
  100. },
  101. postReplyHandle: function(e) {
  102. console.log("+++++" + e.currentTarget.dataset.postid);
  103. this.setData({
  104. replyTempInputValue: '',
  105. replyTex: '',
  106. hiddenmodalput: false,
  107. temppostid: e.currentTarget.dataset.postid
  108. });
  109. },
  110. replyCancelHandle: function() {
  111. this.setData({
  112. hiddenmodalput: true
  113. });
  114. },
  115. replyConfirmHandle: function() {
  116. this.setData({
  117. hiddenmodalput: true
  118. })
  119. var openid = wx.getStorageSync('openid');
  120. var that = this;
  121. var url = app.globalData.cloudBase + "/cloud/Buy/Post/Reply";
  122. wx.request({
  123. url: url,
  124. method: 'GET',
  125. data: {
  126. openid: openid,
  127. showBoxId: this.data.temppostid,
  128. content: this.data.replyTempInputValue
  129. },
  130. header: {
  131. "Content-Type": "json"
  132. },
  133. success: function(res) {
  134. console.debug(res.data);
  135. if (res.data.status === "ok") {
  136. that.getPostList();
  137. }
  138. },
  139. fail: function(error) {
  140. console.log(error)
  141. }
  142. })
  143. },
  144. bindReplyInputHandle: function(e) {
  145. this.setData({
  146. replyTempInputValue: e.detail.value
  147. })
  148. },
  149. viewAllReplyHandle: function(e) {
  150. wx.navigateTo({
  151. url: "../../moreReply/moreReply?showId=" + e.currentTarget.dataset.postid
  152. })
  153. },
  154. getPostList: function(e) {
  155. var that = this;
  156. var openid = this.data.openid;//wx.getStorageSync('openid');
  157. var url = app.globalData.cloudBase + "/cloud/Buy/GetPostList";
  158. wx.request({
  159. url: url,
  160. method: 'GET',
  161. header: {
  162. "Content-Type": "json"
  163. },
  164. data: {
  165. openid: openid
  166. },
  167. success: function(res) {
  168. console.debug(res.data);
  169. if (res.data.status === "ok") {
  170. that.processData(res.data.list);
  171. }
  172. },
  173. fail: function(error) {
  174. console.log(error)
  175. }
  176. })
  177. },
  178. processData: function(list) {
  179. if (null === list || list.length <= 0) {
  180. return;
  181. }
  182. var postList = [];
  183. var date = new Date();
  184. //年
  185. var NY = '' + date.getFullYear();
  186. //月
  187. var NM = this.PrefixInteger(date.getMonth() + 1, 2); // < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  188. //日
  189. var ND = this.PrefixInteger(date.getDate(), 2); // < 10 ? '0' + date.getDate() : date.getDate();
  190. for (var index = 0; index < list.length; index++) {
  191. var post = list[index];
  192. var cdate = new Date(post.updateTime);
  193. var cy = '' + cdate.getFullYear();
  194. var cm = this.PrefixInteger(cdate.getMonth() + 1, 2); // (cdate.getMonth() + 1 < 10 ? '0' + (cdate.getMonth() + 1) : cdate.getMonth() + 1);
  195. var cd = this.PrefixInteger(cdate.getDate(), 2); // < 10 ? '0' + cdate.getDate() : cdate.getDate();
  196. var time = '';
  197. if (cy === NY && cm === NM && cd === ND) {
  198. var ch = this.PrefixInteger(date.getHours(), 2);
  199. var cm = this.PrefixInteger(cdate.getMinutes(), 2);
  200. var cs = this.PrefixInteger(cdate.getSeconds(), 2);
  201. time = '' + ch + ':' + cm + ':' + cs;
  202. } else {
  203. time = '' + cy + '-' + cm + '-' + cd;
  204. }
  205. var replys = [];
  206. for (var i = 0; i < post.replys.length && i < 2; i++) {
  207. var item = post.replys[i];
  208. var reply = {
  209. id: item.id,
  210. openid: item.openid,
  211. showBoxId: item.showBoxId,
  212. content: item.content,
  213. name: item.nick
  214. }
  215. replys.push(reply);
  216. }
  217. var photos = [];
  218. for (var j = 0; j < post.photos.length; j++) {
  219. var item = post.photos[j];
  220. var photo = {
  221. id: item.id,
  222. showBoxId: item.showBoxId,
  223. photo: item.photo,
  224. large: app.globalData.imageBase + "/" + item.photo,
  225. middle: app.globalData.imageBase + "/mid_" + item.photo,
  226. small: app.globalData.imageBase + "/thumb_" + item.photo
  227. }
  228. photos.push(photo);
  229. }
  230. var temp = {
  231. id: post.id,
  232. nick: post.nick,
  233. headIcon: app.globalData.imageBase + "/" + post.headIcon,
  234. updateTime: time,
  235. title: post.desc,
  236. stars: util.convertToStarsArray("" + post.star),
  237. score: post.score,
  238. replyList: replys,
  239. photoList: photos,
  240. replySize: post.replys.length
  241. }
  242. postList.push(temp);
  243. }
  244. this.setData({
  245. postList: postList
  246. })
  247. }
  248. ,
  249. PrefixInteger: function(num, length) {
  250. return (Array(length).join('0') + num).slice(-length);
  251. }
  252. })