comments.js 2.4 KB

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