index.js 4.7 KB

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