index.js 5.2 KB

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