<template>
	<view class="step1">
		<coachInfo @click.native="showStep2" :FormData="FormData"/>
		<view class="h1">预约时间</view>
		<pickDate :FormData="FormData" @updatedForm="updatedForm"/>
		<view class=""  v-if="showCarList.length">
			<view class="h1">教练车</view>
			<view class="card">
				<view class="car">
					<view class="carTag" v-for="(item,index) in showCarList" :key="index">{{item}}</view>
				</view>
			</view>
		</view>
		<view class="" v-if="showSiteList.length">
			<view class="h1">训练场地</view>
			<view class="card" @click="$u.utils.openMap(item.latitude,item.longitude)" v-for="(item,index) in showSiteList" :key="index">
				<view class="site">
					<view class="leftTxt">
						<view class="adrs">{{item.siteName}}</view>
						<view class="adrsTxt">{{item.siteAddress}}</view>
					</view>
					<view class="icon">
						<image src="@/static/images/car/btn_daohang.png" mode=""></image>
						<!-- <image src="@/static/images/car/btn_daohang_cli.png" mode=""></image> -->
					</view>
				</view>
			</view>
		</view>
		
		<view class="poz_btn">
			<view class="btn_row" >
				<view class="btnBg"  @click="openPopup">下一步</view>
			</view>
		</view>
	</view>
</template>

<script>
	import coachInfo from './coachInfo'
	import pickDate from './pickDate'
	export default {
		components: { coachInfo,  pickDate },
		props: ['FormData'],
		data() {
			return {
				
			}
		},
		computed: {
			showSiteList() {
				return this.FormData.courseArr.reduce((acc,obj)=>{
					const found = acc.some(item => item.siteName == obj.siteName );
					  if (!found) {
					    acc.push(obj);
					  }
					  return acc;
				},[])
			},
			showCarList() {
				return [...new Set(this.FormData.courseArr.map(item=>item.carNumber))]
			}
		},
		methods: {
			 openPopup(num) {
				 if(!this.FormData.courseArr.length) {
					return this.$u.toast('请选择排课日期')
				 }
				 this.$emit('openPopup', num)
			 },
			 showStep2() {
				 this.$emit('showStep2')
			 },
			 updatedForm(val) {
				this.$emit('updatedForm', val)
			 }
		}
	}
</script>

<style lang="scss" scoped>
	.poz_btn {
		// position: fixed;
		// bottom: 0;
		// left: 0;
		// padding: 32rpx;
		// width: 100%;
		// background: #F6F6F6;
		.btn_row {
			display: flex;
			align-items: center;
			justify-content: center;
			.btnBg {
				width: 396rpx;
			}
		}
	}
	.h1 {
		line-height: 100rpx;
	}
	.car {
		padding: 32rpx 28rpx;
		.carTag {
			height: 120rpx;
			background: #F8F8F8;
			padding: 0 18rpx;
			color: $themC;
			border-radius: 12rpx;
			font-size: 28rpx;
			font-weight: 500;
			width: fit-content;
			line-height: 120rpx;
		}
	}
	.site {
		padding: 28rpx 40rpx 28rpx 36rpx;
		display: flex;
		align-items: center;
		.leftTxt {
			width: 0;
			flex: 1;
			color: $themC;
			.adrs {
				font-size: 32rpx;
				font-weight: 550;
				margin-bottom: 10rpx;
			}
			.adrsTxt {
				font-size: 28rpx;
				font-weight: 400;
			}
		}
		.icon {
			width: 72rpx;
			height: 72rpx;
		}
	}
</style>