123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import GoodApi from '../../../services/good'
- // 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() {},
- changeTag(e: WechatMiniprogram.BaseEvent<{ commenttype: string }>) {
- const { commenttype } = e.currentTarget.dataset
- this.setData({
- commentType: commenttype,
- })
- },
- })
|