<template>
	<view class="search">
		<scroll-view scroll-y="true" class="search-auto">
			<view class="box">
				<view class="top">

				</view>
				<view class="boxs-flex" v-for="(item,index) in netWorkListDemo" :key="item.id" @click="testIndex(index)"
					v-if="netWorkListDemo.length>0">
					<img class="i" :src="item.image" alt="" />
					<view class="right-flex">
						<view class="title">
							<text>{{item.networkName}}</text>
							<view class="title-right">
								<img class="title-right-i" src="https://www.jiubaotongxue.love/image/map2.png" alt="" />
								<text>{{item.gongli}}km</text>
							</view>
						</view>
						<view class="centers">
							<img class="centers-i" src="https://www.jiubaotongxue.love/image/handle4.png" alt="" />
							<text class="flex-centers-txt">{{item.networkArea}}</text>
						</view>
						<view class="centers1">
							<view class="centers-i-l">
								<img class="centers-i-l-i" src="https://www.jiubaotongxue.love/image/demo29.png"
									alt="" />
								<text class="txt">营业时间：00:00-23:59&nbsp;&nbsp;&nbsp;</text>
							</view>
							<!-- <view class="centers-i-l">
								<img class="centers-i-l-i" src="https://www.jiubaotongxue.love/image/handle3.png"
									alt="" />
								<text class="txts">站点维修</text>
							</view> -->
						</view>
						<view class="bottoms">
							<view class="lefta">
								总工位：{{item.idleDevice}}
							</view>
							<view class="righta">
								空闲：{{item.idleDevice-item.workDevice}}
							</view>
						</view>
					</view>
					<!-- <view class="abo">
						暂停营业
					</view> -->
				</view>
				<view style="width: 80%;height: 500rpx; transform: translate(-50%,-50%); margin-left: 50%;margin-top:50%;"  v-if="netWorkListDemo.length<=0">
					<img src="https://www.jiubaotongxue.love/image/demo111.png" style="width: 100%;height: 480rpx;" alt="" />
					<text style="display: block; width: 100%;text-align: center;font-size: 30rpx; font-weight: 600;">暂无此相关门店信息</text>
				</view>
				<view class="ding">

				</view>


			</view>
		</scroll-view>
	</view>
</template>

<script setup>
	import {
		defineProps,
		ref,
		defineEmits
	} from 'vue';
	import {
		Getnetworklist
	} from '../../api/api.js'
	import {
		list
	} from '../../stor/list/list.js'
	const l = list()
	const netWorkListDemo = ref('')
	const father = ref('')
	const oldProps = ref('')
	const props = defineProps(['netWorkList', 'emitValue'])
	const emits = defineEmits(['test'])
	father.value = props.emitValue
	console.log(props);
	let aac = () => {
		let aaa= setInterval(() => {
			// console.log(props);
			if (father.value === props.emitValue && father.value != ''&&father.value!=oldProps.Value) {
				// console.log("相同")
				clearInterval(aaa)
				oldProps.Value=father.value
				// console.log(father.value)
				Getnetworklist({
					networkName: father.value
				}).then(res => {
					//计算公里数
					res.forEach((e, index) => {
						return e.gongli = l.getDistanceFromLatLonInKm(e.latitude, e.longitude,
								uni
								.getStorageSync('latitude'), uni.getStorageSync('longitude'))
							.toFixed(2)
					})
					res.sort((a, b) => {
						return a.gongli - b.gongli
					})
					netWorkListDemo.value = res
					console.log(res)
					aac()
				}).catch(err => {
					console.log(err)
				})
			} else {
				// console.log("不相同")
				father.value = props.emitValue
			}
		}, 500)
	}
	aac()
	
	const testIndex = (index)=>{
		
		uni.navigateTo({
			url: `/pages/charge/charge?id=${netWorkListDemo.value[index].id}`
		})
	}
	
</script>

