123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- //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 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 } = 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)
- },
- showDrop: function (e) {
- let tag = e.target.dataset.id
- console.log(e)
- let name = e.target.dataset.test
- console.log(tag)
- 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 () {
- // 调用接口
- 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,
- locationNameDesp: locationName
- })
- this.getList(1)
- },
- fail: function (res) {
- console.log(res)
- this.setData({
- locationName: ""
- })
- },
- complete: function (res) {
- console.log(res);
- }
- });
- }
- })
- },
- 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
- console.log(sort, type)
- console.log(page)
- console.log(type, locationName, latitude, longitude);
- console.log(locationNameDesp)
- this.setData({
- loading: true
- })
- request["getExhibitionListOffline"]({
- page: page,
- type: type,
- loginSessionKey,
- city: locationName,
- sort,
- type,
- lng: longitude,
- lat: latitude
- }, '', res => {
- let tempContent = this.data.exhibitionList
- ? this.data.exhibitionList
- : [];
- let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data;
- exhibitionList.forEach((currentValue) => {
- currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
- })
- let { openTime } = exhibitionList;
- this.setData({
- currentPage: res.data.data.number + 1,
- lastPage,
- loading: false,
- exhibitionList: tempContent.concat(exhibitionList),
- exhiNum: totalElements
- });
- console.log(this.data.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);
- 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();
- }, 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);
- }
- },
- onIsclose: function (e) {
- this.setData({
- isShow: e.detail
- })
- },
- getActiveItem:function(e){
- console.log(e)
- let { activeDist, activeType} = e.detail
-
- this.setData({
- activeDist,
- activeType,
- exhibitionList:[]
- })
- this.getList(1)
- },
- to_search: function () {
- wx.navigateTo({
- url: './search/index',
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- }
- })
|