nearshop.vue 6.8 KB
<template>
	<view class="content">
		<view class='navhead flextwo searchnav'>
			
			<view class="navmiddle navmiddlek flexone">
				<view class="middleleft">
					<image src="../../static/search.png" mode=""></image>
				</view>
				<view class="middleenter">
					<input type="text" placeholder="请输入商品,店铺搜索" placeholder-class="enterk" @input="enterword" />
				</view>
			</view>
			<view class="souyou" @click="search">
				搜索
			</view>
		</view>
		<view class="tapnav flexone">
		
			<view class="tapnavitem" :class="order==2?'nearactive':''" @click="rangge" :data-id="2">
				距离最近  
			</view>
			<view class="tapnavitem pingfen" @click="rangge" :class="order==3?'nearactive':''" :data-id="3">评分最高</view>
			<picker @change="bindtypeChange" :value="typeindex" :range="typearr" range-key="name" @click="rangge" :data-id="4">
				<view class="tapnavitem pingfen"  :class="order==4?'nearactive':''" >{{typename}}</view>
			</picker>
			
		</view>

		<view class="nodata" v-if="shoplist.length==0">暂无数据</view>
		<view class="searchshop commnonpadding" style="padding-bottom:120rpx" v-else>
			<!-- v-fo="(item,index) in shoplist" :key="" -->
			<view class="searchgooditem flex boxsizing" v-for="(item,index) in shoplist" :key="index" @click="shopdetail(item.id)" :data-id="item.id">
				
				<view class="shopleftimg">
					<image :src="item.image" mode="aspectFill"></image>
				</view>
				<view class="shopright">
					<view class="shopname">{{item.name}}</view>
					<view class="shopmiddle flexone">
						<view class="shopmiddleleft">
							{{item.score}}
						</view>
						<view class="shopmiddleright">
							<view class="star flex">
								<view class="starimg">
									<image src="../../static/shixing.png" mode="" v-if="item.star>=2"></image>
									<image src="../../static/kongxing.png" mode="" v-else></image>
								</view>
								<view class="starimg">
									<image src="../../static/shixing.png" mode="" v-if="item.star>=4"></image>
									<image src="../../static/kongxing.png" mode="" v-else></image>
								</view>
								<view class="starimg">
									<image src="../../static/shixing.png" mode="" v-if="item.star>=6"></image>
									<image src="../../static/kongxing.png" mode="" v-else></image>
								</view>
								<view class="starimg">
									<image src="../../static/shixing.png" mode="" v-if="item.star>=8"></image>
									<image src="../../static/kongxing.png" mode="" v-else></image>
								</view>
								<view class="starimg">
									<image src="../../static/shixing.png" mode="" v-if="item.star>=10"></image>
									<image src="../../static/kongxing.png" mode="" v-else></image>
								</view>
							</view>
							<view class="haoping">好评率{{item.probability}}%</view>
						</view>
					
					
					</view>
					<view class="shopdizhi flexone">
						<view class="shopdiimg">
							<image src="../../static/shopaddress.png" mode=""></image>
						</view>
						<view class='shopli'>距离{{item.distance}}km</view>
					</view>
				</view>
			</view>
			
		</view>
		<tabBar :current="currentTabIndex" backgroundColor="#fbfbfb" color="#999" tintColor="#42b983" ></tabBar>
		
	</view>
</template>

<script>
	
	import app from "../../App.vue";
	import tabBar from '../../components/tabvue/tabvue.vue'
	
	export default {
		components:{
				tabBar
			},
		data() {
			return {
				showbanben: false,
				footersel: 2,
				keyword: '',
				order: 2,
				shoplist: [],
				currentTabIndex:1,
				province_id:'',
				provincename:'',
				typearr:[{
					id:1,
					name:'面制品'
				},
				{
					id:2,
					name:'米制品'
				},
				{
					id:3,
					name:'豆制品'
				}
				
				],
				typeindex:0,
				typeid:'',
				typename:'面制品',
				moreshow:false
				
			}
		},
		onLoad() {
			
			
		},
		onShow() {
			this.moreshow=false
			console.log(343489)
			this.page=1;
			this.shoplist=[]
			this.provincename=uni.getStorageSync("newprovincename");
			this.getprovinceid();
			
			uni.hideTabBar({
				
			})
		},
		methods: {
			bindtypeChange(e){
				this.order=4;
				this.typeid=this.typearr[e.target.value].id;
				this.typename=this.typearr[e.target.value].name;
				this.shoplist = [];
				this.page = 1;
				this.getshoplist()
				
			},
			// 根据城市名字获取id
			getprovinceid(){
				let that = this;
				var url = 'question/get_area';
				var params = {
					province_name: that.provincename
				}
				console.log('7766554', params)
				app.post(url, params).then((res) => {
					console.log('3493948',res)
					
					that.province_id=res.data.data.id;
					
				// 获取附近店铺
				this.getshoplist();
				}).catch((err) => {
					console.log(err)
				
				})
			},

			// 顶部切换
			rangge(e) {
				this.order = e.currentTarget.dataset.id;
				if(this.order==4){
					this.typeid=1
				}else{
					this.typeid=''
				}
				this.shoplist = [];
				this.page = 1;
				this.getshoplist()
			},
				// 店铺详情
				shopdetail(id){
					// console.log(e)
					// let id=e.currentTarget.dataset.id;
					 console.log(id)
					uni.navigateTo({
						url:'/pages/nearshop/shopdetail?shopid='+id
					})
				},
			// 底部导航跳转
			selnav(e) {
				console.log(e)

				let id = e.currentTarget.dataset.id;
				console.log(id)
				if (id == 1) {
					uni.navigateTo({
						url: '../homepage/homepage'
					})
				} else if (id == 2) {
					uni.navigateTo({
						url: "../nearshop/nearshop"
					})
				} else if (id == 3) {
					uni.navigateTo({
						url: "../luntan/luntan"
					})
				} else if (id == 4) {
					uni.navigateTo({
						url: "../usercenter/my"
					})
				}
			},
			enterword(e) {
				this.keyword = e.detail.value;
			},

			search() {
				this.page = 1;
				this.shoplist = [];
				
				this.getshoplist()
			},
			//获取店铺列表
			getshoplist() {
				let that = this;
				let token=uni.getStorageSync("token");
				var url = 'store/get_store_list';
				var params = {
					province_id:'',
					keyword: that.keyword,
					order: that.order,
					type:this.typeid,
					page: that.page,
					pageNum: 10
				}
				console.log('参数', params)
				app.post(url, params, "post").then((res) => {
					console.log(res);
					that.shoplist = that.shoplist.concat(res.data.data)
					if(that.page>1){
						if(res.data.data.length==0){
							uni.showToast({
								title:'没有更多了~',
								icon:'none'
							})
							that.moreshow=true
						}
					}
				}).catch((err) => {
					console.log(err)
					if(err.msg=='用户未登录'){
						uni.reLaunch({
							url:'/pages/login/loginindex'
						})
					}

				})
			}



		},
		onReachBottom() {
			console.log(3483489,this.moreshow)
			let newpage=this.page;
			newpage++;
			this.page=newpage;
			if(this.moreshow==false){
				this.getshoplist()
			}
		}

	}
</script>

<style>
	@import url('../../base/homepage');
	.nodata{
		margin:150rpx auto 0;
	}
</style>