<style lang="scss">
	.search {
		width: 100%;
		height: 100%;
		position: absolute;
		z-index: 999;
		// background-color: rgba(0, 0, 0, 0.5);

		.search-auto {
			width: 100%;
			height: 80%;
			background-color: #f0f3fb;
			margin-top: 350rpx;
			position: relative;

			.box {
				width: 100%;
				height: 100%;
				position: relative;

				.top {
					width: 100%;
					height: 10rpx;
					// background-color: red;
					background-image: url("https://www.jiubaotongxue.love/image/handle1.png");
					background-size: 100% 100%;
				}

				.boxs-flex {
					width: 100%;
					height: 244rpx;
					background-color: white;
					border-radius: 20rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 10rpx;
					position: relative;

					.i {
						width: 184rpx;
						height: 164rpx;
						margin-left: 36rpx;
						border-radius: 10rpx;
					}

					.right-flex {
						width: 68%;
						height: 244rpx;

						.title {
							width: 100%;
							height: 42rpx;
							display: flex;
							justify-content: space-between;
							margin-top: 30rpx;
							font-size: 30rpx;
							font-weight: 600;
							line-height: 42rpx;
							box-sizing: border-box;
							padding-right: 30rpx;

							.title-right {
								width: 160rpx;
								height: 42rpx;
								display: flex;
								align-items: center;
								font-size: 24rpx;
								color: #666;

								.title-right-i {
									width: 28rpx;
									height: 28rpx;
									margin-right: 10rpx;
									position: relative;
									z-index: 100;
								}
							}
						}

						.centers {
							width: 100%;
							height: 34rpx;
							display: flex;
							align-items: center;
							margin-top: 10rpx;

							.centers-i {
								width: 24rpx;
								height: 24rpx;
							}

							.flex-centers-txt {
								display: block;
								width: 80%;
								height: 34rpx;
								position: relative;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								font-size: 24rpx;
								margin-left: 10rpx;

							}
						}

						.centers1 {
							width: 100%;
							height: 28rpx;
							font-size: 24rpx;
							display: flex;
							align-items: center;
							margin-top: 10rpx;

							.centers-i-l {
								display: flex;
								align-items: center;

								.centers-i-l-i {
									width: 24rpx;
									height: 24rpx;
								}

								.txt {
									display: block;
									margin-left: 10rpx;
								}

								.txts {
									display: block;
									margin-left: 10rpx;
									color: #FF3232;
								}
							}


						}

						.bottoms {
							width: 100%;
							height: 36rpx;
							display: flex;
							margin-top: 16rpx;

							.lefta {
								width: 220rpx;
								height: 36rpx;
								background: #348EFF;
								border-radius: 5rpx;
								background-image: url("https://www.jiubaotongxue.love/image/handle5.png");
								background-position: 170rpx 5rpx;
								background-size: 24rpx 24rpx;
								background-repeat: no-repeat;
								box-sizing: border-box;
								padding-left: 30rpx;
								font-size: 22rpx;
								color: white;
								line-height: 36rpx;
							}

							.righta {
								width: 220rpx;
								height: 36rpx;
								background: #42BE45;
								margin-left: 20rpx;
								border-radius: 5rpx;
								background-image: url("https://www.jiubaotongxue.love/image/handle5.png");
								background-position: 170rpx 5rpx;
								background-size: 24rpx 24rpx;
								background-repeat: no-repeat;
								font-size: 22rpx;
								color: white;
								line-height: 36rpx;
								box-sizing: border-box;
								padding-left: 30rpx;
								font-size: 22rpx;
							}
						}
					}

					.abo {
						width: 108rpx;
						height: 36rpx;
						background: linear-gradient(135deg, #FE7864 0%, #FF3232 100%);
						position: absolute;
						top: 30rpx;
						left: 40rpx;
						line-height: 36rpx;
						color: white;
						font-size: 22rpx;
						text-align: center;
						border-radius: 10rpx 0rpx 10rpx 0rpx;
					}
				}
			}

			.ding {
				width: 100%;
				height: 200rpx;
			}
		}
	}
</style>