index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // pages/user/my_comment/index.js
  2. const {
  3. request,
  4. serverName,
  5. imgServer
  6. } = require('../../../utils/services');
  7. const {
  8. defaultImg,
  9. noExhibitionImg,
  10. noCollectionImg
  11. } = require('../../../utils/images');
  12. const {
  13. Toast
  14. } = require('../../../utils/util.js');
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. myComment: [],
  21. loading: false,
  22. currentPage: 1,
  23. full_star_img: "../../../imgs/icon/full.png",
  24. empty_star_img: "../../../imgs/icon/empty.png",
  25. half_star_img: "../../../imgs/icon/half.png",
  26. imgServer
  27. },
  28. tapTodetail: function(e) {
  29. let {
  30. id,
  31. product
  32. } = e.currentTarget.dataset;
  33. if (product){
  34. wx.navigateTo({
  35. url: `../../yuezhan/pay_page/index?id=${id}`,
  36. success: function (res) { },
  37. fail: function (res) { },
  38. complete: function (res) { },
  39. })
  40. }
  41. else{
  42. wx.navigateTo({
  43. url: `../../zl_detail/index?id=${id}`,
  44. success: function (res) { },
  45. fail: function (res) { },
  46. complete: function (res) { },
  47. })
  48. }
  49. },
  50. fix_starImg: function (points) {
  51. let strPoints = String(Number(points).toFixed(2));
  52. let show_Arr = [];
  53. let ten = strPoints.split('.')[0] || 0;
  54. let unit = strPoints.split('.')[1] || 0;
  55. let surPlus = 0;
  56. if (strPoints < 0) {
  57. return
  58. }
  59. if (ten) {
  60. for (let i = 0; i < Number(ten); i++) {
  61. show_Arr.push({
  62. 'img': this.data.full_star_img
  63. })
  64. }
  65. surPlus = 5 - Number(ten);
  66. }
  67. if (unit && surPlus > 0) {
  68. let numUnit = Number(unit.substr(0, 1)) || 0
  69. if (numUnit > 0) {
  70. // let fix_unit = Math.round(numUnit);
  71. // switch (true) {
  72. // case numUnit > 5:
  73. // show_Arr.push({
  74. // 'img': this.data.half_star_img
  75. // })
  76. // break;
  77. // case numUnit <= 5:
  78. // show_Arr.push({
  79. // 'img': this.data.half_star_img
  80. // })
  81. // break;
  82. // default:
  83. // break
  84. // }
  85. show_Arr.push({
  86. 'img': this.data.half_star_img
  87. })
  88. } else if (numUnit == 0) {
  89. show_Arr.push({
  90. 'img': this.data.empty_star_img
  91. })
  92. } else {
  93. return
  94. }
  95. }
  96. if (surPlus > 0) {
  97. for (let i = 0; i < surPlus - 1; i++) {
  98. show_Arr.push({
  99. 'img': this.data.empty_star_img
  100. })
  101. }
  102. }
  103. return show_Arr
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function(options) {
  109. this.setData({
  110. serverName,
  111. noExhibitionImg,
  112. defaultImg,
  113. noCollectionImg
  114. })
  115. this.getComment(1)
  116. },
  117. onPullDownRefresh: function() {
  118. this.setData({
  119. myComment: [],
  120. });
  121. this.getComment(1)
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function() {
  127. },
  128. loadMore: function() {
  129. if (!this.data.lastPage) {
  130. console.log(this.data.currentPage + 1)
  131. this.getComment(this.data.currentPage + 1);
  132. } else {
  133. return;
  134. }
  135. },
  136. onReachBottom: function() {
  137. if (!this.data.loading) {
  138. this.loadMore();
  139. console.log('reach Bottom');
  140. }
  141. },
  142. getComment: function(page) {
  143. let loginSessionKey = wx.getStorageSync("token") || "";
  144. request["getComments"]({
  145. loginSessionKey,
  146. pageNumber: page
  147. }, "", res => {
  148. if (res.data.code > -1) {
  149. let tempContent = this.data.myComment ?
  150. this.data.myComment :
  151. [];
  152. let {
  153. last: lastPage,
  154. totalPages,
  155. content: myComment
  156. } = res.data.data;
  157. if (myComment) {
  158. for (let i = 0; i < myComment.length; i++) {
  159. let comments_star = this.fix_starImg(myComment[i].exhibition.score || '0.0')
  160. myComment[i]['imgObj'] = comments_star
  161. }
  162. }
  163. console.log('myComment', myComment)
  164. this.setData({
  165. currentPage: res.data.data.number + 1,
  166. lastPage,
  167. loading: false,
  168. myComment: tempContent.concat(myComment),
  169. });
  170. console.log(myComment)
  171. wx.stopPullDownRefresh();
  172. }
  173. }, err => {
  174. },
  175. complete => {
  176. })
  177. },
  178. /**
  179. * 生命周期函数--监听页面显示
  180. */
  181. onShow: function() {
  182. },
  183. /**
  184. * 生命周期函数--监听页面隐藏
  185. */
  186. onHide: function() {
  187. },
  188. /**
  189. * 生命周期函数--监听页面卸载
  190. */
  191. onUnload: function() {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function() {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function() {
  202. }
  203. })