msite.vue 5.5 KB
Newer Older
M
maguohua 已提交
1
<template>
M
maguohua 已提交
2 3
    <div>
    	<head-top signin-up='msite'>
revser  
马国华 已提交
4
    		<router-link :to="'/search/geohash'" class="link_search" slot="search">
M
maguohua 已提交
5
	    		<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" version="1.1">
M
maguohua 已提交
6 7
	    			<circle cx="8" cy="8" r="7" stroke="rgb(255,255,255)" stroke-width="1" fill="none"/>
	    			<line x1="14" y1="14" x2="20" y2="20" style="stroke:rgb(255,255,255);stroke-width:2"/>
M
maguohua 已提交
8 9 10
	    		</svg>
    		</router-link>
			<router-link to="/home" slot="msite-title" class="msite_title">
M
update  
maguohua 已提交
11
				<span class="title_text ellipsis">{{msietTitle}}</span>
M
maguohua 已提交
12 13 14
			</router-link>
    	</head-top>
    	<nav class="msite_nav">
M
maguohua 已提交
15
    		<div class="swiper-container" v-if="foodTypes.length">
M
maguohua 已提交
16 17
		        <div class="swiper-wrapper">
		            <div class="swiper-slide food_types_container" v-for="(item, index) in foodTypes" :key="index">
M
maguohua 已提交
18
	            		<router-link :to="{path: '/food', query: {geohash, title: foodItem.title, restaurant_category_id: getCategoryId(foodItem.link)}}" v-for="foodItem in item" :key="foodItem.id" class="link_to_food">
M
maguohua 已提交
19 20 21 22
	            			<figure>
	            				<img :src="imgBaseUrl + foodItem.image_url">
	            				<figcaption>{{foodItem.title}}</figcaption>
	            			</figure>
M
update  
maguohua 已提交
23
	            		</router-link>
M
maguohua 已提交
24 25 26 27
		            </div>
		        </div>
		        <div class="swiper-pagination"></div>
		    </div>
M
maguohua 已提交
28
		    <img src="../../images/fl.svg" class="fl_back animation_opactiy" v-else>
M
maguohua 已提交
29 30 31 32 33 34 35 36
    	</nav>
    	<div class="shop_list_container">
	    	<header class="shop_header">
	    		<svg class="shop_icon">
	    			<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#shop"></use>
	    		</svg>
	    		<span class="shop_header_title">附近商家</span>
	    	</header>
M
maguohua 已提交
37
	    	<shop-list v-if="hasGetData" :geohash="geohash"></shop-list>
M
maguohua 已提交
38
    	</div>
M
maguohua 已提交
39
    	<foot-guide></foot-guide>
M
maguohua 已提交
40
    </div>    
M
maguohua 已提交
41 42 43
</template>

<script>
M
maguohua 已提交
44
import {mapMutations} from 'vuex'
M
maguohua 已提交
45
// import {imgBaseUrl} from 'src/config/env'
M
update  
maguohua 已提交
46 47 48
import headTop from 'src/components/header/head'
import footGuide from 'src/components/footer/footGuide'
import shopList from 'src/components/common/shoplist'
M
maguohua 已提交
49
import {msiteAdress, msiteFoodTypes, cityGuess} from 'src/service/getData'
M
update  
maguohua 已提交
50 51
import 'src/plugins/swiper.min.js'
import 'src/style/swiper.min.css'
M
maguohua 已提交
52 53 54 55

export default {
	data(){
        return {
M
maguohua 已提交
56
        	geohash: '', // city页面传递过来的地址geohash
M
maguohua 已提交
57
            msietTitle: '请选择地址...', // msiet页面头部标题
M
maguohua 已提交
58
            foodTypes: [], // 食品分类列表
M
maguohua 已提交
59
            hasGetData: false, //是否已经获取地理位置数据,成功之后再获取商铺列表信息
M
maguohua 已提交
60
            imgBaseUrl: 'https://fuss10.elemecdn.com', //图片域名地址
M
maguohua 已提交
61 62
        }
    },
M
maguohua 已提交
63
    async beforeMount(){
M
maguohua 已提交
64 65 66 67 68 69
		if (!this.$route.query.geohash) {
			const address = await cityGuess();
			this.geohash = address.latitude + ',' + address.longitude;
		}else{
			this.geohash = this.$route.query.geohash
		}
M
maguohua 已提交
70 71
		//保存geohash 到vuex
		this.SAVE_GEOHASH(this.geohash);
M
maguohua 已提交
72 73 74 75
    	//获取位置信息
    	let res = await msiteAdress(this.geohash);
    	this.msietTitle = res.name;
    	// 记录当前经度纬度
M
maguohua 已提交
76
    	this.RECORD_ADDRESS(res);
M
maguohua 已提交
77 78 79 80 81 82 83

    	this.hasGetData = true;
    },
    mounted(){
        //获取导航食品类型列表
       	msiteFoodTypes(this.geohash).then(res => {
       		let resLength = res.length;
M
maguohua 已提交
84
       		let resArr = [...res]; // 返回一个新的数组
M
maguohua 已提交
85 86 87 88 89 90
       		let foodArr = [];
    		for (let i = 0, j = 0; i < resLength; i += 8, j++) {
    			foodArr[j] = resArr.splice(0, 8);
    		}
    		this.foodTypes = foodArr;
        }).then(() => {
M
maguohua 已提交
91
        	//初始化swiper
M
maguohua 已提交
92 93 94 95 96 97 98 99
        	new Swiper('.swiper-container', {
		        pagination: '.swiper-pagination',
		        loop: true
		    });
        })
    },
    components: {
    	headTop,
M
maguohua 已提交
100 101
    	shopList,
    	footGuide,
M
maguohua 已提交
102 103 104 105 106 107
    },
    computed: {

    },
    methods: {
    	...mapMutations([
M
maguohua 已提交
108
    		'RECORD_ADDRESS', 'SAVE_GEOHASH'
M
maguohua 已提交
109 110 111 112 113 114 115 116 117 118
    	]),
    	// 解码url地址,求去restaurant_category_id值
    	getCategoryId(url){
    		let urlData = decodeURIComponent(url.split('=')[1].replace('&target_name',''));
    		if (/restaurant_category_id/gi.test(urlData)) {
    			return JSON.parse(urlData).restaurant_category_id.id
    		}else{
    			return ''
    		}
    	}
M
maguohua 已提交
119 120 121
    },
    watch: {

M
maguohua 已提交
122 123 124 125 126 127
    }
}

</script>

<style lang="scss" scoped>
M
update  
maguohua 已提交
128
    @import 'src/style/mixin';
M
maguohua 已提交
129 130
	.link_search{
		left: .8rem;
M
maguohua 已提交
131
		@include wh(.9rem, .9rem);
M
maguohua 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
		@include ct;
	}
	.msite_title{
		@include center;
        width: 50%;
        color: #fff;
        text-align: center;
        margin-left: -0.5rem;
        .title_text{
            @include sc(0.8rem, #fff);
            text-align: center;
            display: block;
        }
	}
	.msite_nav{
		padding-top: 2.1rem;
		background-color: #fff;
		border-bottom: 0.025rem solid $bc;
M
maguohua 已提交
150
		height: 10.6rem;
M
maguohua 已提交
151 152 153 154 155 156 157
		.swiper-container{
			@include wh(100%, auto);
			padding-bottom: 0.6rem;
			.swiper-pagination{
				bottom: 0.2rem;
			}
		}
M
maguohua 已提交
158 159 160
		.fl_back{
			@include wh(100%, 100%);
		}
M
maguohua 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	}
	.food_types_container{
		display:flex;
		flex-wrap: wrap;
		.link_to_food{
			width: 25%;
			padding: 0.3rem 0rem;
			@include fj(center);
			figure{
				img{
					margin-bottom: 0.3rem;
					@include wh(1.8rem, 1.8rem);
				}
				figcaption{
					text-align: center;
					@include sc(0.55rem, #666);
				}
			}
		}
	}
	.shop_list_container{
		margin-top: .4rem;
		border-top: 0.025rem solid $bc;
		background-color: #fff;
		.shop_header{
			.shop_icon{
				fill: #999;
				margin-left: 0.6rem;
				vertical-align: middle;
				@include wh(0.6rem, 0.6rem);
			}
			.shop_header_title{
				color: #999;
				@include font(0.55rem, 1.6rem);
			}
		}
	}

M
maguohua 已提交
199
</style>