123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- // pages/yuezhan/search/index.js
- const { request, serverName } = require('../../../utils/services');
- 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();
- console.log(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(){
- request["getDomesticCity"]({},"",res=>{
- if(res.data.code==0){
- let { data: domesticCityList} = res.data;
- this.setData({
- domesticCityList
- })
- }
- // console.log(domesticCityList)
- })
- },
- getLocationName:function(){
- // 调用接口
- wx.getLocation({
- type: 'wgs84',
- success: (res) => {
- 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);
- this.getList(1, 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, locationName) {
- let loginSessionKey = wx.getStorageSync("token");
- console.log(loginSessionKey)
- let { latitude, longitude, activeDist, activeType } = this.data;
- this.setData({
- loading: true
- })
- request["getExhibitionListOffline"]({
- page: page,
- loginSessionKey,
- city: locationName||"",
- sort:0,
- type:0,
- lng: longitude,
- lat: latitude,
- }, '', res => {
- let { totalElements: exhibitionNum } = res.data.data;
- console.log(res)
- this.setData({
- exhibitionNum,
- loading: false,
- });
- wx.stopPullDownRefresh();
- }, err => {
- }, complete => {
- })
- },
- getInternationalCity(){
- request["getInternationalCity"]({}, "", res => {
- if (res.data.code == 0) {
- let { data: internationalCity } = res.data;
- this.setData({
- internationalCity
- })
- }
- // console.log(res)
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|