123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781 |
- //index.js
- //获取应用实例
- const { request, serverName,imgServer } = require('../../utils/services');
- const { Toast, qqmapsdk } = require('../../utils/util.js');
- const { defaultImg, noExhibitionImg } = require('../../utils/images');
- const WxParse = require('../../common/component/wxParse/wxParse.js');
- const {
- newRequestFns,
- newServerName
- } = require('../../utils/newServices.js');
- // const QQMapWX = require('../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
- const app = getApp();
- const distItems = [
- {
- name: '按距离排序',
- id: '距离排序',
- idx: 1
- },
- {
- name: '按热度排序',
- id: '热度排序',
- idx: 2
- }
- ]
- const typeItems = [
- {
- name: '展览中',
- id: '展览中',
- idx: 1
- },
- {
- name: '即将开始',
- id: '即将开始',
- idx: 2
- },
- {
- name: '已结束',
- id: '已结束',
- idx: 3
- },
- {
- name: '全部状态',
- id: '全部状态',
- idx: 0
- }
- ]
- Page({
- data: {
- navItem: distItems,
- indicatorDots: true,
- autoplay: true,
- interval: 5000,
- duration: 1000,
- activeIndex: 0,
- locationName: "北京",
- locationNameDesp:"",
- isLike: false,
- showConfirm: false,
- tag: "",
- exhibitionList: [],
- commodityImgs: [
- '../../imgs/testImg/thumbSmallImg.jpg',
- '../../imgs/testImg/thumbSmallImg.jpg',
- ],
- type: 5,
- testImg: '../../imgs/testImg/fdkz.png',
- getLocationBtn: false,
- isShow: false,
- exhiNum:0,
- activeDist:'距离排序',
- activeType:'展览中'
- },
- to_search_exhibition: function () {
- wx.navigateTo({
- url: '../yuezhan/search/index',
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- },
- onLoad: function () {
-
- this.getLocationName();
- // this.getList(1)
- this.setData({
- serverName,
- noExhibitionImg,
- defaultImg,
- imgServer
- });
- },
- onShareAppMessage: function () {
- },
- onShow: function () {
- let { city, clickToSelect, collectedArr, collectedChange, latitude, longitude, locationName } = app.globalData;
- let { activeIndex, exhibitionList } = this.data
- if (clickToSelect) {
- // 使用 globalData 中的位置信息
- let finalLocationName = locationName || city || "北京";
-
- this.setData({
- locationName: finalLocationName,
- exhibitionList: [],
- activeIndex: 0,
- type: 5
- });
-
- // 如果有完整的位置信息,也设置坐标
- if (latitude && longitude) {
- this.setData({
- latitude: latitude,
- longitude: longitude
- });
- }
-
- // 确保 city 与 locationName 一致
- if (finalLocationName && finalLocationName !== "北京") {
- app.globalData.city = finalLocationName;
- } else {
- app.globalData.city = "北京";
- }
- 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
- }
- }
- }
- }
- this.setData({
- exhibitionList
- })
- }
- app.globalData.clickToSelect = false;
- // app.globalData.collectedChange = false;
- },
- addLike: function (e) {
- let { type, id, idx } = e.currentTarget.dataset;
- let exhibitionList = this.data.exhibitionList;
- let { collectedArr, collectedChange } = app.globalData, hasItem = true;
- 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();
- })
- // }
- },
- showDrop: function (e) {
- let tag = e.target.dataset.id
- let name = e.target.dataset.test
- if (tag==='type'){
- this.setData({
- navItem: {
- type: tag,
- name: name,
- arr: typeItems
- },
- isShow: !this.data.isShow
- })
- }
- else{
- this.setData({
- navItem: {
- type: tag,
- name: name,
- arr: distItems
- },
- isShow: !this.data.isShow
- })
- }
- },
- getLocationName: function () {
- // 检查 globalData 是否已有位置信息
- // if (app.globalData.latitude && app.globalData.longitude && app.globalData.locationName) {
- // 使用 globalData 中的值
- this.setData({
- latitude: app.globalData.latitude,
- longitude: app.globalData.longitude,
- locationName: app.globalData.locationName,
- locationNameDesp: app.globalData.locationName
- });
- app.globalData.city = app.globalData.locationName || '北京';
- this.getList(1);
- return;
- // }
-
- // 没有完整位置信息,获取位置
- // 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
- // })
- // //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
- // qqmapsdk.reverseGeocoder({
- // location: {
- // latitude: res.latitude,
- // longitude: res.longitude
- // },
- // success: (res) => {
- // let { city: locationName } = res.result.address_component;
- // locationName = locationName.substring(0, 2);
-
- // // 保存到 globalData
- // app.globalData.city = locationName;
- // app.globalData.locationName = locationName;
- // this.setData({
- // locationName,
- // locationNameDesp: locationName
- // })
- // this.getList(1)
- // },
- // fail: function (res) {
- // // 失败时设置默认值
- // app.globalData.city = "北京";
- // app.globalData.locationName = "北京";
- // this.setData({
- // locationName: "北京"
- // })
- // },
- // complete: function (res) {
- // }
- // });
- // }
- // })
- },
- offlineRecommend: function () {
- // 检查 globalData 是否已有位置信息
- if (app.globalData.latitude && app.globalData.longitude) {
- // 使用 globalData 中的经纬度
- 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 = "北京";
- }
- }
- // 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
- // })
- // }
- // })
- // }
-
- let { latitude: lat, longitude: lng } = this.data;
- newRequestFns["offlineRecommend"]({
- lat,
- lng,
- }, "", res => {
- this.setData({
- ExhibitionPopular: res.data.data
- })
- }, err => {
- }, complete => {
- })
- },
- getList: function (page) {
- let { locationNameDesp, locationName, latitude, longitude, activeDist, activeType } = this.data;
- let loginSessionKey = wx.getStorageSync("token");
- let sort = distItems.find(item => item.id === activeDist).idx
- let type = typeItems.find(item => item.id === activeType).idx
-
- this.setData({
- loading: true
- })
- newRequestFns["getExhibitionListOffline"]({
- page: page,
- type: type,
- loginSessionKey,
- city: locationName,
- sort,
- type,
- lng: longitude,
- lat: latitude
- }, '', 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, // 标记为最后一页
- exhiNum: total || 0
- });
- wx.stopPullDownRefresh();
- if (total <= 3) {
- this.offlineRecommend();
- }
- return;
- }
- exhibitionList.forEach((currentValue) => {
- currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
- })
- // 拼接新数据
- let newExhibitionList = tempContent.concat(exhibitionList);
- this.setData({
- currentPage: page,
- lastPage: false, // 有数据时设为false
- loading: false,
- exhibitionList: newExhibitionList,
- exhiNum: total
- });
- wx.stopPullDownRefresh();
- // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
- if (total <= 3){
- this.offlineRecommend();
- }
- }, err => {
- }, complete => {
- })
- },
- getNearByList: function (page) {
- let { type, locationName, latitude, longitude } = this.data;
- let loginSessionKey = wx.getStorageSync("token");
- console.log(locationName, latitude, longitude, 999)
- 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) {
- // 检查 globalData 是否已有位置信息
- if (app.globalData.latitude && app.globalData.longitude) {
- // 使用 globalData 中的经纬度
- let longitude = app.globalData.longitude;
- let latitude = app.globalData.latitude;
-
- // 处理 city 设置
- if (app.globalData.locationName) {
- app.globalData.city = app.globalData.locationName;
- } else {
- app.globalData.city = "北京";
- }
-
- this.setData({
- longitude,
- latitude
- });
-
- newRequestFns["getNearByList"]({
- page: page,
- loginSessionKey,
- city: locationName,
- lng: longitude,
- lat: latitude
- }, '', 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;
- }
- // 拼接新数据
- 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 => {
- })
- } else {
- // 没有位置信息,获取位置
- // wx.getLocation({
- // success: res => {
- // // 保存到 globalData
- // app.globalData.latitude = res.latitude;
- // app.globalData.longitude = res.longitude;
-
- // let longitude = (this.longitude = res.longitude);
- // let latitude = (this.latitude = res.latitude);
- // newRequestFns["getNearByList"]({
- // page: page,
- // loginSessionKey,
- // city: locationName,
- // lng: longitude,
- // lat: latitude
- // }, '', 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;
- // }
- // // 拼接新数据
- // let newExhibitionList = tempContent.concat(exhibitionList);
- // this.setData({
- // currentPage: page,
- // lastPage: false, // 有数据时设为false
- // loading: false,
- // longitude,
- // latitude,
- // exhibitionList: newExhibitionList,
- // });
- // wx.stopPullDownRefresh();
- // // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
- // }, err => {
- // }, complete => {
- // })
- // },
- // })
- }
- } else {
- newRequestFns["getNearByList"]({
- page: page,
- loginSessionKey,
- city: locationName,
- lng: longitude,
- lat: latitude
- }, '', 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;
- }
- // 拼接新数据
- let newExhibitionList = tempContent.concat(exhibitionList);
- this.setData({
- currentPage: page,
- lastPage: false, // 有数据时设为false
- loading: false,
- exhibitionList: newExhibitionList,
- });
- wx.stopPullDownRefresh();
- }, err => {
- }, complete => {
- })
- }
- }
- }
- })
- },
- closeDialog: function () {
- this.setData({
- showConfirm: false
- })
- },
- loadMore: function () {
- let { activeIndex } = this.data
- if (!this.data.lastPage) {
- 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();
- }
- },
- tabClick: function (e) {
- console.log(111111)
- 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);
- }
- },
- onIsclose: function (e) {
- this.setData({
- isShow: e.detail
- })
- },
- getActiveItem:function(e){
- let { activeDist, activeType} = e.detail
-
- this.setData({
- activeDist,
- activeType,
- exhibitionList:[]
- })
- this.getList(1)
- },
- to_search: function () {
- // 检查 globalData 是否已有位置信息
- if (app.globalData.latitude && app.globalData.longitude && app.globalData.locationName) {
- // 已有位置信息,直接跳转
- wx.navigateTo({
- url: './search/index',
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- return;
- }
- // // 没有位置信息,显示弹窗
- // wx.showModal({
- // title: '获取你的位置信息',
- // content: '将获取你的具体位置信息,用于推荐你所在定位附近的展览',
- // confirmText: '同意',
- // cancelText: '拒绝',
- // success: (res) => {
- // if (res.confirm) {
- // // 用户点击同意,获取位置信息(使用 getLocationName 的逻辑)
- // wx.getLocation({
- // type: 'wgs84',
- // success: (locationRes) => {
- // // 设置坐标到 globalData 和页面数据
- // app.globalData.latitude = locationRes.latitude;
- // app.globalData.longitude = locationRes.longitude;
- // this.setData({
- // latitude: locationRes.latitude,
- // longitude: locationRes.longitude
- // });
-
- // // 使用腾讯地图逆地址解析获取城市名称
- // qqmapsdk.reverseGeocoder({
- // location: {
- // latitude: locationRes.latitude,
- // longitude: locationRes.longitude
- // },
- // success: (geoRes) => {
- // let { city: locationName } = geoRes.result.address_component;
- // locationName = locationName.substring(0, 2);
-
- // // 保存到 globalData
- // app.globalData.city = locationName;
- // app.globalData.locationName = locationName;
-
- // this.setData({
- // locationName,
- // locationNameDesp: locationName
- // });
-
- // // 获取位置成功,跳转到搜索页面
- // wx.navigateTo({
- // url: './search/index',
- // success: function (res) { },
- // fail: function (res) { },
- // complete: function (res) { },
- // })
- // },
- // fail: (geoErr) => {
- // // 逆地址解析失败,使用默认城市(北京),直接跳转
- // app.globalData.city = "北京";
- // app.globalData.locationName = "北京";
- // this.setData({
- // locationName: "北京"
- // });
- // wx.navigateTo({
- // url: './search/index',
- // success: function (res) { },
- // fail: function (res) { },
- // complete: function (res) { },
- // })
- // }
- // });
- // },
- // fail: (locationErr) => {
- // // 获取位置失败,保持默认城市(北京),直接跳转
- // console.log('获取位置失败:', locationErr);
- // app.globalData.city = "北京";
- // app.globalData.locationName = "北京";
- // this.setData({
- // getLocationBtn: true,
- // locationName: "北京"
- // });
- // wx.navigateTo({
- // url: './search/index',
- // success: function (res) { },
- // fail: function (res) { },
- // complete: function (res) { },
- // })
- // }
- // })
- // } else if (res.cancel) {
- // // 用户点击拒绝,保持默认城市(北京),直接跳转
- // app.globalData.city = "北京";
- // app.globalData.locationName = "北京";
- // wx.navigateTo({
- // url: './search/index',
- // success: function (res) { },
- // fail: function (res) { },
- // complete: function (res) { },
- // })
- // }
- // },
- // fail: function (res) {
- // // 弹窗失败,直接跳转
- // wx.navigateTo({
- // url: './search/index',
- // success: function (res) { },
- // fail: function (res) { },
- // complete: function (res) { },
- // })
- // }
- // })
- }
- })
|