<template>
	<view class="content">
		<view class="container">
			<!-- #ifdef MP-WEIXIN -->
			<headers :titles="titles"><uni-icons @click="goback()" type="arrow-left" color="#000000"
					size="22px"></uni-icons></headers>
				<!-- #endif -->
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">
				<swiper-item v-for="(item,index) in swiperListData" :key="index">
					<view class="img-swiper">
						<image :src="baseUrl + item.swiperPicture" mode=""></image>
					</view>
				</swiper-item>

			</swiper>

			<view class="top-box">
				<view class="box-title">{{jxInfoData.schoolName}}</view>
				<view class="box-hui">营业中 {{jxInfoData.businessStartTime}}-{{jxInfoData.businessEndTime}}</view>
				<view class="wrap-box">
					<view v-if="jxInfoData.announcement" class="icon-box">{{jxInfoData.announcement}}</view>
				</view>
				<view class="tel">
					<image @click="findJxPhone(jxInfoData.phone)" class="top-box-img" src="../../static/imgs/dh.png"
						mode=""></image>
				</view>
				<view class="top-bottom">
					<view class="">
						<view v-if="jxInfoData.region" class="l-box">{{jxInfoData.address}}</view>
						<view class="lv-size" style="margin-top: 10px;" @click="djsj()">班车路线</view>
						<!-- <view class="h-box">距离4.9km</view> -->
					</view>
					<view @click="goNavigationClick(jxInfoData.lat, jxInfoData.lgt)" class="right-box">
						<image src="../../static/imgs/dw.png" mode=""></image>
						<view class="">导航</view>
					</view>
				</view>
			</view>
			<!--  -->


		</view>
		<view class="jb-box" @click="goschoollsit()">
			<view class="lift-box">
				<image src="../../static/imgs/ssxx.png" mode=""></image>
			</view>
			<view class=""></view>
			<swiper class="swipers" :vertical="true" circular :indicator-dots="false" :autoplay="autoplay"
				:interval="interval" :duration="duration">

				<view v-for="(item,index) in titleslist" :key="index">
					<swiper-item style="height: 40px;">
						<view class="sw-box">
							<view class="qiu"></view> {{item.title}}
						</view>
					</swiper-item>
				</view>

			</swiper>



			<view class="right-box">
				<u-icon name="arrow-right" size="20"></u-icon>
			</view>
		</view>

		<!-- 报名类型 -->
		<view class="sign-type">
			<view class="sign-type-title">
				<view style="margin-right: 15px;" v-for="(item,index) in typelist" :key="index"
					@click="gettype(item.id)">
					{{item.name}}
				</view>
			</view>

			<view @click="goCourseInfo(item.id)" v-for="(item,index) in rightInfoList" class="sign-type-list">
				<view class="list-left">
					<image class="list-left-img" :src="baseUrl + item.photo" mode=""></image>
				</view>
				<view class="list-right">
					<view class="list-right-name">
						{{item.automatic}}
					</view>
					<view class="bm-page-right-2">
						<view class="bm-page-right-zd">{{item.automatic}}</view>
						<view class="bm-page-right-c2">{{item.license}}</view>
					</view>
					<view class="list-right-price">
						<view class="right-price-1">
							￥{{item.price}}
						</view>
						<view class="right-price-2">
							交定金优惠：<text style="color: crimson;"> {{item.favour}}</text> 元
						</view>
					</view>
				</view>
			</view>
		</view>



		<view class="jl-type">
			<view class="jl-title">
				明星教练
			</view>
			<scroll-view scroll-x="true" class="tap-box">
				<view class="size-box" v-show="!jlId||jlId==item.id" v-for="(item,index) in jlInfoList" :key="index"
					@click="goDetails(item.id)">
					<view class="d-s">
						<view class="touxiang">
							<image :src="baseUrl + item.image" mode=""></image>
						</view>
						<view class="">
							<view class="name_">{{item.instructorName || "匿名教练" }}</view>
							<view class="d-s">
								<view class="icon-y">耐心</view>
								<view class="icon-r">专业</view>
							</view>
						</view>
					</view>
					<view class="bottom-b">
						<view class="w-box">驾龄 <text style="color: #4AA76F;">{{item.experienceYear || 1 }}</text> 年
						</view>
						<view> | </view>
						<view class="w-box">学员<text style="color: #4AA76F;">{{item.student || 0 }}</text></view>
					</view>
				</view>
			</scroll-view>


		</view>
		<view style="width: 100%; height: 50px; "></view>

	</view>
</template>

