index.js 4.6 KB

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