//index.js const { request, serverName, imgServer } = require('../../utils/services'); 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) { console.log(this.data.currentPage + 1) this.getList(this.data.currentPage + 1); } else { return; } }, onReachBottom: function () { if (!this.data.loading) { this.loadMore(); console.log('reach Bottom'); } }, onShareAppMessage: function () { }, onShow: function () { let { collectedArr, collectedChange } = app.globalData; let { exhibitionList } = this.data // this.setData({ // exhibitionList: [] // }); // this.getBanner(); // this.getList(1); console.log('dwdwasda',collectedChange) 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 } } } // console.log(collectedArr.status, collectedArr.collectedId) } 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; console.log(this.data.tag) this.setData({ loading: true }) request["getExhibitionList"]({ page: page, type: type }, '', res => { let tempContent = this.data.exhibitionList ? this.data.exhibitionList : []; let { last: lastPage, totalPages, content: exhibitionList } = res.data.data; let { openTime } = exhibitionList; exhibitionList.forEach((currentValue) => { currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : ''; }) console.log(res) this.setData({ currentPage: res.data.data.number + 1, lastPage, loading: false, exhibitionList: tempContent.concat(exhibitionList), }); console.log(exhibitionList) wx.stopPullDownRefresh(); // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that) }, err => { }, complete => { }) }, addLike: function (e) { let { type, id, idx } = e.currentTarget.dataset; console.log(idx, type, id) let likes = this.data.likes; likes[id] = !likes[id]; let exhibitionList = this.data.exhibitionList; let { collectedArr, collectedChange } = app.globalData, hasItem = true; console.log('type', type) this.setData({ likes: likes }) Toast.showToast2('loading'); let loginSessionKey = wx.getStorageSync('token') || ""; // if (loginSessionKey){ request['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) { console.log("true") 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(); }) // } console.log(this.data.exhibitionList) }, to_search: function () { wx.navigateTo({ url: './search/index', success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) }, to_pay: function (e) { console.log(e) let url = e.currentTarget.dataset.url wx.navigateTo({ url: `../wv_page/index?url=${url}`, success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) } })