123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- // pages/yuezhan/search/index.js
- const { request, serverName } = require('../../../utils/services');
- const {
- newRequestFns,
- newServerName
- } = require('../../../utils/newServices.js');
- const { Toast } = require('../../../utils/util.js');
- const QQMapWX = require('../../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
- var qqmapsdk = "";
- const app = getApp();
- const WxParse = require('../../../common/component/wxParse/wxParse.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tabs: ['国内', '国际'],
- testImg: '../../../imgs/testImg/thumbSmallImg2.jpg',
- avatar: '../../../imgs/testImg/1.jpg',
- activeIndex:0,
- domesticCityList:[],
- internationalCity:[]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- qqmapsdk = new QQMapWX({
- key: '2Z3BZ-H7EWO-F4YWX-SG5JF-2VOK2-S2FUB'
- });
- this.getLocationName();
- this.getDomesticCity();
- this.setData({
- cityAction: app.globalData.city
- })
- },
- tabClick: function (e) {
- this.setData({
- loading: true,
- activeIndex: e.currentTarget.id,
- domesticCityList: [],
- internationalCity: []
- });
- if (this.data.activeIndex==0){
- this.getDomesticCity();
- }
- else{
- this.getInternationalCity();
-
- }
- },
- clickItem:function(e){
- console.log(e.currentTarget)
-
- let { name } = e.currentTarget.dataset;
- console.log(name);
- app.globalData.city = name;
- app.globalData.clickToSelect = true;
- wx.navigateBack({
- delta: 1,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- getDomesticCity:function(){
- newRequestFns["getDomesticCity"]({},"",res=>{
- if(res.data.code==0){
- let { data: domesticCityList} = res.data;
- let exhibitionNum = 0;
- //暂时改成从城市列表获取
- domesticCityList.find((item) => {
- if(item[0] == '北京'){
- exhibitionNum = item[1];
- }
- })
- this.setData({
- domesticCityList,
- exhibitionNum
- })
- }
- // console.log(domesticCityList)
- })
- },
- 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
- });
- app.globalData.city = app.globalData.city || "北京";
- this.getList(1, app.globalData.city);
- 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
- // })
- // // console.log('0202', res)
- // //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.getList(1, locationName)
- // this.setData({
- // locationName
- // })
- // },
- // fail: function (res) {
- // console.log(res)
- // // 失败时设置默认值
- // app.globalData.city = "北京";
- // app.globalData.locationName = "北京";
- // this.setData({
- // locationName:"北京"
- // })
- // },
- // complete: function (res) {
- // console.log(res);
- // }
- // });
- // }
- // })
- },
- getList: function (page, locationName) {
- let loginSessionKey = wx.getStorageSync("token");
- console.log(loginSessionKey)
- let { latitude, longitude, activeDist, activeType } = this.data;
- this.setData({
- loading: true
- })
- newRequestFns["getExhibitionListOffline"]({
- page: page,
- loginSessionKey,
- city: locationName||"",
- sort:0,
- type:0,
- lng: longitude,
- lat: latitude,
- }, '', res => {
- // let { total: exhibitionNum } = res.data.data;
- let exhibitionNum = 0;
- //暂时改成从城市列表获取
- this.data.domesticCityList.find((item) => {
- if(item[0] == '北京'){
- exhibitionNum = item[1];
- }
- })
- this.setData({
- exhibitionNum,
- loading: false,
- });
- wx.stopPullDownRefresh();
- }, err => {
- }, complete => {
- })
- },
- getInternationalCity(){
- newRequestFns["getInternationalCity"]({}, "", res => {
- if (res.data.code == 0) {
- let { data: internationalCity } = res.data;
- this.setData({
- internationalCity
- })
- }
- // console.log(res)
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // 更新选中的城市状态
- console.log(app.globalData.city, 'app.globalData.city')
- this.setData({
- cityAction: app.globalData.city
- });
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|