city.vue 6.1 KB
Newer Older
M
updata  
maguohua 已提交
1
<template>
M
updata  
maguohua 已提交
2 3
  	<div class="city_container">
        <head-top :head-title="cityname" go-back='true'>
M
updata  
maguohua 已提交
4 5
            <router-link to="/home" slot="changecity" class="change_city">切换城市</router-link>
        </head-top>
M
updata  
maguohua 已提交
6
        <form class="city_form" v-on:submit.prevent>
M
updata  
maguohua 已提交
7
            <div>
M
updata  
maguohua 已提交
8
                <input type="search" name="city" placeholder="输入学校、商务楼、地址" class="city_input input_style" required v-model='inputVaule'>
M
updata  
maguohua 已提交
9 10
            </div>
            <div>
J
Junv Zhao 已提交
11
                <input type="submit" name="submit" class="city_submit input_style" @click='postpois' value="提交">
M
updata  
maguohua 已提交
12 13
            </div>
        </form>
M
maguohua 已提交
14
        <header v-if="historytitle" class="pois_search_history">搜索历史</header>
M
updata  
maguohua 已提交
15 16 17 18
        <ul class="getpois_ul">
            <li v-for="(item, index) in placelist" @click='nextpage(index, item.geohash)' :key="index">
                <h4 class="pois_name ellipsis">{{item.name}}</h4>
                <p class="pois_address ellipsis">{{item.address}}</p>
J
Junv Zhao 已提交
19
            </li>
M
updata  
maguohua 已提交
20
        </ul>
M
maguohua 已提交
21
        <footer v-if="historytitle&&placelist.length" class="clear_all_history" @click="clearAll">清空所有</footer>
M
updata  
maguohua 已提交
22
        <div class="search_none_place" v-if="placeNone">很抱歉!无搜索结果</div>
M
updata  
maguohua 已提交
23
    </div>
M
updata  
maguohua 已提交
24 25 26
</template>

<script>
M
update  
maguohua 已提交
27 28
    import headTop from 'src/components/header/head'
    import {currentcity, searchplace} from 'src/service/getData'
M
maguohua 已提交
29
    import {getStore, setStore, removeStore} from 'src/config/mUtils'
M
updata  
maguohua 已提交
30

M
updata  
maguohua 已提交
31 32 33
    export default {
    	data(){
            return{
M
maguohua 已提交
34
                inputVaule:'', // 搜索地址
J
Junv Zhao 已提交
35
                cityid:'', // 当前城市id
M
maguohua 已提交
36 37 38 39 40
                cityname:'', // 当前城市名字
                placelist:[], // 搜索城市列表
                placeHistory:[], // 历史搜索记录
                historytitle: true, // 默认显示搜索历史头部,点击搜索后隐藏
                placeNone: false, // 搜索无结果,显示提示信息
M
updata  
maguohua 已提交
41 42 43
            }
        },

M
maguohua 已提交
44
        mounted(){
M
updata  
maguohua 已提交
45
            this.cityid = this.$route.params.cityid;
M
maguohua 已提交
46
            //获取当前城市名字
M
updata  
maguohua 已提交
47 48 49
            currentcity(this.cityid).then(res => {
                this.cityname = res.name;
            })
M
maguohua 已提交
50
            this.initData();
M
updata  
maguohua 已提交
51 52 53 54 55 56 57 58 59 60 61
        },

        components:{
            headTop
        },

        computed:{

        },

        methods:{
M
maguohua 已提交
62 63 64 65 66 67 68 69
            initData(){
                //获取搜索历史记录
                if (getStore('placeHistory')) {
                    this.placelist = JSON.parse(getStore('placeHistory'));
                }else{
                    this.placelist = [];
                }
            },
M
maguohua 已提交
70
            //发送搜索信息inputVaule
M
updata  
maguohua 已提交
71
            postpois(){
M
maguohua 已提交
72
                //输入值不为空时才发送信息
M
updata  
maguohua 已提交
73 74 75 76 77 78 79 80
                if (this.inputVaule) {
                    searchplace(this.cityid, this.inputVaule).then(res => {
                        this.historytitle = false;
                        this.placelist = res;
                        this.placeNone = res.length? false : true;
                    })
                }
            },
M
maguohua 已提交
81 82 83 84
            /**
             * 点击搜索结果进入下一页面时进行判断是否已经有一样的历史记录
             * 如果没有则新增,如果有则不做重复储存,判断完成后进入下一页
             */
M
updata  
maguohua 已提交
85
            nextpage(index, geohash){
M
updata  
maguohua 已提交
86
                let history = getStore('placeHistory');
M
updata  
maguohua 已提交
87
                let choosePlace = this.placelist[index];
J
Junv Zhao 已提交
88
                if (history) {
M
updata  
maguohua 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101
                    let checkrepeat = false;
                    this.placeHistory = JSON.parse(history);
                    this.placeHistory.forEach(item => {
                        if (item.geohash == geohash) {
                            checkrepeat = true;
                        }
                    })
                    if (!checkrepeat) {
                        this.placeHistory.push(choosePlace)
                    }
                }else {
                    this.placeHistory.push(choosePlace)
                }
M
updata  
maguohua 已提交
102
                setStore('placeHistory',this.placeHistory)
M
updata  
maguohua 已提交
103
                this.$router.push({path:'/msite', query:{geohash}})
M
maguohua 已提交
104 105 106 107
            },
            clearAll(){
                removeStore('placeHistory');
                this.initData();
M
updata  
maguohua 已提交
108
            }
M
updata  
maguohua 已提交
109 110
        }
    }
