comment.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. // 当前tab
  8. // currentTab: -1,
  9. // 列表高度
  10. swiperHeight: 0,
  11. // 页面参数
  12. options: {
  13. goods_id: null,
  14. scoreType: -1
  15. },
  16. // 评论列表
  17. list: [],
  18. // 当前页码
  19. page: 1,
  20. // show
  21. notcont: false
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function(options) {
  27. let _this = this;
  28. // 设置swiper的高度
  29. this.setSwiperHeight();
  30. // 记录页面参数
  31. _this.setData({
  32. 'options.goods_id': options.goods_id
  33. }, function() {
  34. // 获取评论列表
  35. _this.getCommentList();
  36. });
  37. },
  38. /**
  39. * 设置swiper的高度
  40. */
  41. setSwiperHeight: function() {
  42. // 获取系统信息(拿到屏幕宽度)
  43. let systemInfo = wx.getSystemInfoSync(),
  44. rpx = systemInfo.windowWidth / 750, // 计算rpx
  45. tapHeight = Math.floor(rpx * 80) + 1, // tap高度
  46. swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
  47. this.setData({
  48. swiperHeight
  49. });
  50. },
  51. /**
  52. * 获取评论列表
  53. */
  54. getCommentList: function(isNextPage, page) {
  55. let _this = this;
  56. let params = _this.data.options;
  57. params.page = page || 1;
  58. App._get('comment/lists', params, function(result) {
  59. let resultList = result.data.list,
  60. dataList = _this.data.list;
  61. if (isNextPage !== true || typeof dataList.data === 'undefined') {
  62. _this.setData({
  63. list: resultList,
  64. total: result.data.total,
  65. notcont: !resultList.length
  66. });
  67. } else {
  68. _this.setData({
  69. 'list.data': dataList.data.concat(resultList.data),
  70. total: result.data.total
  71. });
  72. }
  73. });
  74. },
  75. /**
  76. * 点击tab切换
  77. */
  78. swichNav: function(e) {
  79. let _this = this;
  80. _this.setData({
  81. list: {},
  82. page: 1,
  83. no_more: false,
  84. 'options.scoreType': e.target.dataset.current
  85. }, function() {
  86. // 获取评论列表
  87. _this.getCommentList();
  88. });
  89. },
  90. /**
  91. * 图片预览
  92. */
  93. previewImages: function(e) {
  94. let commentIndex = e.target.dataset.commentIndex,
  95. imgIndex = e.target.dataset.imgIndex,
  96. images = this.data.list.data[commentIndex].image,
  97. imageUrls = [];
  98. images.forEach(function(item) {
  99. imageUrls.push(item.file_path);
  100. });
  101. wx.previewImage({
  102. current: imageUrls[imgIndex],
  103. urls: imageUrls
  104. })
  105. },
  106. /**
  107. * 下拉到底加载数据
  108. */
  109. bindDownLoad: function() {
  110. // 已经是最后一页
  111. if (this.data.page >= this.data.list.last_page) {
  112. this.setData({
  113. no_more: true
  114. });
  115. return false;
  116. }
  117. this.getCommentList(true, ++this.data.page);
  118. },
  119. })