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.
 
 
 

512 lines
11 KiB

<template>
<div class="wrapper" :style="'top:'+statusBarHeight+'px'">
<div class="header">
<!-- <view class="back_div">
<image class="back_img" @click="back_city()" src="@/static/images/back_img.png" mode=""></image>
</view> -->
<input class="input" @input="onInput" placeholder="搜索 中文/拼音/首字母" v-model="searchValue" />
</div>
<scroll-view class="calendar-list" scroll-y="true" :scroll-into-view="scrollIntoId">
<view v-if="disdingwei" id="hot">
<!-- 定位模块 -->
<view class="dingwei">
<view class="dingwei_Tips">
当前定位
</view>
<view class="dingwei_city">
<view class="dingwei_city_one" @click="back_city(currentCity)">
{{currentCity.cityName}}
</view>
<view class="dingweis_div" @click="getWarpweft">
<image class="dingweis" src="@/static/images/dingweis.png" mode=""></image>
<text>{{po_tips}}</text>
</view>
</view>
</view>
<!-- 最近模块 -->
<view class="dingwei">
<view class="dingwei_Tips">
热门城市
</view>
<view class="dingwei_city dingwei_city_zuijin">
<view class="dingwei_city_one toright" v-for="(item,index) in hotCity" @click="back_city(item)">
{{item.cityName}}
</view>
</view>
</view>
</view>
<!-- 城市列表 -->
<view v-if="searchValue == ''" v-for="(item, index) in list" :id="getId(index)" :key="index">
<view class="letter-header">{{ getId(index) }}</view>
<view class="city-div" v-for="(city, i) in item" :key="i" @click="back_city(city)">
<text class="city">{{ city.cityName }}</text>
</view>
</view>
<!-- 搜索结果 -->
<view class="city-div" v-for="(item, index) in searchList" @click="back_city(item)">
<text class="city">{{ item.cityName }}</text>
</view>
</scroll-view>
<!-- 右侧字母 -->
<view class="letters" v-if="searchValue == ''">
<view class="letters-item" @click="scrollTo('hot')">最近</view>
<view class="letters-item" v-for="item in letter" :key="item" @click="scrollTo(item)">{{ item }}</view>
</view>
<!-- 选中之后字母 -->
<view class="mask" v-if="showMask">
<view class="mask-r">{{selectLetter}}</view>
</view>
</div>
</template>
<script>
import Citys from './city.js';
import allCity from './allCity.js'
import HotCity from './HotCity.js'
import carStore from '@/store/modules/car.js'
let usecarStore = carStore()
import {
jsonp
} from 'vue-jsonp'
export default {
data() {
return {
statusBarHeight: this.statusBarHeight,
ImgUrl: this.ImgUrl,
letter: [],
selectLetter: '',
searchValue: '',
scrollIntoId: '',
list: [],
tId: null,
searchList: [],
showMask: false,
disdingwei: true,
Visit: [], //最近访问
currentCity: ' ',
longitude: '', //经度
latitude: '', //纬度
seconds: 3,
po_tips: '重新定位',
citys: [],
hotCity: HotCity
}
},
created() {
console.log(usecarStore)
//获取存储的最近访问
this.initcity()
var that = this
uni.getStorage({
key: 'Visit_key',
success: function(res) {
that.Visit = res.data
}
});
//获取定位 经度纬度
that.getWarpweft()
//获取city.js 的程序字母
var mu = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'w', 'x',
'y',
'z'
];
var tmp = [];
for (var i = 0; i < mu.length; i++) {
var item = mu[i];
for (var j = 0; j < this.citys.length; j++) {
var py = this.citys[j].py;
if (py.substring(0, 1) == item) {
if (tmp.indexOf(item) == -1) {
this.list[i] = [this.citys[j]];
tmp.push(item);
this.letter.push(item.toUpperCase());
} else {
this.list[i].push(this.citys[j]);
}
}
}
}
},
methods: {
initcity() {
let cityArr = allCity.map(arr => {
return arr.cityInfoList.map(item => {
let obj = {
cityName: item.cityName,
pinYin: item.cityPinyin,
py: item.cityAcronym.toLocaleLowerCase(),
code: item.cityCode,
cityInitial: item.cityInitial
}
return obj
})
})
this.citys = cityArr.flat()
console.log(this.citys)
},
getId(index) {
return this.letter[index];
},
scrollTo(letter) {
this.showMask = true
this.selectLetter = letter == 'hot' ? '最' : letter
setTimeout(() => {
this.showMask = false
}, 300);
this.scrollIntoId = letter;
},
query(source, text) {
console.log(source, text)
let res = [];
var self = this;
res = source.filter(item => {
const arr = [];
let isHave = false;
Object.keys(item).forEach(prop => {
const itemStr = item[prop];
self.isString(itemStr) &&
itemStr.split(',').forEach(val => {
arr.push(val);
});
});
arr.some(val => {
isHave = new RegExp('^' + text).test(val);
return isHave;
});
return isHave;
});
console.log(JSON.stringify(res));
return res;
},
isString(obj) {
return typeof obj === 'string';
},
onInput(e) {
const value = e.detail.value;
console.log(value);
if (value !== '' && this.citys && this.citys.length > 0) {
const queryData = this.query(this.citys, String(value).trim());
this.searchList = queryData;
this.disdingwei = false
} else {
this.searchList = [];
this.disdingwei = true
}
},
back_city(item) {
if (item) {
console.log(item)
usecarStore.setCar('city', item.code)
usecarStore.setCar('cityName', item.cityName)
uni.navigateBack()
return
this.$emit('back_city', item);
//unshift 把数据插入到首位,与push相反
this.Visit.unshift(item)
this.searchValue = "";
this.disdingwei = true
var arr = this.Visit
//数组去重
function distinct(arr) {
let newArr = []
for (let i = 0; i < arr.length; i++) {
if (newArr.indexOf(arr[i]) < 0) {
newArr.push(arr[i])
}
}
return newArr
}
this.Visit = distinct(arr)
console.log(this.Visit, "---最近访问")
uni.setStorage({
key: 'Visit_key',
data: this.Visit
});
} else {
this.$emit('back_city', 'no');
}
},
// IDZBZ-L5GCZ-EQXXA-ZR5K4-JTSXH-IQBLO
getWarpweft() {
var that = this
that.po_tips = '定位中...'
// let key = 'NRWBZ-TKRWV-CSAPH-5PFDS-J4HT6-IWF4O'
let key = 'IDZBZ-L5GCZ-EQXXA-ZR5K4-JTSXH-IQBLO'
let countdown = setInterval(() => {
that.seconds--;
uni.getLocation({
type: 'wgs84',
success: function(res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
that.longitude = res.longitude
that.latitude = res.latitude
let url = 'https://apis.map.qq.com/ws/geocoder/v1/'
jsonp(url, {
key: key,
location: res.latitude + ',' + res.longitude,
output: 'jsonp'
}).then(res => {
console.log('jsonp', res.result.address_component);
let {
province,
city,
district
} = res.result.address_component;
that.province = province;
that.city = city;
that.area = district;
console.log(province, city, district);
that.currentCity = that.citys.find(item=>item.cityName==city)
if(!that.currentCity) {
uni.$u.toast('获取定位失败,请手动选择城市')
}
console.log(that.currentCity, '当前城市')
}).catch(()=>{
uni.$u.toast('获取定位失败,请手动选择城市')
})
},
fail() {
uni.$u.toast('获取定位失败,请手动选择城市')
}
})
if (that.seconds <= 0) {
that.seconds = 3
that.po_tips = '重新定位'
clearInterval(countdown);
}
},
1000);
}
}
};
</script>
<style scoped>
.wrapper {
/* position: fixed;
z-index: 999999;
background: #ffffff;
height: 100%;
width: 100%;
top: 0px;
left: 0px; */
}
.mask {
position: absolute;
bottom: 0rpx;
top: 83rpx;
left: 0rpx;
right: 0rpx;
width: 750rpx;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0);
}
.mask-r {
height: 120rpx;
width: 120rpx;
border-radius: 60rpx;
display: flex;
background: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
font-size: 40rpx;
color: #FFFFFF
}
.content {
height: 100%;
width: 100%;
background-color: #ffffff;
}
.header {
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
}
.back_div {
width: 65rpx;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.back_img {
width: 35rpx;
height: 35rpx;
}
.input {
font-size: 28rpx;
width: 620rpx;
height: 70rpx;
border-radius: 40rpx;
background-color: #F5F5F5;
padding-left: 20rpx;
padding-right: 20rpx;
box-sizing: border-box;
}
.title {
font-size: 30rpx;
color: white;
}
.show {
left: 0;
width: 100%;
transition: left 0.3s ease;
}
.hide {
left: 100%;
width: 100%;
transition: left 0.3s ease;
}
.title {
font-size: 30rpx;
color: white;
}
.calendar-list {
position: absolute;
top: 83rpx;
bottom: 0rpx;
width: 100%;
background-color: #FFFFFF;
}
.letters {
position: absolute;
right: 30rpx;
bottom: 0px;
width: 50rpx;
top: 260rpx;
color: #2f9bfe;
text-align: center;
font-size: 24rpx;
}
.letters-item {
margin-bottom: 5rpx;
}
.letter-header {
height: 45rpx;
font-size: 22rpx;
color: #333333;
padding-left: 24rpx;
box-sizing: border-box;
display: flex;
align-items: center;
background-color: #ebedef;
}
.city-div {
width: 660rpx;
height: 85rpx;
margin-left: 24rpx;
border-bottom-width: 0.5rpx;
border-bottom-color: #ebedef;
border-bottom-style: solid;
display: flex;
align-items: center;
margin-right: 35rpx;
}
.city {
font-size: 28rpx;
color: #000000;
padding-left: 30rpx;
}
.dingwei {
width: 100%;
padding-top: 25rpx;
box-sizing: border-box;
margin-bottom: 26rpx;
}
.dingwei_Tips {
margin-left: 24rpx;
margin-bottom: 24rpx;
font-size: 24rpx;
color: #A5A5A5;
}
.dingwei_city {
width: 100%;
height: 60rpx;
padding-left: 55rpx;
padding-right: 70rpx;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.dingwei_city_one {
width: 185rpx;
height: 60rpx;
background-color: #F5F5F5;
border-radius: 10rpx;
font-size: 32rpx;
color: #333333;
display: flex;
justify-content: center;
align-items: center;
}
.dingweis_div {
display: flex;
align-content: flex-end;
align-items: center;
font-size: 24rpx;
color: #FD5745;
}
.dingweis {
width: 32rpx;
height: 32rpx;
}
.dingwei_city_zuijin {
display: flex;
justify-content: flex-start;
}
.toright {
margin-right: 25rpx;
}
</style>