index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. } = require('../../../utils/images');
  11. const {
  12. Toast
  13. } = require('../../../utils/util.js');
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. myComment: [],
  20. loading: false,
  21. currentPage: 1,
  22. imgServer,
  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. exhibitionId: "",
  27. sortType: 0,
  28. tapNav: [{
  29. name: '热门',
  30. sortType: 0
  31. }, {
  32. name: '时间',
  33. sortType: 1
  34. }]
  35. },
  36. fix_starImg: function (points) {
  37. let strPoints = String(Number(points).toFixed(2));
  38. let show_Arr = [];
  39. let ten = strPoints.split('.')[0] || 0;
  40. let unit = strPoints.split('.')[1] || 0;
  41. let surPlus = 0;
  42. if (strPoints < 0) {
  43. return
  44. }
  45. if (ten) {
  46. for (let i = 0; i < Number(ten); i++) {
  47. show_Arr.push({
  48. 'img': this.data.full_star_img
  49. })
  50. }
  51. surPlus = 5 - Number(ten);
  52. }
  53. if (unit && surPlus > 0) {
  54. let numUnit = Number(unit.substr(0, 1)) || 0
  55. if (numUnit > 0) {
  56. // let fix_unit = Math.round(numUnit);
  57. // switch (true) {
  58. // case numUnit > 5:
  59. // show_Arr.push({
  60. // 'img': this.data.half_star_img
  61. // })
  62. // break;
  63. // case numUnit <= 5:
  64. // show_Arr.push({
  65. // 'img': this.data.half_star_img
  66. // })
  67. // break;
  68. // default:
  69. // break
  70. // }
  71. show_Arr.push({
  72. 'img': this.data.half_star_img
  73. })
  74. } else if (numUnit == 0) {
  75. show_Arr.push({
  76. 'img': this.data.empty_star_img
  77. })
  78. } else {
  79. return
  80. }
  81. }
  82. if (surPlus > 0) {
  83. for (let i = 0; i < surPlus - 1; i++) {
  84. show_Arr.push({
  85. 'img': this.data.empty_star_img
  86. })
  87. }
  88. }
  89. return show_Arr
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function(options) {
  95. this.setData({
  96. defaultImg,
  97. exhibitionId: options.id,
  98. serverName
  99. })
  100. this.getComment(1)
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function() {
  106. },
  107. addCommentLike: function(e) {
  108. let {
  109. type,
  110. id,
  111. idx
  112. } = e.currentTarget.dataset;
  113. console.log(idx, type, id)
  114. let {
  115. myComment
  116. } = this.data;
  117. Toast.showToast2('loading');
  118. let loginSessionKey = wx.getStorageSync('token') || "";
  119. // if (loginSessionKey){
  120. request['commentLike']({
  121. loginSessionKey,
  122. commentId: id,
  123. type: Number(type),
  124. }, "post", res => {
  125. if (res.data.code > -1) {
  126. console.log("asdw", myComment)
  127. myComment[idx].hasLike = res.data.data.hasLike
  128. if (res.data.data.hasLike) {
  129. myComment[idx].likeCount += 1;
  130. } else {
  131. myComment[idx].likeCount -= 1;
  132. }
  133. this.setData({
  134. myComment: myComment
  135. })
  136. }
  137. }, err => {
  138. }, complete => {
  139. Toast.hideLoading();
  140. })
  141. // }
  142. },
  143. loadMore: function() {
  144. if (!this.data.lastPage) {
  145. console.log(this.data.currentPage + 1)
  146. this.getComment(this.data.currentPage + 1);
  147. } else {
  148. return;
  149. }
  150. },
  151. onReachBottom: function() {
  152. if (!this.data.loading) {
  153. this.loadMore();
  154. console.log('reach Bottom');
  155. }
  156. },
  157. tapToComment: function() {
  158. let {
  159. exhibitionId
  160. } = this.data;
  161. wx.navigateTo({
  162. url: `../../zl_detail/create_evaluation/index?id=${exhibitionId}`,
  163. success: function(res) {},
  164. fail: function(res) {},
  165. complete: function(res) {},
  166. })
  167. },
  168. getComment: function(page) {
  169. let loginSessionKey = wx.getStorageSync("token") || "";
  170. let {
  171. exhibitionId,
  172. sortType
  173. } = this.data
  174. request["getCommentslist"]({
  175. exhibitionId,
  176. loginSessionKey,
  177. page: page,
  178. sortType
  179. }, "", res => {
  180. if (res.data.code > -1) {
  181. let tempContent = this.data.myComment ?
  182. this.data.myComment :
  183. [];
  184. let {
  185. exhibition,
  186. comments,
  187. score
  188. } = res.data.data
  189. let {
  190. last: lastPage,
  191. totalPages,
  192. content: myComment
  193. } = comments;
  194. if (myComment){
  195. for (let i = 0; i < myComment.length; i++) {
  196. let comments_star = this.fix_starImg(myComment[i].score || '0.0')
  197. myComment[i]['imgObj'] = comments_star
  198. }
  199. }
  200. let score_img = this.fix_starImg(score)
  201. console.log(score_img)
  202. // console.log(res)
  203. this.setData({
  204. currentPage: res.data.data.number + 1,
  205. lastPage,
  206. loading: false,
  207. myComment: tempContent.concat(myComment),
  208. exhibition,
  209. score_img,
  210. score
  211. });
  212. console.log(myComment)
  213. wx.stopPullDownRefresh();
  214. }
  215. }, err => {
  216. },
  217. complete => {
  218. })
  219. },
  220. changeNav: function(e) {
  221. let {
  222. type
  223. } = e.currentTarget.dataset;
  224. this.setData({
  225. sortType: type,
  226. myComment: []
  227. })
  228. this.getComment(1)
  229. // console.log(e)
  230. },
  231. /**
  232. * 生命周期函数--监听页面显示
  233. */
  234. onShow: function() {
  235. },
  236. /**
  237. * 生命周期函数--监听页面隐藏
  238. */
  239. onHide: function() {
  240. },
  241. /**
  242. * 生命周期函数--监听页面卸载
  243. */
  244. onUnload: function() {
  245. },
  246. /**
  247. * 页面相关事件处理函数--监听用户下拉动作
  248. */
  249. onPullDownRefresh: function() {
  250. },
  251. /**
  252. * 页面上拉触底事件的处理函数
  253. */
  254. onReachBottom: function() {
  255. },
  256. /**
  257. * 用户点击右上角分享
  258. */
  259. onShareAppMessage: function() {
  260. }
  261. })