<template>
	<view>
		<u-navbar autoBack placeholder bgColor="#FFFFFF">
			<view class="navSlot" slot="center">
				<!-- <u-icon name="arrow-left" size="19"></u-icon> -->
				<view class="title">电站信息</view>
			</view>
		</u-navbar>
		<view class="search">
			<u-search placeholder="搜索电站名称、价格、地址等..." :showAction="false" @search="search" bgColor="#FAF7F6"
				v-model="field" :animation="false">
			</u-search>
		</view>

		<view class="bgMains">

			<view class="listGasStations" @click="startGasStaionDetails(item)" v-for="(item,index) in dataList"
				:key="index">
				<view class="GasStationsItem">
					<view>
						<image class="img" :src="item.storeLogo"></image>
					</view>
					<view class="info">
						<view class="title">
							<view>{{item.storeName}}</view>
							<view>
								<image class="goImg" src="../../static/tabar/ic_go.png"  @click.stop="openLocation(item)"></image>
							</view>
						</view>
						<view class="addressInfo">
							<view class="distance">{{item.distance||0}}km</view>
							<view class="address">{{item.detailedAddress}}</view>
						</view>
						<view class="price">
							<view class="currentprice">￥{{item.powerStationPrice}}/度起</view>
							<!-- <view class="originalprice">￥{{item.internationalPrices}}/L</view> -->
						</view>
					</view>


				</view>
				<u-line class="line" length="100%"></u-line>
				<view class="detailsOrder">
					<view class="historicalOrders" @click.stop="addPowerStation(item.id,'edit')">编辑信息</view>
					<!-- <view>	<u-line class="line" direction="col"></u-line></view> -->
					<view class="sleDetail">查看详情</view>
				</view>
			</view>
		</view>

		<div class="addItem" @click="addPowerStation">
			添加电站
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				pageNum: 1,
				total: 0,
				beginTime: "",
				endTime: "",
				field: "",
			}
		},

		onShow() {
			this.pageNum = 1
			this.getoilList();
		},

		onLoad() {
			this.getLocation()
		},

		onReachBottom() {
			console.log(this.total, this.dataList.length);
			if (this.total > this.dataList.length) {
				this.pageNum = this.pageNum + 1
				this.getoilList(true)
			} else {
				wx.showToast({
					title: '没有更多啦！',
					icon: 'none'
				})
			}
		},

		methods: {
			
			openLocation(item){
				console.log(item);
				uni.openLocation({
					latitude:item.lat * 1,
					longitude:item.lon * 1,
					name:item.storeName,
					address:item.detailedAddress,
					success: (res) => {
						console.log(res);
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			search() {
				this.pageNum = 1
				this.getoilList();
			},

			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
					},
					fail: (err) => {
						console.log(err);
					}
				});
			},


			//电站列表
			getoilList(flag) {
				this.$http.post('/api/store/power/powerList', {
					pageNum: this.pageNum,
					pageSize: '20',
					field: this.field,
					lon: "1",
					lat: "1"
				}).then(res => {
					if (res.code == 200)
						this.dataList = !flag ? res.data.rows : this.dataList.concat(res.data.rows)
					this.total = res.data.total

				})
			},


			startGasStaionDetails(item) {
				uni.navigateTo({
					url: '/pages/powerStationDetails/powerStationDetails?id='+item.id
				})
			},

			addPowerStation(id, type) {
				if (id) {
					uni.navigateTo({
						url: '/pages/addPowerStation/addPowerStation?id=' + id + '&type=' + type
					})
				} else {
					uni.navigateTo({
						url: '/pages/addPowerStation/addPowerStation'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #FAF7F6;
		padding-bottom: 200rpx;
	}

	.bgMains {
		padding-bottom: 200rpx;
		background: #f9f6f4;
	}

	.listGasStations {
		background: #FFFFFF;
		padding: 24rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
		margin-bottom: 20rpx;

		.detailsOrder {
			display: flex;
			align-items: center;
			padding-top: 15rpx;

			.historicalOrders {
				width: 50%;
				font-size: 28rpx;
				color: #0278FF;
				text-align: center;
			}

			.sleDetail {
				width: 50%;
				font-size: 28rpx;
				color: #FF4502;
				text-align: center;
			}
		}

		.line {
			padding-top: 10rpx;
		}

		.GasStationsItem {
			display: flex;

			.detailsOrder {
				display: flex;
				align-items: center;
				padding-top: 15rpx;

				.historicalOrders {
					width: 50%;
					font-size: 28rpx;
					color: #0278FF;
					text-align: center;
				}

				.sleDetail {
					width: 50%;
					font-size: 28rpx;
					color: #FF4502;
					text-align: center;
				}
			}

			.line {
				padding-top: 10rpx;
			}

			.info {
				flex: 1;
				padding-left: 10rpx;
			}

			.price {
				display: flex;
				padding: 5rpx;
				background: #FAF7F6;
				border-radius: 23rpx 23rpx 23rpx 23rpx;
				padding-top: 15rpx;

				.currentprice {
					font-size: 22rpx;
					color: #FF4502;
				}

				.originalprice {
					font-size: 24rpx;
					color: #999999;
					text-decoration-line: line-through;
				}
			}

			.addressInfo {
				display: flex;
				padding-top: 15rpx;

				.distance {
					font-size: 24rpx;
					color: #333333;
				}

				.address {
					font-size: 24rpx;
					padding-left: 5rpx;
					color: #999999;
				}
			}

			.title {

				display: flex;
				justify-content: space-between;
				flex: 1;
			}

			.img {
				width: 156rpx;
				height: 156rpx;
			}

			.goImg {
				width: 52rpx;
				height: 52rpx;
			}
		}
	}

	.addItem {
		width: 702rpx;
		height: 100rpx;
		background: linear-gradient(90deg, #FF4502 0%, #FF8903 100%);
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		text-align: center;
		line-height: 100rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #FFFFFF;
		position: fixed;
		left: 50%;
		bottom: 50rpx;
		transform: translateX(-50%);
	}

	.search {
		padding: 24rpx;
		background: #FFFFFF;
	}
</style>