123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- <template>
- <div class="">
- <div class="header">
- <!-- <view class="back_div">
- <image class="back_img" @click="back_city()" src="../../static/img/login/logo@2x.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_citytop">
- <view class="" style="margin-bottom: 0;" @click="back_city(position)">
- {{position.cityName}}
- </view>
- <view class="dingweis_div" @click="getWarpweft">
- <text>{{po_tips}}</text>
- </view>
- </view>
- </view>
-
- </view>
- <!-- 最近模块 -->
- <view class="dingwei vist-list" v-if="Visit.length>=0">
- <view class="dingwei_Tips">
- 访问记录
- </view>
- <view class="dingwei_city dingwei_city_zuijin">
- <view class="dingwei_city_one toright" v-for="(item,index) in Visit" @click="back_city(item)">
- {{item.cityName}}
- </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';
- export default {
- components: {},
- props: {},
- computed: {
- hotCity() {
- return Citys.hotCity;
- },
- citys() {
- return Citys.cities;
- }
- },
- data() {
- return {
- // statusBarHeight: this.statusBarHeight,
- statusBarHeight: 45,
- ImgUrl: this.ImgUrl,
- letter: [],
- selectLetter: '',
- searchValue: '',
- scrollIntoId: '',
- list: [],
- tId: null,
- searchList: [],
- showMask: false,
- disdingwei: true,
- Visit: [], //最近访问
- position: '',
- longitude: '', //经度
- latitude: '', //纬度
- seconds: 3,
- po_tips: '重新定位',
- positionObj:{}
- }
- },
- created() {
- //获取存储的最近访问
- var that = this
- let _k = false
- uni.getStorage({
- key: 'Visit_key',
- success: function(res) {
- that.Visit = res.data
- _k = true
- }
- });
- if(!_k){
- that.Visit = [{
- cityName:'全国'
- }]
- }
- //获取定位 经度纬度
- 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: {
- 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) {
- 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.target.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) {
- this.positionObj.positionName = item
- this.$emit('back_city', this.positionObj);
- //unshift 把数据插入到首位,与push相反
- if(item){
- 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');
- }
- },
- getWarpweft() {
- var that = this
- that.po_tips = '定位中...'
- let countdown = setInterval(() => {
- that.seconds--;
- uni.getLocation({
- type: 'gcj02',
- geocode: true,
- success: function(res) {
- // console.log('当前位置的经度:' + res.longitude);
- // console.log('当前位置的纬度:' + res.latitude);
- // console.log(res)
- that.positionObj = res;
- that.longitude = res.longitude
- that.latitude = res.latitude
- //#ifdef APP-PLUS
- that.position ={cityName:res.address.city}
- //#endif
- }
- });
- 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: 0upx;
- top: 83upx;
- left: 0upx;
- right: 0upx;
- width: 750upx;
- display: flex;
- justify-content: center;
- align-items: center;
- background: rgba(0, 0, 0, 0);
- }
- .mask-r {
- height: 120upx;
- width: 120upx;
- border-radius: 60upx;
- display: flex;
- background:#22C572;
- justify-content: center;
- align-items: center;
- font-size: 40upx;
- color: #FFFFFF
- }
- .content {
- height: 100%;
- width: 100%;
- /* background-color: #ffffff; */
- }
- .header {
- height: 85upx;
- display: flex;
- justify-content: center;
- align-items: center;
- background: white;
- }
- .back_div {
- width: 65upx;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .back_img {
- width: 35upx;
- height: 35upx;
- }
- .input {
- font-size: 28upx;
- width: 90%;
- height: 55upx;
- border-radius: 40upx;
- background-color: #F5F5F5;
- padding-left: 20upx;
- padding-right: 20upx;
- box-sizing: border-box;
- }
- .title {
- font-size: 30upx;
- 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: 30upx;
- color: white;
- }
- .calendar-list {
- position: absolute;
- top: 83upx;
- bottom: 0upx;
- width: 100%;
- /* background-color: #FFFFFF; */
- }
- .letters {
- position: absolute;
- right: 30upx;
- bottom: 0px;
- width: 50upx;
- top: 260upx;
- color: #333333;
- text-align: center;
- font-size: 24upx;
- }
- .letters-item {
- margin-bottom: 5upx;
- }
- .letter-header {
- height: 45upx;
- font-size: 22upx;
- color: #333333;
- padding-left: 24upx;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- background-color: #ebedef;
- }
- .city-div {
- width: 660upx;
- height: 85upx;
- margin-left: 24upx;
- border-bottom-width: 0.5upx;
- border-bottom-color: #ebedef;
- border-bottom-style: solid;
- display: flex;
- align-items: center;
- margin-right: 35upx;
- }
- .city {
- font-size: 28upx;
- color: #000000;
- padding-left: 30upx;
- }
- .dingwei {
- width: 100%;
- padding-top: 25upx;
- box-sizing: border-box;
- /* margin-bottom: 26upx; */
- background: reds;
- padding-bottom: 20rpx;
- }
- .dingwei_Tips {
- margin-left: 24upx;
- margin-bottom: 24upx;
- font-size: 24upx;
- color: #A5A5A5;
- }
- .dingwei_city {
- width: 100%;
- /* height: 60upx; */
- /* padding-left: 55upx;
- padding-right: 70upx; */
- /* box-sizing: border-box;
- display: flex;
- justify-content: space-between; */
- /* width: 25%; */
- padding-left: 20rpx;
- display: inline-block;
- }
- .dingwei_city_one {
-
- display: inline-block;
- text-align: center;
- line-height: 60rpx;
- width: 25%;
- height: 60rpx;
- background: #F5F6F9;
- border-radius: 40rpx;
- font-size: 24rpx;
- color: #333333;
- margin-bottom: 20rpx;
-
- }
- .dingweis_div {
- display: inline-block;
- font-size: 24upx;
- color: #22C572;
- font-weight: 400;
-
- }
- .dingweis {
- width: 32upx;
- height: 32upx;
- }
- .dingwei_city_zuijin {
- /* display: flex;
- justify-content: flex-start; */
- }
- .toright {
- margin-right: 30upx;
- }
- .dingwei_citytop{
- /* background: red; */
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 30rpx;
- }
- #hot{
- background:white;
- font-size: 28rpx;
- padding-bottom: 1rpx;
- border-radius: 0 0 30rpx 30rpx;
- }
- .vist-list{
- background: white;
- margin-top: 20rpx;
- border-radius: 30rpx 30rpx 0 0 ;
- }
- </style>
|