You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.3 KiB
166 lines
4.3 KiB
const app = getApp()
|
|
import commonApi from "../../../utils/https/common.js"
|
|
let QQMapWx = require("../../../utils/qqmap-wx-jssdk.min.js")
|
|
var qqmap;
|
|
Component({
|
|
options: {
|
|
styleIsolation: 'apply-shared',
|
|
addGlobalClass: true
|
|
},
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
tab: {
|
|
type: String,
|
|
value: "0"
|
|
},
|
|
transparent: {
|
|
type: String,
|
|
value: "0"
|
|
},
|
|
isScene: {
|
|
type: String,
|
|
value: 0
|
|
},
|
|
regionKey:{
|
|
type:String,
|
|
value:""
|
|
},
|
|
clickid:{
|
|
type:String,
|
|
value:""
|
|
},
|
|
cityclickid:{
|
|
type:String,
|
|
value:""
|
|
},
|
|
focusclickid:{
|
|
type:String,
|
|
value:""
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.statusBarHeight,
|
|
left: app.globalData.menuWidth,
|
|
top: app.globalData.statusBarTop,
|
|
keywords: '',
|
|
// cities:['南京','苏州','镇江'],
|
|
cityIndex:0,
|
|
cities:[]
|
|
},
|
|
lifetimes:{
|
|
created:function(){
|
|
// 腾讯地图接入
|
|
qqmap = new QQMapWx({
|
|
key:app.globalData.mapKey
|
|
})
|
|
const _this = this;
|
|
// 获取江苏省的市
|
|
commonApi._post("customReg/getJsCityList").then(res=>{
|
|
let cities = [],city = res.data;
|
|
for(let i=0;i<city.length;i++){
|
|
cities.push(city[i].name);
|
|
}
|
|
this.setData({
|
|
cities:cities,
|
|
city:city
|
|
})
|
|
let regionKey = app.globalData.regionKey?app.globalData.regionKey:this.properties.regionKey;
|
|
if(regionKey){
|
|
let index = city.findIndex(item=>item.regionKey==regionKey);
|
|
this.setData({
|
|
cityIndex:index
|
|
})
|
|
_this.triggerEvent("onload",{regionKey:city[index].regionKey})
|
|
return false
|
|
}
|
|
// 获取当前定位
|
|
// 获取当前地区的经纬度
|
|
wx.getLocation({
|
|
type: 'gcj02',
|
|
success: function (res) {
|
|
// 获取成功后调用腾讯sdk解析获取城市名
|
|
qqmap.reverseGeocoder({
|
|
location:res.latitude+","+res.longitude,
|
|
success:function(res){
|
|
let address = res.result.address_component;
|
|
// 如果在江苏省外则统一显示江苏 在江苏省内需要获取城市
|
|
let cityItem = address.province.indexOf("江苏")!=-1?address.city:"江苏";
|
|
// 南京的定位改成江苏的
|
|
cityItem = cityItem.indexOf("南京")!=-1?"江苏":cityItem
|
|
let index = cities.findIndex(item=>item.indexOf(cityItem)!=-1)
|
|
// 防止地区列表没有该地区 设置默认是0
|
|
index = index==-1?0:index;
|
|
_this.setData({
|
|
cityIndex:index
|
|
})
|
|
app.globalData.regionKey = cities[index].regionKey
|
|
_this.triggerEvent("onload",{regionKey:city[index].regionKey})
|
|
},
|
|
fail:function(){
|
|
_this.triggerEvent("onload",{regionKey:city[0].regionKey})
|
|
}
|
|
})
|
|
},
|
|
fail:function(){
|
|
_this.triggerEvent("onload",{regionKey:city[0].regionKey})
|
|
}
|
|
})
|
|
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
searchInput: function (e) {
|
|
this.setData({
|
|
keywords: e.detail.value
|
|
})
|
|
},
|
|
search: function () {
|
|
let keywords = this.data.keywords;
|
|
this.triggerEvent("onload",{keywords:keywords})
|
|
},
|
|
inputFocus:function(){
|
|
if(this.properties.focusclickid){
|
|
wx.uma.trackEvent(this.properties.focusclickid);
|
|
}
|
|
},
|
|
bindPickerChange:function(e){
|
|
this.setData({
|
|
cityIndex: e.detail.value
|
|
})
|
|
let regionKey = this.data.city[e.detail.value].regionKey;
|
|
app.globalData.regionKey = regionKey;
|
|
if(this.properties.cityclickid){
|
|
wx.uma.trackEvent(this.properties.cityclickid);
|
|
}
|
|
this.triggerEvent("onload",{regionKey:regionKey})
|
|
},
|
|
back: function () {
|
|
if(this.properties.clickid){
|
|
wx.uma.trackEvent(this.properties.clickid);
|
|
}
|
|
const pages = getCurrentPages();
|
|
wx.showTabBar({})
|
|
if (pages.length <= 1) {
|
|
wx.switchTab({
|
|
url: app.globalData.menuRoute
|
|
})
|
|
}
|
|
else {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|