<script>
	import headers from '../../components/header/headers.vue'
	import request from '@/utils/request.js'
	export default {
		data() {
			return {
				titles: "驾校详情",
				indicatorDots: false,
				autoplay: true,
				interval: 8000,
				duration: 500,
				qhindex: 0,
				swxw: 0,
				Phone: null,
				baseUrl: this.$imagesUrl,
				newId: null,
				typelist: [{
						name: '成人班',
						id: 1
					},
					{
						name: '学生班',
						id: 2
					},
				],
				jxInfoData: [],
				rightInfoList: [],
				jlInfoList: [],
				currentJlIndex: 0,
				titleslist: [],
				swiperListData: [],
				urlpdf: '',
				jlId: null,
				queryParams: {
					pageNum: 1,
					pageSize: 100,
				},
			}
		},
		onLoad: function(option) {
			uni.showToast({
				title: '请选择报名课程',
				icon: 'none'
			})
			if (option) {
				try {
					if (option.type && option.type == 2) {
						this.newId = option.id
						uni.setStorageSync('jlId', option.jlId);
					} else if (option.id) {
						this.newId = option.id
					} else if (option.q) {
						const url = decodeURIComponent(option.q) // 获取到二维码原始链接内容
						let paramstr = url.split("/\?/")[1]
						let params = qs.parser(paramstr);
						uni.setStorageSync('inviteId', params.inviteId);
						if (params.type && params.type == 2) {
							this.newId = params.id
							uni.setStorageSync('jlId', params.jlId);
						} else {
							this.newId = params.id
						}
					}

				} catch (e) {
					//TODO handle the exception
				}
			}


		},
		onShow() {
			this.gettype(1)
			this.jlId = uni.getStorageSync('jlId');
			this.getSwiperInfoData()
			this.ShuttleRoutes()
			this.getTextList()
			// this.actList = ["1", "1", "1", "1", "1", ]
			// this.status = "nomore" 底部刷新结束
			this.getJxInfoDataById(this.newId),
				setInterval(() => {
					this.currentJlIndex++
					if (this.currentJlIndex > this.jlInfoList.length - 1) {
						this.currentJlIndex = 0
					}
				}, 5000)

		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		// 发送好友
		onShareAppMessage(res) {
			return {
				title: this.titles,
				path: '/pages/index/index',
			}
		},
		// 分享朋友圈
		onShareTimeline(res) {
			return {
				title: this.titles,
				path: '/pages/index/index',
			}
		},
		components: {
			headers
		},
		methods: {
			async gettype(id) {
				console.log(id);
				let res = await request({
					url: '/drivingSchool/system/driveSchoolCourse/list?name=' + id + '&deptId=' + this.newId,
				})
				this.rightInfoList = res.data.records
			},
			goDetails(id) {
				uni.navigateTo({
					url: '/pages/index/coachDetails?id=' + id
				})
			},
			goschoollsit() {
				uni.navigateTo({
					url: '/pages/index/schoolCounseling?deptId=' + this.newId
				})
			},
			async getSwiperInfoData() {
				let res = await request({
					url: '/drivingSchool/system/swiper/pclist?jxId=' + this.newId,
					method: 'get',
				})
				console.log('getSwiperInfoData', this.swiperListData);
				this.swiperListData = res.data
			},

			async ShuttleRoutes() {
				let res = await request({
					url: '/drivingSchool/system/file/getOneFile?fileType=4' + '&deptId=' + this.newId,
					method: 'get',
				})
				let ress = await request({
					url: '/drivingSchool/system/phone/getPhone?deptId=' + this.newId,
					method: 'get',
				})
				if (ress.code == 0) {
					this.Phone = ress.data.phone
				}
				if (res.code == 0) {
					this.urlpdf = this.baseUrl + res.data.fileAddress
				}

			},
			djsj() {
				uni.downloadFile({ //通过uniapp的api下载下来
					url: this.urlpdf,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							success: function(FileRes) {
								console.log('打开文档成功');
							}
						});
					}
				});
			},
			async getTextList() {
				let res = await request({
					url: '/drivingSchool/system/news/applist?deptId=' + this.newId,
					method: 'get'
				})
				let ress = await request({
					url: '/drivingSchool/system/dynamic/applist?deptId=' + this.newId,
					method: 'get'
				})
				// this.titleslist.push(res.data)
				// this.titleslist.push(ress.data)
				for (var i = 0; i < res.data.length; i++) {
					this.titleslist.push(res.data[i])
				}
				for (var i = 0; i < ress.data.length; i++) {
					this.titleslist.push(ress.data[i])
				}
				console.log('1', res);
				console.log('2', ress);
				console.log(this.titleslist);
			},
			goJlInfo(id) {
				uni.navigateTo({
					url: '/pages/index/jlInfo?id=' + id,
				})
			},
			goCourseInfo(id) {
				uni.navigateTo({
					// url: '/pages/index/courseInfo?id=' + id,
					url: `/pages/index/courseInfo?courseId=${id}&jxId=${this.jxInfoData.id}`
				})
			},
			getqh(index) {
				this.qhindex = index
			},
			goback() {
				uni.navigateBack()
			},
			async getJxInfoDataById() {
				let res = await request({
					url: `/drivingSchool/system/schoolInfo/list?id=` + this.newId,
				})
				this.jxInfoData = res.data.records[0],
					console.log("驾校信息", this.jxInfoData)
				// this.getRightInfoList(this.jxInfoData.deptId)
				this.getJlInfoList(this.jxInfoData.deptId)
			},
			async getRightInfoList(id) {

				let res = await request({
					// url: `/drivingSchool/system/driveSchoolCourse/list?jxId=${this.jxInfoData.id}`,

					url: "/drivingSchool/system/driveSchoolCourse/list?deptId=" + id,
					method: 'get',
				})
				this.rightInfoList = res,
					console.log("报名班类型", res)
			},
			async getJlInfoList(id) {
				let res = await request({
					// url: `/drivingSchool/system/schoolCoach/list`,
					url: "/drivingSchool/system/schoolCoach/list?deptId=" + id,
					method: 'get',
				})
				this.jlInfoList = res.data
				console.log("明星教练", this.jlInfoList)
			},
			goNavigationClick(lat, lgt) {
				// 进行导航
				uni.openLocation({
					latitude: lat,
					longitude: lgt,
					success: function() {
						console.log('success');
					}
				});
			},
			findJxPhone(phone) {
				console.log("this.Phone:", this.Phone);
				uni.makePhoneCall({
					phoneNumber: this.Phone, //仅为示例

				});
			}

		}

	}
