// pages/user/my_comment/index.js const { request, serverName, imgServer } = require('../../../utils/services'); const { defaultImg, noExhibitionImg, noCollectionImg } = require('../../../utils/images'); const { Toast } = require('../../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { myComment: [], loading: false, currentPage: 1, full_star_img: "../../../imgs/icon/full.png", empty_star_img: "../../../imgs/icon/empty.png", half_star_img: "../../../imgs/icon/half.png", imgServer }, tapTodetail: function(e) { let { id, product, link } = e.currentTarget.dataset; console.log(e.currentTarget) if (product){ wx.navigateTo({ url: `../../../pages/wv_page/index?link=${escape(link)}&id=${id}`, success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) } else{ wx.navigateTo({ url: `../../zl_detail/index?id=${id}`, success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) } }, fix_starImg: function (points) { let strPoints = String(Number(points).toFixed(2)); let show_Arr = []; let ten = strPoints.split('.')[0] || 0; let unit = strPoints.split('.')[1] || 0; let surPlus = 0; if (strPoints < 0) { return } if (ten) { for (let i = 0; i < Number(ten); i++) { show_Arr.push({ 'img': this.data.full_star_img }) } surPlus = 5 - Number(ten); } if (unit && surPlus > 0) { let numUnit = Number(unit.substr(0, 1)) || 0 if (numUnit > 0) { // let fix_unit = Math.round(numUnit); // switch (true) { // case numUnit > 5: // show_Arr.push({ // 'img': this.data.half_star_img // }) // break; // case numUnit <= 5: // show_Arr.push({ // 'img': this.data.half_star_img // }) // break; // default: // break // } show_Arr.push({ 'img': this.data.half_star_img }) } else if (numUnit == 0) { show_Arr.push({ 'img': this.data.empty_star_img }) } else { return } } if (surPlus > 0) { for (let i = 0; i < surPlus - 1; i++) { show_Arr.push({ 'img': this.data.empty_star_img }) } } return show_Arr }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { this.setData({ serverName, noExhibitionImg, defaultImg, noCollectionImg }) this.getComment(1) }, onPullDownRefresh: function() { this.setData({ myComment: [], }); this.getComment(1) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, loadMore: function() { if (!this.data.lastPage) { console.log(this.data.currentPage + 1) this.getComment(this.data.currentPage + 1); } else { return; } }, onReachBottom: function() { if (!this.data.loading) { this.loadMore(); console.log('reach Bottom'); } }, getComment: function(page) { let loginSessionKey = wx.getStorageSync("token") || ""; request["getComments"]({ loginSessionKey, pageNumber: page }, "", res => { if (res.data.code > -1) { let tempContent = this.data.myComment ? this.data.myComment : []; let { last: lastPage, totalPages, content: myComment } = res.data.data; if (myComment) { for (let i = 0; i < myComment.length; i++) { let comments_star = this.fix_starImg(myComment[i].exhibition.score || '0.0') myComment[i]['imgObj'] = comments_star } } console.log('myComment', myComment) this.setData({ currentPage: res.data.data.number + 1, lastPage, loading: false, myComment: tempContent.concat(myComment), }); console.log(myComment) wx.stopPullDownRefresh(); } }, err => { }, complete => { }) }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { } })