city.vue 5.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>
M
updata  
maguohua 已提交
11
                <input type="submit" name="submit" class="city_submit input_style" @click='postpois'>
M
updata  
maguohua 已提交
12 13
            </div>
        </form>
M
updata  
maguohua 已提交
14 15 16 17 18 19 20 21 22 23
        <div>
            <header v-if="historytitle" class="pois_search_history">搜索历史</header>
        </div>    
        <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 已提交
24
    </div>
M
updata  
maguohua 已提交
25 26 27
</template>

<script>
M
updata  
maguohua 已提交
28
    import headTop from '../../components/header/head'
M
updata  
maguohua 已提交
29 30
    import {currentcity, searchplace} from '../../service/getData'
    import * as Tool from '../../config/mUtils'
M
updata  
maguohua 已提交
31

M
updata  
maguohua 已提交
32 33 34
    export default {
    	data(){
            return{
M
updata  
maguohua 已提交
35 36 37 38 39 40 41
                inputVaule:'',
                cityid:'',
                cityname:'',
                placelist:[],
                placeHistory:[],
                historytitle: true,
                placeNone: false,
M
updata  
maguohua 已提交
42 43 44 45
            }
        },

        created(){
M
updata  
maguohua 已提交
46 47 48 49
            this.cityid = this.$route.params.cityid;
            currentcity(this.cityid).then(res => {
                this.cityname = res.name;
            })
M
updata  
maguohua 已提交
50

M
updata  
maguohua 已提交
51 52 53
            if (Tool.getStore('placeHistory')) {
                this.placelist = JSON.parse(Tool.getStore('placeHistory'));
            }
M
updata  
maguohua 已提交
54 55 56 57 58 59 60 61 62 63 64
        },

        components:{
            headTop
        },

        computed:{

        },

        methods:{
M
updata  
maguohua 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
            postpois(){
                if (this.inputVaule) {
                    searchplace(this.cityid, this.inputVaule).then(res => {
                        this.historytitle = false;
                        this.placelist = res;
                        this.placeNone = res.length? false : true;
                    })
                }
            },
            nextpage(index, geohash){
                let history = Tool.getStore('placeHistory');
                let choosePlace = this.placelist[index];
                if (history) {
                    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)
                }
                Tool.setStore('placeHistory',this.placeHistory)
                this.$router.push({path:'/msite', query:{geohash}})
            }
M
updata  
maguohua 已提交
94 95
        }
    }
M
updata  
maguohua 已提交
96 97 98 99

</script>

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