city.vue 5.6 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>
M
updata  
maguohua 已提交
11
                <input type="submit" name="submit" class="city_submit input_style" @click='postpois'>
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 19 20 21
        <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>
            </li>  
        </ul>
        <div class="search_none_place" v-if="placeNone">很抱歉!无搜索结果</div>
M
updata  
maguohua 已提交
22
    </div>
M
updata  
maguohua 已提交
23 24 25
</template>

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

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

M
maguohua 已提交
43
        mounted(){
M
updata  
maguohua 已提交
44
            this.cityid = this.$route.params.cityid;
M
maguohua 已提交
45
            //获取当前城市名字
M
updata  
maguohua 已提交
46 47 48
            currentcity(this.cityid).then(res => {
                this.cityname = res.name;
            })
M
maguohua 已提交
49
            //获取搜索历史记录
M
updata  
maguohua 已提交
50 51
            if (getStore('placeHistory')) {
                this.placelist = JSON.parse(getStore('placeHistory'));
M
updata  
maguohua 已提交
52
            }
M
updata  
maguohua 已提交
53 54 55 56 57 58 59 60 61 62 63
        },

        components:{
            headTop
        },

        computed:{

        },

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

</script>

<style lang="scss" scoped>
M
update  
maguohua 已提交
105
    @import 'src/style/mixin';
M
updata  
maguohua 已提交
106 107 108
    .city_container{
        padding-top: 2.35rem;
    }
M
updata  
maguohua 已提交
109 110
    .change_city{
        right: 0.4rem;
M
maguohua 已提交
111 112
        @include sc(0.6rem, #fff);
        @include ct;
M
updata  
maguohua 已提交
113
    }
M
updata  
maguohua 已提交
114
    .city_form{
M
updata  
maguohua 已提交
115
        background-color: #fff;
M
maguohua 已提交
116 117
        border-top: 1px solid $bc;
        border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
118 119 120 121 122 123 124 125
        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 已提交
126
                @include wh(100%, 1.4rem);
M
updata  
maguohua 已提交
127 128
            }
            .city_input{
M
maguohua 已提交
129
                border: 1px solid $bc;
M
updata  
maguohua 已提交
130
                padding: 0 0.3rem;
M
maguohua 已提交
131
                @include sc(0.65rem, #333);
M
updata  
maguohua 已提交
132 133 134
            }
            .city_submit{
                background-color: $blue;
M
maguohua 已提交
135
                @include sc(0.65rem, #fff);
M
updata  
maguohua 已提交
136 137
            }
        }
M
updata  
maguohua 已提交
138
    }
M
updata  
maguohua 已提交
139
    .pois_search_history{
M
maguohua 已提交
140 141
        border-top: 1px solid $bc;
        border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
142 143 144 145 146
        padding-left: 0.5rem;
        @include font(0.475rem, 0.8rem);
    }
    .getpois_ul{
        background-color: #fff;
M
maguohua 已提交
147
        border-top: 1px solid $bc;
M
updata  
maguohua 已提交
148 149 150
        li{
            margin: 0 auto;
            padding-top: 0.65rem;
M
maguohua 已提交
151
            border-bottom: 1px solid $bc;
M
updata  
maguohua 已提交
152 153 154
            .pois_name{
                margin: 0 auto 0.35rem;
                width: 90%;
M
maguohua 已提交
155
               @include sc(0.65rem, #333);
M
updata  
maguohua 已提交
156 157 158 159
            }
            .pois_address{
                width: 90%;
                margin: 0 auto 0.55rem;
M
maguohua 已提交
160
                @include sc(0.45rem, #999);
M
updata  
maguohua 已提交
161 162 163 164 165 166 167 168 169 170
            }
        }
    }
    .search_none_place{
        margin: 0 auto;
        @include font(0.65rem, 1.75rem);
        color: #333;
        background-color: #fff;
        text-indent: 0.5rem;
    }
M
updata  
maguohua 已提交
171
</style>