<template>
|
<view :data-theme='theme()' :class="theme() || ''">
|
<chose-city :citydata="citydata" :myCityObj="citySupplierRes" :nowCityObj="locationCityObj" @selectCity="selectCity" @selectCityByLatLng="selectCityByLatLng" v-if="showCity && citydata.cityList.length>0" @closeModal="closeModal"></chose-city>
|
</view>
|
</template>
|
|
<script>
|
import choseCity from "@/pages2/components/chose-city/chose-city";
|
export default {
|
components: {
|
choseCity
|
},
|
data() {
|
return {
|
showCity:true, // 默弹窗显示
|
citySupplierRes: {}, // 当前 选择的城市
|
locationCityObj: {}, // 自动定位的城市
|
citydata:[],
|
};
|
},
|
onLoad() {
|
if(uni.getStorageSync('citySupplierRes')){
|
this.citySupplierRes = uni.getStorageSync('citySupplierRes');
|
uni.setStorageSync('realCityObj', this.citySupplierRes);
|
// this.locationCityObj = uni.getStorageSync('locationCityObj');
|
}
|
this.getData();
|
},
|
methods: {
|
selectCity(item) {
|
console.log('-您选择的城市-',item)
|
let self = this;
|
let city = item.name;
|
let url = 'index/getCitySupplierBycity';
|
if (item.level == 3) {
|
url = 'index/getCitySupplierByRegion';
|
}
|
self._get(url, {
|
city: city,
|
}, function(res) {
|
let pages = getCurrentPages(); //获取所有页面栈实例列表
|
let nowPage = pages[ pages.length - 1]; //当前页页面实例
|
let prevPage = pages[ pages.length - 2 ]; //上一页页面实例
|
prevPage.$vm.city_supplier_ids = res.data.supplier_ids; //修改上一页data里面的searchVal参数值为222
|
prevPage.$vm.index_cityname = res.data.city;
|
// 记录当前站点信息
|
self.citySupplierRes = res.data;
|
uni.setStorageSync('citySupplierRes', res.data);
|
uni.navigateBack({ //uni.navigateTo跳转的返回,默认1为返回上一级
|
delta: 1
|
});
|
});
|
},
|
selectCityByLatLng(item, type) {
|
var self = this;
|
self._get('index/getCitySupplier', {
|
longitude: item.longitude,
|
latitude: item.latitude
|
}, function(res) {
|
res.data.city = res.data.name;
|
res.data.level = 2;
|
self.locationCityObj = res.data;
|
console.log(type);
|
// 记录定位的站点信息 by lyzflash
|
// uni.setStorageSync('locationCityObj', res.data);
|
// 记录定位的时间 by lyzflash
|
// uni.setStorageSync('city_expiration', expiration);
|
// 记录当前站点信息
|
if (type) {
|
self.citySupplierRes = res.data;
|
uni.setStorageSync('citySupplierRes', res.data);
|
// 获取区县信息
|
self.getRegionList(res.data.name);
|
uni.navigateBack({ //uni.navigateTo跳转的返回,默认1为返回上一级
|
delta: 1
|
});
|
}
|
})
|
},
|
getRegionList(city) {
|
// 获取区县信息
|
console.log(city);
|
let cityData = this.citydata.cityList;
|
for(let i = 0; i < cityData.length; i++) {
|
if (cityData[i].name == city) {
|
uni.setStorageSync('regionObj', cityData[i].regions);
|
break;
|
}
|
}
|
},
|
closeModal() {
|
this.showCity = false;
|
uni.navigateBack({ //uni.navigateTo跳转的返回,默认1为返回上一级
|
delta: 1
|
});
|
},
|
goback() {
|
uni.navigateBack();
|
},
|
/*获取数据*/
|
getData() {
|
let self = this;
|
self.isloadding = true;
|
self._get('index/getCityList', {
|
|
}, function(res) {
|
res.data.cityList = Object.values(res.data.cityList);
|
res.data.alphabet = Object.values(res.data.alphabet);
|
self.citydata = res.data;
|
self.getRegionList(self.citySupplierRes.name);
|
});
|
},
|
}
|
}
|
</script>
|
|
<style>
|
@import '/pages2/common/main.css';
|
@import '/pages2/common/icon.css';
|
page{
|
background: #fff;
|
}
|
.cu-btn{
|
width: 92%;
|
border-radius: 10rpx;
|
}
|
.cu-btn[class*="line"]::after{
|
border: 1rpx solid #aaaaaa;
|
}
|
</style>
|