M
updata  
maguohua 已提交
111 112 113 114

</script>

<style lang="scss" scoped>
M
update  
maguohua 已提交
115
    @import 'src/style/mixin';
M
updata  
maguohua 已提交
116 117 118
    .city_container{
        padding-top: 2.35rem;
    }
M
updata  
maguohua 已提交
119 120
    .change_city{
        right: 0.4rem;
M
maguohua 已提交
121 122
        @include sc(0.6rem, #fff);
        @include ct;
M
updata  
maguohua 已提交
123
    }
M
updata  
maguohua 已提交
124
    .city_form{
M
updata  
maguohua 已提交
125
        background-color: #fff;
M
maguohua 已提交
126 127
        border-top: 1px solid $bc;
        border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
128 129 130 131 132 133 134 135
        padding-top: 0.4rem;
        div{
            width: 90%;
            margin: 0 auto;
            text-align: center;
            .input_style{
                border-radius: 0.1rem;
                margin-bottom: 0.4rem;
M
updata  
maguohua 已提交
136
                @include wh(100%, 1.4rem);
M
updata  
maguohua 已提交
137 138
            }
            .city_input{
M
maguohua 已提交
139
                border: 1px solid $bc;
M
updata  
maguohua 已提交
140
                padding: 0 0.3rem;
M
maguohua 已提交
141
                @include sc(0.65rem, #333);
M
updata  
maguohua 已提交
142 143 144
            }
            .city_submit{
                background-color: $blue;
M
maguohua 已提交
145
                @include sc(0.65rem, #fff);
M
updata  
maguohua 已提交
146 147
            }
        }
M
updata  
maguohua 已提交
148
    }
M
updata  
maguohua 已提交
149
    .pois_search_history{
M
maguohua 已提交
150 151
        border-top: 1px solid $bc;
        border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
152 153 154 155 156
        padding-left: 0.5rem;
        @include font(0.475rem, 0.8rem);
    }
    .getpois_ul{
        background-color: #fff;
M
maguohua 已提交
157
        border-top: 1px solid $bc;
M
updata  
maguohua 已提交
158 159 160
        li{
            margin: 0 auto;
            padding-top: 0.65rem;
M
maguohua 已提交
161
            border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
162 163 164
            .pois_name{
                margin: 0 auto 0.35rem;
                width: 90%;
M
maguohua 已提交
165
               @include sc(0.65rem, #333);
M
updata  
maguohua 已提交
166 167 168 169
            }
            .pois_address{
                width: 90%;
                margin: 0 auto 0.55rem;
M
maguohua 已提交
170
                @include sc(0.45rem, #999);
M
updata  
maguohua 已提交
171 172 173 174 175 176 177 178 179 180
            }
        }
    }
    .search_none_place{
        margin: 0 auto;
        @include font(0.65rem, 1.75rem);
        color: #333;
        background-color: #fff;
        text-indent: 0.5rem;
    }
M
maguohua 已提交
181 182 183 184 185 186
    .clear_all_history{
        @include sc(0.7rem, #666);
        text-align: center;
        line-height: 2rem;
        background-color: #fff;
    }
M
updata  
maguohua 已提交
187
</style>