comments.js 2.5 KB

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