comments.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // pages/comments/comments.js
  2. const getReq = require('./../../config.js').getReq
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. comments: [],
  9. hasmore: '',
  10. curpage: 1,
  11. common_id: '',
  12. addtimes: []
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.setData({
  19. common_id: options.common_id
  20. })
  21. this.getDatas(options.common_id, this.data.curpage)
  22. },
  23. getDatas(common_id, curpage) {
  24. wx.showLoading({
  25. title: '加载中'
  26. })
  27. var self = this
  28. getReq({
  29. act: 'goods_common',
  30. op: 'comments',
  31. goods_commonid: 3398,
  32. curpage,
  33. page: 10
  34. }, function (res) {
  35. if (res.code == 200) {
  36. wx.hideLoading()
  37. self.getAddTimes(res.datas.comments)
  38. self.setData({
  39. comments: self.data.comments.concat(res.datas.comments),
  40. hasmore: res.datas.mobile_page.hasmore
  41. })
  42. }
  43. })
  44. },
  45. getAddTimes(comments) {
  46. let arr = []
  47. comments.map(item => {
  48. let addtime = item.addtime || ''
  49. if (addtime) {
  50. let date = new Date(addtime * 1000);
  51. let year = date.getFullYear();
  52. let month = date.getMonth() + 1;
  53. let day = date.getDate();
  54. addtime = `${year}.${month}.${day}`
  55. }
  56. arr.push(addtime)
  57. })
  58. this.setData({
  59. addtimes: this.data.addtimes.concat(arr)
  60. })
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. if (!this.data.hasmore) {
  92. return
  93. }
  94. this.data.curpage++
  95. this.getDatas(3398, this.data.curpage)
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. }
  102. })