//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, closeImg } = require('../../utils/images'); const WxParse = require('../../common/component/wxParse/wxParse.js'); const app = getApp(); Page({ data: { // navItem: [{ title: '热门', tag: 0 }, { title: '即将开始', tag: 2 }, { title: '展览中', tag: 4 }, { title: '已结束', tag: 6 }], indicatorDots: true, autoplay: true, interval: 2000, duration: 1000, activeIndex: 0, animationData: {}, loading: false, isLike: true, commodityImgs: [], testImg: '../../imgs/testImg/fdkz.png', currentPage: 1, exhibitionList: [], likes: {}, tag: 0, latitude: null, longitude: null, showRecommend:false, bombList:[], // 首页弹窗 }, onLoad: function() { this.setData({ serverName, defaultImg, noExhibitionImg, imgServer, closeImg, showRecommend:true // isLogin }) // 获取首页弹窗 this.getBombList(); this.getBanner(); this.getList(1); // wx.hideTabBar() }, 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'); } }, onShow: function() { let { collectedArr, collectedChange } = app.globalData; let { exhibitionList } = this.data let isLogin = app.globalData.isLogin; this.setData({ isLogin }) 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; }, onPullDownRefresh: function() { this.setData({ exhibitionList: [], currentPage: 1 }); this.getBanner(); this.getList(1); }, hideRecommend:function(){ this.setData({ showRecommend:false }) wx.showTabBar() }, fetchData: function (page){ newRequestFns["getExhibitionList"]({ page: page, type: 0, lat: this.data.latitude, lng: this.data.longitude }, '', 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 // 标记为最后一页 }); return; } exhibitionList.forEach((currentValue) => { currentValue.distance = Math.ceil(currentValue.distance); if (currentValue.product){ currentValue.product.link = escape(currentValue.product.link); currentValue.product.imageUrl = escape(currentValue.product.imageUrl); } }) // 拼接新数据 let newExhibitionList = tempContent.concat(exhibitionList); this.setData({ currentPage: page, lastPage: false, // 有数据时设为false loading: false, exhibitionList: newExhibitionList, }); // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that) }, err => { }, complete => { wx.stopPullDownRefresh(); }) }, getList: function(page) { let type = this.data.tag; this.setData({ loading: true }) // 检查是否已有位置信息(页面数据或 globalData) if (this.data.latitude || this.data.longitude || (app.globalData.latitude && app.globalData.longitude)) { // 如果页面没有位置信息但 globalData 有,使用 globalData 的值 if (!this.data.latitude && !this.data.longitude && app.globalData.latitude && app.globalData.longitude) { this.setData({ latitude: app.globalData.latitude, longitude: app.globalData.longitude }); // 处理 city 设置 if (app.globalData.locationName) { app.globalData.city = app.globalData.locationName; } else { app.globalData.city = "北京"; } } this.fetchData(page) } // else { // wx.getLocation({ // type: 'wgs84', // success: (res) => { // // 保存到 globalData // app.globalData.latitude = res.latitude; // app.globalData.longitude = res.longitude; // this.setData({ // latitude: res.latitude, // longitude: res.longitude // }) // this.fetchData(page) // }, // fail: (res) => { // this.fetchData(page) // } // }) // } }, getBanner: function() { newRequestFns.getBannerList({}, 'get', res => { let commodityImgs = res.data.data.pageData; this.setData({ commodityImgs: commodityImgs || [] }); console.log('banner', commodityImgs) }, err => { }, complete => { wx.stopPullDownRefresh() }) }, getBombList: function() { newRequestFns.getBombList({}, 'get', res => { console.log('bomb', this.data.showRecommend) if(res.data.data.length && this.data.showRecommend) { wx.hideTabBar() } this.setData({ bombList: res.data.data || [] }) }, 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){ 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) { 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) }, tabClick: function(e) { // console.log(e.currentTarget.dataset) // if (e.currentTarget.id == 1) { // wx.switchTab({ // url: '../swkz/index', // success: function (res) { }, // fail: function (res) { }, // complete: function (res) { }, // }) // } // else { this.setData({ exhibitionList: [], activeIndex: e.currentTarget.id, tag: e.currentTarget.dataset.tag, currentPage: 1 }); this.getList(1); // } }, onShareAppMessage: function() { }, navigatorBomb: function(e) { let { url, pagetype, urltype, hasproduct, haspay, productlink, id, description, imageUrl, relayUrl } = e.currentTarget.dataset; console.log('dwdwdw', hasproduct, productlink, imageUrl) if (productlink) { wx.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(productlink)}` }); } else { wx.navigateTo({ url: `../zl_detail/index?id=${id}&imageUrl=${imageUrl}`, success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) } }, to_pay: function(e) { console.log('dwdwdw', e.currentTarget.dataset) let { url, pagetype, urltype, hasproduct, haspay, productlink, id, description, imageUrl, relayurl } = e.currentTarget.dataset; console.log(relayurl, 6666) // app.globalData.currentUrl = url // console.log('dwdwdw', app.globalData.currentUrl) // console.log('dwdwdwd',wx.getStorageSync('url')) switch (urltype) { case 0: if (productlink) { wx.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(productlink)}&relayUrl=${relayurl||''}` }); } break; case 1: switch (pagetype) { case 0: wx.navigateTo({ url: `../cg_detail/index?id=${url}&imageUrl=${imageUrl}&relayUrl=${relayurl||''}`, success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) break; case 1: // if (hasproduct) { // 需要调一下getExhibitionDetail获取足迹 wx.navigateTo({ url: `../wv_page/index?&id=${url}&relayUrl=${relayurl||''}`, success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) // } else { // wx.navigateTo({ // url: `../zl_detail/index?id=${url}`, // success: function(res) {}, // fail: function(res) {}, // complete: function(res) {}, // }) // } break; default: break; } break; case 2: app.globalData.bannerHtml = description; wx.navigateTo({ url: `./html_detail/index?id=${id}&imageUrl=${imageUrl}&relayUrl=${relayurl||''}`, success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) break; default: break; } } })