comment.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // pages/pt/comment/comment.js
  2. var api = require('../../../api.js');
  3. var app = getApp();
  4. var is_no_more = false;
  5. var is_loading = false;
  6. var p = 2;
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. app.pageOnLoad(this);
  18. is_no_more = false;
  19. is_loading = false;
  20. p = 2;
  21. var page = this;
  22. page.setData({
  23. gid: options.id,
  24. });
  25. wx.showLoading({
  26. title: "正在加载",
  27. mask: true,
  28. });
  29. app.request({
  30. url: api.group.comment,
  31. data: {
  32. gid: options.id,
  33. },
  34. success: function (res) {
  35. wx.hideLoading();
  36. if (res.code == 1) {
  37. wx.showModal({
  38. title: "提示",
  39. content: res.msg,
  40. showCancel: false,
  41. success: function (e) {
  42. if (e.confirm) {
  43. wx.navigateBack();
  44. }
  45. }
  46. });
  47. }
  48. if (res.code == 0) {
  49. if (res.data.comment.length==0){
  50. wx.showModal({
  51. title: "提示",
  52. content: '暂无评价',
  53. showCancel: false,
  54. success: function (e) {
  55. if (e.confirm) {
  56. wx.navigateBack();
  57. }
  58. }
  59. });
  60. }
  61. page.setData({
  62. comment: res.data.comment,
  63. });
  64. }
  65. page.setData({
  66. show_no_data_tip: (page.data.comment.length == 0),
  67. });
  68. }
  69. });
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. var page = this;
  101. if (is_loading || is_no_more)
  102. return;
  103. is_loading = true;
  104. app.request({
  105. url: api.group.comment,
  106. data: {
  107. gid: page.data.gid,
  108. page: p,
  109. },
  110. success: function (res) {
  111. if (res.code == 0) {
  112. var comment = page.data.comment.concat(res.data.comment);
  113. page.setData({
  114. comment: comment,
  115. });
  116. if (res.data.comment.length == 0) {
  117. is_no_more = true;
  118. }
  119. }
  120. p++;
  121. },
  122. complete: function () {
  123. is_loading = false;
  124. }
  125. });
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage: function () {
  131. } ,
  132. /**
  133. * 图片放大
  134. */
  135. bigToImage: function (e) {
  136. var urls = this.data.comment[e.target.dataset.index]['pic_list'];
  137. wx.previewImage({
  138. current: e.target.dataset.url, // 当前显示图片的http链接
  139. urls: urls // 需要预览的图片http链接列表
  140. })
  141. }
  142. })