<template>
	<view class="refuel">
		<image class="banner" src="https://zswl-dev.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/03uYm9N6msBkfcb964559107edb57a716b835f90fde5.jpg/1.jpg" mode=""></image>
		
		<view class="notice-box">
			<image class="icon" src="../static/notice.png" mode=""></image>
			进入加油站后，请前往安全区域使用手机
		</view>
		<!-- 内容 -->
		<zs-list class="store-box" mt="0" @load="loadMore" :status="status">
				<view class="item" v-for="(item,index) in list" :key="index" @click="goDetail(item)">
					<image class="tag" src="../static/refuel-tag.png" mode=""></image>
					<!-- <zs-img :src="item.logo" width="200rpx" height="200rpx" radius="full" ></zs-img> -->
					<view class="info">
						<view class="title-box">
							<view class="title">
								{{item.storeName}}
							</view>
							<view class="diatance-box">
								<image class="icon" src="../static/refuel/nav-icon-black.png" mode=""></image>
								{{(item.distance/1000).toFixed(2)}}km
							</view>
						</view>
						<view class="address" >
							距离你 {{(item.distance/1000).toFixed(2)}} 公里
						</view>
						<view  class="activity">
							<view class="discount">
								满200元减14
							</view>
		<!-- 					<view class="coupon">
								<image class="icon" src="../static/refuel/card-icon.png" mode=""></image>
								优惠券省999
							</view> -->
							
							<view class="price-box">
								<view class="label">
									特惠价
								</view>
								<view class="price">
									￥{{item |filterVipPrice}}/L
								</view>
							</view>
							
						</view>
						
						
					</view>
				</view>
		</zs-list>



	</view>
</template>

<script>
	import { getNearbyStore } from '@/api/refuel.js';
	import {
		search
	} from '@/api/shop.js';
	export default {
		data() {
			return {
				map: null,
				longitude: 0,
				latitude: 0,
				scale:18,
				markers: [],
				destination: '',
				active: 0,
				status: 'more',
				list: [],
				list: [],
				// query:{
				// 	latitude:39.896751,
				// 	longitude:116.460653,
				// 	maxDistanceInKilometers:50,
				// 	pageCurrent:1,
				// 	pageSize:10
				// },
				query: {
					district:'',
					menuId: 4,
					queryName: '',
					'location.lat': 0,
					'location.lon': 0,
					pageCurrent: 1,
					pageSize: 10,
					userId: uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
				},
			}
		},
		filters: {
			filterVipPrice: function(item) {
				let arr = item.itemInfoList.filter(i=>i.itemName == '92#')
				if(!arr.length &&item.itemInfoList.length){
					arr = [item.itemInfoList[0]] 
				}
				return arr.length?(arr[0].vipPrice/100).toFixed(2) : 0;
			},
			filterPrice: function(item) {
				let arr = item.itemInfoList.filter(i=>i.itemName == '92#')
				if(!arr.length &&item.itemInfoList.length){
					arr = [item.itemInfoList[0]] 
				}
				return arr.length?(arr[0].cityPrice/100).toFixed(2) : 0;
			}
		},
		methods: {

			goDetail(item) {
				if(!uni.getStorageSync('token')){
					return uni.showModal({
						title:'请登录',
						confirmText:'去登录',
						success(res){
							console.log(res);
							if(res.confirm){
								uni.navigateTo({
									url:'/login/login/login?redirect=/refuel/index'
								})
							}
						}
					})
				}
				uni.navigateTo({
					url: `/refuel/refuelDetail?id=${item.storeId}&epId=${item.shopId}`
				})
			},
			loadMore() {
				this.search()
			},
			search() {
					this.status = 'loading'
					let obj = JSON.parse(JSON.stringify(this.query))
					search(obj).then(res => {
						uni.stopPullDownRefresh()
						if (res.state == 'Success') {
							let dataList = []
							res.content.records.map(item=>{
								let obj 
								if(item.tripartiteJson){
									obj = JSON.parse(item.tripartiteJson)
									obj.distance = item.shopVo.distance
									obj.shopId = item.shopVo.id
									dataList.push(obj)
								}
							})
							this.list = this.list.concat(dataList)
							console.log(this.list);
							if (this.list.length >= res.content.total) {
								this.status = 'noMore'
							} else {
								this.status = 'more'
								this.query.pageCurrent++
							}
						}
					})
					// getNearbyStore(this.query).then(res=>{
					// 		uni.stopPullDownRefresh()
					// 		this.status = 'noMore'
					// 	if(res.state == 'Success'){
					// 		this.list = res.content
							
					// 	}
					// })
			},
		},
		onPullDownRefresh() {
			uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						// 解析地址
						this.query['location.lat'] = res.latitude
						this.query['location.lon'] = res.longitude
						// 存储经纬度
						uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
						this.query.pageCurrent = 1
						this.status = 'more'
						this.list = []
						this.search()
					}
			})
		},
		onLoad(option) {
		},
		onReady() {
			// let location = JSON.parse(uni.getStorageSync('location'))
			// this.query['location.lat'] = location.latitude
			// this.query['location.lon']= location.longitude
			// this.search()
			uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						// 解析地址
						this.query['location.lat'] = res.latitude
						this.query['location.lon'] = res.longitude
						console.log(this);
						// 存储经纬度
						uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
						this.search()
					}
			})
		}
	}
