// 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 () { } })