//index.js const { request, serverName, imgServer } = require('../../utils/services'); const { newRequestFns, newServerName } = require('../../utils/newServices.js'); const { Toast } = require('../../utils/util.js'); const { defaultImg, noExhibitionImg } = require('../../utils/images'); const WxParse = require('../../common/component/wxParse/wxParse.js'); const app = getApp(); Page({ data: { animationData: {}, loading: false, isLike: true, imgServer, commodityImgs: [], testImg: '../../imgs/testImg/fdkz.png', currentPage: 1, exhibitionList: [], likes: {}, tag: 1 }, onLoad: function () { this.setData({ serverName, defaultImg, noExhibitionImg, }) this.getList(1); }, loadMore: function () { if (!this.data.lastPage) { this.getList(this.data.currentPage + 1); } else { return; } }, onReachBottom: function () { if (!this.data.loading) { this.loadMore(); } }, onShareAppMessage: function () { }, onShow: function () { let { collectedArr, collectedChange } = app.globalData; let { exhibitionList } = this.data // this.setData({ // exhibitionList: [] // }); // this.getBanner(); // this.getList(1); if (collectedChange) { for (let i = 0; i < exhibitionList.length; i++) { for (let j = 0; j < collectedArr.length; j++) { if (collectedArr[j].collectedId == exhibitionList[i].id) { exhibitionList[i].hasCollect = collectedArr[j].status if (exhibitionList[i].hasCollect) { exhibitionList[i].collectionsCount += 1; } else { exhibitionList[i].collectionsCount -= 1; } if (exhibitionList[i].collectionsCount < 0) { exhibitionList[i].collectionsCount = 0 } } } } this.setData({ exhibitionList }) } app.globalData.clickToSelect = false; app.globalData.collectedChange = false; }, enablePullDownRefresh: function () { this.setData({ exhibitionList: [], currentPage: 1 }); this.getList(1); this.getBanner(); }, onPullDownRefresh: function () { this.setData({ exhibitionList: [], currentPage: 1 }); this.getList(1); }, getList: function (page) { let type = this.data.tag; this.setData({ loading: true }) newRequestFns["getExhibitionList"]({ page: page, type: type }, '', res => { let tempContent = this.data.exhibitionList ? this.data.exhibitionList : []; let { pageData: exhibitionList, total } = res.data.data; // 判断是否为最后一页(返回空数组表示没有更多数据) let isLastPage = !exhibitionList || exhibitionList.length === 0; if (isLastPage) { this.setData({ loading: false, lastPage: true // 标记为最后一页 }); wx.stopPullDownRefresh(); return; } exhibitionList.forEach((currentValue) => { currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : ''; currentValue.product ? currentValue.product.imageUrl = escape(currentValue.product.imageUrl) : ''; }) // 拼接新数据 let newExhibitionList = tempContent.concat(exhibitionList); this.setData({ currentPage: page, lastPage: false, // 有数据时设为false loading: false, exhibitionList: newExhibitionList, }); wx.stopPullDownRefresh(); // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that) }, err => { }, complete => { }) }, addLike: function (e) { let { type, id, idx } = e.currentTarget.dataset; let likes = this.data.likes; likes[id] = !likes[id]; let exhibitionList = this.data.exhibitionList; let { collectedArr, collectedChange } = app.globalData, hasItem = true; this.setData({ likes: likes }) Toast.showToast2('loading'); let loginSessionKey = wx.getStorageSync('token') || ""; // if (loginSessionKey){ newRequestFns['isCollect']({ loginSessionKey, exhibitionId: id, type: Number(type), }, "post", res => { if (res.data.code > -1) { for (let i = 0; i < collectedArr.length; i++) { if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) { collectedArr[i] = { collectedId: id, status: res.data.data.hasCollect, } hasItem = false; } } if (hasItem) { collectedArr.push({ collectedId: id, status: res.data.data.hasCollect, }) } app.globalData.collectedArr = collectedArr; app.globalData.collectedChange = true; exhibitionList[idx].hasCollect = res.data.data.hasCollect this.setData({ exhibitionList: exhibitionList }) } }, err => { }, complete => { Toast.hideLoading(); }) // } }, to_search: function () { wx.navigateTo({ url: './search/index', success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) }, })