//index.js //获取应用实例 const { request, serverName } = require('../../utils/services'); const { Toast } = require('../../utils/util.js'); const { defaultImg, noExhibitionImg } = require('../../utils/images'); const WxParse = require('../../common/component/wxParse/wxParse.js'); const QQMapWX = require('../../common/component/mapSDK/qqmap-wx-jssdk.min.js'); var qqmapsdk = ""; const app = getApp(); Page({ data: { navItem: [{ title: '', tag: 5 }, { title: '附近', tag: "" }, { title: '热门', tag: 0 }, { title: '展览中', tag: 4 }, { title: '即将开始', tag: 2 }, { title: '已结束', tag: 6 }], indicatorDots: true, autoplay: true, interval: 5000, duration: 1000, activeIndex: 0, locationName: "珠海", animationData: {}, isLike: false, showConfirm: false, tag: "", exhibitionList: [], commodityImgs: [ '../../imgs/testImg/thumbSmallImg.jpg', '../../imgs/testImg/thumbSmallImg.jpg', ], type: 5, testImg: '../../imgs/testImg/fdkz.png', getLocationBtn: false }, to_search_exhibition: function () { wx.navigateTo({ url: '../yuezhan/search/index', success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) }, onLoad: function () { this.getList(1) qqmapsdk = new QQMapWX({ key: '2Z3BZ-H7EWO-F4YWX-SG5JF-2VOK2-S2FUB' }); this.getLocationName(); var animation = wx.createAnimation({ duration: 400, timingFunction: 'ease-in-out', }) this.animation = animation animation.scale(1.5, 1.5).step(); animation.scale(1, 1).step(); this.setData({ serverName, animationData: animation.export(), noExhibitionImg, defaultImg }) }, onShareAppMessage: function () { }, onShow: function () { let { city, clickToSelect, collectedArr, collectedChange } = app.globalData; let { activeIndex, exhibitionList } = this.data if (clickToSelect){ // console.log(city) this.setData({ locationName: city || "珠海", exhibitionList: [], activeIndex:0, type: 5 }); if (activeIndex == 1) { this.getNearByList(1); } else { 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 } } } // console.log(collectedArr.status, collectedArr.collectedId) } this.setData({ exhibitionList }) } app.globalData.clickToSelect = false; // app.globalData.collectedChange = false; }, addLike: function (e) { let { type, id, idx } = e.currentTarget.dataset; console.log(idx, type, id) let exhibitionList = this.data.exhibitionList; let { collectedArr, collectedChange } = app.globalData, hasItem = true; console.log('type', type) 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) }, getLocationName: function () { // 调用接口 wx.getLocation({ type: 'wgs84', success: (res) => { this.setData({ latitude: res.latitude, longitude: res.longitude }) //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析 qqmapsdk.reverseGeocoder({ location: { latitude: res.latitude, longitude: res.longitude }, success: (res) => { let { city: locationName } = res.result.address_component; locationName = locationName.substring(0, 2); console.log(locationName); app.globalData.city = locationName; this.setData({ locationName }) }, fail: function (res) { console.log(res) this.setData({ locationName: "" }) }, complete: function (res) { console.log(res); } }); } }) }, getList: function (page) { let { type, locationName } = this.data; let loginSessionKey = wx.getStorageSync("token"); console.log(loginSessionKey) console.log(type, locationName); this.setData({ loading: true }) request["getExhibitionList"]({ page: page, type: type, loginSessionKey, city: locationName }, '', res => { let tempContent = this.data.exhibitionList ? this.data.exhibitionList : []; let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data; let { openTime } = exhibitionList; 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 => { }) }, getNearByList: function (page) { let { type, locationName, latitude, longitude } = this.data; let loginSessionKey = wx.getStorageSync("token"); wx.getSetting({ success:res=>{ if (!res.authSetting['scope.userLocation']) { Toast.showToast('tip', "无法获取用户位置", () => { return; }) this.setData({ getLocationBtn: true }) } else { this.setData({ loading: true, getLocationBtn: false }) if(!longitude&&!latitude){ wx.getLocation({ success: res => { let longitude = (this.longitude = res.longitude); let latitude = (this.latitude = res.latitude); console.log("dqwdwd6w5d465ad4w") request["getNearByList"]({ page: page, loginSessionKey, city: locationName, lng: longitude, lat: latitude }, '', res => { let tempContent = this.data.exhibitionList ? this.data.exhibitionList : []; let { last: lastPage, totalPages, content: exhibitionList } = res.data.data; let { openTime } = exhibitionList; console.log(res) this.setData({ currentPage: res.data.data.number + 1, lastPage, loading: false, longitude, latitude, exhibitionList: tempContent.concat(exhibitionList), }); console.log(exhibitionList) wx.stopPullDownRefresh(); // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that) }, err => { }, complete => { }) }, }) }else{ request["getNearByList"]({ page: page, loginSessionKey, city: locationName, lng: longitude, lat: latitude }, '', res => { let tempContent = this.data.exhibitionList ? this.data.exhibitionList : []; let { last: lastPage, totalPages, content: exhibitionList } = res.data.data; let { openTime } = exhibitionList; 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 => { }) } } } }) }, closeDialog: function () { this.setData({ showConfirm: false }) }, loadMore: function () { let { activeIndex } = this.data if (!this.data.lastPage) { console.log(this.data.currentPage + 1) if (activeIndex == 1) { this.getNearByList(this.data.currentPage + 1); } else { this.getList(this.data.currentPage + 1); } } else { return; } }, onReachBottom: function () { if (!this.data.loading) { this.loadMore(); console.log('reach Bottom'); } }, tabClick: function (e) { // console.log(e.currentTarget.dataset) this.setData({ exhibitionList: [], activeIndex: e.currentTarget.id, type: e.currentTarget.dataset.tag, currentPage: 1 }); if (e.currentTarget.id == 1) { this.getNearByList(1); } else { this.getList(1); } }, to_search: function () { wx.navigateTo({ url: './search/index', success: function (res) { }, fail: function (res) { }, complete: function (res) { }, }) } })