</script>

<style scoped lang="scss">
	.icon-y {
		width: 45px;
		height: 18px;
		background: #E6F5F0;
		border-radius: 2px 2px 2px 2px;
		font-size: 10px;
		color: #4AA76F;
		margin-right: 10px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.jb-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 10px;
		background: #fff;
		margin-bottom: 15px;

	}

	.lift-box {
		width: 40px;
		height: 40px;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.swipers {
		width: 60%;
		height: 40px;
		margin: 0 auto;
	}

	.icon-r {
		width: 45px;
		height: 18px;
		background: #FFEDD4;
		border-radius: 2px 2px 2px 2px;
		font-size: 10px;
		color: #EDA23A;
		margin-right: 10px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.d-s {
		display: flex;
		align-items: center;
	}

	.name_ {
		font-weight: bold;
		font-size: 14px;
		color: #333333;
		margin-bottom: 10px;
	}

	.w-box {
		width: 50%;
		display: flex;
		align-items: center;
		justify-content: center;

	}

	.bottom-b {
		border-top: 1px solid #DDDDDD;
		box-sizing: border-box;
		padding-top: 10px;
		margin-top: 10px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 12px;
		color: #999999;
	}

	.tap-box {
		width: 100%;
		box-sizing: border-box;
		white-space: nowrap;

		.size-box {
			display: inline-block;
			border-radius: 8px 8px 8px 8px;
			border: 1px solid #DDDDDD;
			box-sizing: border-box;
			padding: 10px;
			width: 190px;

			margin-right: 15px;
		}

		.touxiang {
			width: 38px;
			height: 38px;
			border-radius: 50%;
			overflow: hidden;
			margin-right: 10px;
			background: #4AA76F;

			image {
				width: 100%;
				height: 100%;

			}
		}

	}

	.jl-type {
		padding: 20rpx;
		background-color: #fff;
		margin-top: 20rpx;

		.jl-list {
			width: 500rpx;
			height: 300rpx;

			.jl-bottom {
				border-top: 1px solid #666;
				padding: 20rpx;
				display: flex;
				font-size: 33rpx;

				.jl-bootom-right {
					flex: 1.3;
					border-left: 1px solid #444;
					padding-left: 30rpx;

					.jl-bootom-right-text {
						color: #4AA76F;
					}
				}

				.jl-bottom-left {
					flex: 0.8;

					.jl-bottom-left-text {
						color: #4AA76F;
					}
				}
			}

			.jl-top-list {
				padding-bottom: 30rpx;
				display: flex;

				.jl-top-left {
					display: flex;
					justify-content: space-between;
					padding: 10rpx 20rpx;
					flex-direction: column;

					.jl-top-left-bottom {
						.jl-top-left-bottom-1 {
							padding: 10rpx 20rpx;
							background-color: rgba(86, 173, 121, 0.2);
							border-radius: 12rpx;
						}

						.jl-top-left-bottom-2 {
							margin-left: 30rpx;
							padding: 10rpx 20rpx;
							background-color: rgba(244, 191, 119, 0.2);
							border-radius: 12rpx;
						}
					}

					.jl-top-left-top {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.jl-top-left-top-left {
							font-size: 30rpx;
							font-weight: 600;
						}

						.jl-top-left-top-right {}

					}
				}

				.jl-top-left-img {
					height: 70px;
					width: 70px;
					margin-right: 25rpx;
					border-radius: 50%;
				}
			}
		}

		.jl-title {
			font-size: 34rpx;
			font-weight: 600;
			padding: 20rpx;
		}
	}

	.sign-type {
		padding: 20rpx;
		background-color: #fff;

		.sign-type-list {
			display: flex;
			justify-content: space-between;
			height: 200rpx;

			.list-right {
				flex: 3;
				margin-left: 30rpx;
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				padding: 30rpx 0;

				.list-right-price {
					display: flex;
					align-items: center;

					.right-price-1 {
						color: red;
						font-size: 34rpx;
					}

					.right-price-2 {
						margin-left: 30rpx;
						color: #666666;
						// text-decoration: underline;
						font-size: 24rpx;
					}
				}

				.list-right-name {
					font-weight: 600;
				}

				.bm-page-right-2 {
					display: flex;
					font-size: 22rpx;

					.bm-page-right-zd {
						background-color: rgba(94, 255, 153, 0.2);
					}

					.bm-page-right-c2 {
						background-color: rgba(255, 208, 112, 0.2);
					}

					view {
						text-align: center;
						border-radius: 12rpx;
						padding: 10rpx;
						background-color: red;
						margin-right: 10rpx;
					}

					&:last-child {
						margin-right: 20rpx;
					}
				}
			}

			.list-left {
				flex: 1;

				.list-left-img {
					height: 180rpx;
					width: 280rpx;
					border-radius: 16rpx;
				}
			}

		}

		.sign-type-title {
			font-size: 38rpx;
			font-weight: 600;
			padding: 20rpx;
			display: flex;
			align-items: center;
		}
	}

	.content {
		background: #f4f5f6;

		height: 100vh;
	}

	.container {
		width: 100%;
		background: #f4f5f6;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.swiper {
		width: 100%;
		height: 280px;
	}

	.img-swiper {
		width: 100%;
		height: 280px;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.top-box {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		background: #fff;
		margin-bottom: 15px;
		position: relative;

		.top-box-img {
			width: 100rpx;
			height: 100rpx;
		}

	}

	.wrap-box {
		width: 100%;
		display: flex;
		margin: 10px 0px;

	}

	.top-bottom {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.right-box {
		border-left: 1px solid #DDDDDD;
		box-sizing: border-box;
		padding-left: 20px;
		text-align: center;
		font-size: 12px;
		color: #4AA76F;

		image {
			width: 28px;
			height: 28px;
		}
	}

	.l-box {
		font-size: 12px;
		color: #333333;
	}

	.h-box {
		font-size: 12px;
		color: #666666;
	}

	.icon-box {

		background: #E6F5F0;
		border-radius: 2px 2px 2px 2px;
		font-size: 10px;
		color: #4AA76F;
		display: flex;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		padding: 2px 5px;
	}

	.box-title {
		font-weight: 800;
		font-size: 20px;
		color: #333333;
		margin-bottom: 5px;
	}

	.box-hui {
		font-weight: 400;
		font-size: 12px;
		color: #666666;
	}

	//
	.ri-box {
		width: 100%;
		box-sizing: border-box;
		padding: 15px;
		background: #fff;
		margin-bottom: 15px;

	}

	.ri-title {
		font-weight: bold;
		font-size: 16px;
		color: #333333;
	}

	.tap-top {
		margin-top: 20rpx;
		width: 100%;
		box-sizing: border-box;

		white-space: nowrap;



		.sz {
			display: inline-block;
		}

		.box {
			background: #fff;
			text-align: center;
			font-size: 32rpx;
			margin-right: 50rpx;
			line-height: 32rpx;
			text-align: center;
			// font-weight: bold;
			color: #4AA76F;
			margin-bottom: 22rpx;
		}
	}

	.xztap {
		color: #fff !important;
		background-color: #4AA76F !important;
		box-sizing: border-box;
		padding: 10px;
		border-radius: 4px;
	}

	.ri-bs {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 10px auto;
	}

	.hui-box {
		width: 47%;
		border-radius: 8px;
		border: 1px solid #d3d3d3;
		box-sizing: border-box;
		padding: 16px;
		text-align: center;
		color: #adadad;
	}

	.lvanniu {
		color: #4AA76F !important;
		border: 1px solid #4AA76F;
	}

	.bottom-bo {
		width: 100%;
		height: 60px;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.lv-anniu {
		width: 318px;
		height: 40px;
		background: #4AA76F;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		border-radius: 50px;
	}

	.tel {
		position: absolute;
		right: 15px;
		top: 15px;
	}

	.lv-size {
		font-size: 14px;
		font-weight: bold;
		color: #4AA76F;
	}
</style>