</script>

<style lang="scss">

	.refuel {
		background: #F9F9F9;
		padding: 20rpx 24rpx;
		.banner{
			width: 100%;
			height: 132rpx;
			border-radius: 16rpx;
		}
		.notice-box{
			display: flex;
			align-items: center;
			font-weight: 300;
			font-size: 22rpx;
			color: #EE4927;
			margin: 20rpx 0;
			.icon{
				width: 26rpx;
				height: 26rpx;
				margin-right: 10rpx;
			}
		}
		.zs-list {
			// padding-top: 20rpx;
			.item {
				display: flex;
				padding: 24rpx;
				background: #fff;
				border-radius: 16rpx;
				margin-bottom: 20rpx;
				position: relative;
				.tag{
					position: absolute;
					top: 0%;
					left: 0%;
					width: 150rpx;
					height: 53rpx;
				}

				.info{
					flex: 1;
					padding: 26rpx 0 0;
					.title-box{
						display: flex;
						align-items: center;
						justify-content: space-between;
						.title{
							font-size: 28rpx;
							font-weight: bold;
							width: 500rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							margin-top: 10rpx;
						}
						.diatance-box{
							display: flex;
							align-items: center;
							font-weight: 400;
							font-size: 24rpx;
							color: #222222;
							.icon{
								width: 20rpx;
								height: 20rpx;
								margin-right: 8rpx;
							}
						}
					}
					.address{
						font-weight: 300;
						font-size: 24rpx;
						color: #AAAAAA;
						margin-top: 12rpx;
					}
					
					.activity{
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 10rpx;
						.price-box{
							display: flex;
							align-items: center;
							.label{
								font-weight: 300;
								font-size: 20rpx;
								color: #FF4D3A;
							}
							.price{
								font-weight: 600;
								font-size: 32rpx;
								color: $uni-color-primary;
								margin-left: 8rpx;
							}
						}
						.coupon{
							font-weight: 300;
							padding: 4rpx 16rpx;
							font-weight: 400;
							font-size: 24rpx;
							color: #FFFFFF;
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							background: linear-gradient( 270deg, #EE4320 0%, #FF9C87 100%);
							display: flex;
							align-items: center;
							.icon{
								width: 30rpx;
								height: 30rpx;
							}
						}
					}
					.discount{
						display: inline-block;
						font-weight: 300;
						font-size: 22rpx;
						color: #AAAAAA;
						padding: 2rpx 12rpx;
						border: 1rpx solid #F0F0F0;
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						margin-top: 10rpx;
					}
				}
			}
		}
	}
</style>