import GoodApi from '../../../services/good' import { share } from '../../../utils/http' // pages/goods/comments/index.ts Page({ /** * 页面的初始数据 */ data: { seartInput: { gid: 'HcVJnL5DAA', skipCount: 0, maxResultCount: 10, }, totalCount: 0, items: [] as any[], loadMoreStatus: 0, loading: true, commentType: '', goodCount: 0, middleCount: 0, badCount: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad() { this.load(true) }, load(rest = false) { this.setData({ loadMoreStatus: 1, }) GoodApi.GetCommentlist(this.data.seartInput).then((rsp) => { if (rsp.result) { const result = rsp.result const { items = [], totalCount = 0, goodCount = 0, badCount = 0, middleCount = 0 } = result const nowItems = rest ? items : this.data.items.concat(items) this.setData({ items: nowItems, totalCount, goodCount, badCount, middleCount, loadMoreStatus: nowItems.length === result.totalCount ? 2 : 0, loading: false, }) console.log(nowItems) } }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (!this.data.loading && this.data.loadMoreStatus === 0) { this.setData( { albumInput: { ...this.data.seartInput, skipCount: 0, }, loading: true, }, () => { wx.stopPullDownRefresh() this.load(true) }, ) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { console.log(this.data.items.length, this.data.totalCount) if (this.data.loadMoreStatus === 0 && this.data.items.length < this.data.totalCount) { this.setData( { albumInput: { ...this.data.seartInput, skipCount: this.data.seartInput.skipCount + 10, }, }, () => { this.load() }, ) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 用户点击右上角分享 */ onShareAppMessage() { let pages = getCurrentPages(); //获取所有页面栈实例列表 let nowPage = pages[pages.length - 1]; //当前页页面实例 return { title: share.title, path: `/${nowPage.route}`, imageUrl: share.imageUrl, success(res) { console.log('success(res)==', res); }, fail(res) { console.log('fail(res)==', res); } } }, changeTag(e: WechatMiniprogram.BaseEvent<{ commenttype: string }>) { const { commenttype } = e.currentTarget.dataset this.setData({ commentType: commenttype, }) }, })