<template>
	<view>
		<view class="top_view">
			<view class="flex justify-between align-center margin-lr-lg">
				<view class="top_title">正在寻找乘客</view>
				<view class="top_rightview" @click="bjShow = !bjShow">
					<image src="../../static/upload/more.png">
					</image>
					<view class="top_popuView" v-if="bjShow">
						<view style="padding: 40rpx 50rpx 20rpx;" @click.stop="closeSave">取消行程</view>
						<view style="padding: 0rpx 50rpx 40rpx;" @click.stop="editSave" class="margin-top">编辑行程</view>
					</view>
				</view>
			</view>

			<view v-if="order.shipAddress" class="margin-lr-lg"
				style="background: #FFFFFF;background: #FFFFFF;border-radius: 24rpx;padding: 30rpx;margin-top: 40rpx;">
				<view class="flex justify-end align-center" @tap="goXC">
					<view style="font-size: 26rpx;font-weight: bold;margin-right: 10rpx;">查看行程</view>
					<view>
						<image src="../../static/image/right.png" style="width: 12rpx;height: 22rpx;">
						</image>
					</view>
				</view>
				<view class="topbox_addview justify-between" style="margin-top: 20rpx;">
					<view class="flex align-center" style="margin-bottom: 4rpx;">
						<view class="green"></view>
						<view class="topbox_addName">{{order.shipAddress}}</view>
					</view>
					<image src="/static/upload/up.png"></image>
					<view class="flex align-center">
						<view class="orgin"></view>
						<view class="topbox_addName">{{order.deliveryAddress}}</view>
					</view>
				</view>
				<view class="flex justify-between margin-tb-sm">
					<view class="flex">
						<view class="topbox_title" v-if="order.seatNum">{{order.seatNum}}人乘车</view>
						<view class="topbox_title" v-if="order.isHighSpeedPrice && order.isHighSpeedPrice == 1">
							·司机承担</view>
						<view class="topbox_title" v-if="order.isHighSpeedPrice && order.isHighSpeedPrice == 2">
							·乘客承担</view>
						<view class="topbox_title" v-if="order.isHighSpeedPrice && order.isHighSpeedPrice == 3">
							·费用AA</view>
					</view>
					<view class="topbox_title">{{order.startTime}}出发</view>
				</view>
			</view>

			<u-sticky @fixed="xdCheck" @unfixed="noXDCheck" bgColor="none" bgColors="#FFFFFF">
				<view class="flex justify-between margin-top margin-lr-lg" :class="scrollTop == 1 ? 'showTopView' : ''">
					<view :class="typeSel == 0 ? 'type_item_sel' : 'type_item'" @tap="typeCheck(0)">智能排序</view>
					<view :class="typeSel == 1 ? 'type_item_sel' : 'type_item'" @tap="typeCheck(1)">最新发布</view>
					<view :class="typeSel == 2 ? 'type_item_sel' : 'type_item'" @tap="typeCheck(2)">价格最高</view>
					<view :class="typeSel == 3 ? 'type_item_sel' : 'type_item'" @tap="typeCheck(3)">起点最近</view>
				</view>
			</u-sticky>
			<view class="boxa margin-lr-lg" @click="goOrder(item)" v-for="(item,index) in list" :key="index">
				<view class="flex align-center justify-between" style="padding: 0rpx 0rpx 0rpx 30rpx;">
					<view class="flex align-center">
						<view class="item_time">{{item.appointmentStartTime}}</view>
						<view class="item_chakan" v-if="item.browCount && item.browCount == 1">查看过</view>
					</view>
					<view class="item_shunlu">{{item.similarity ? item.similarity : '0'}}% <text
							style="font-size: 24rpx;">顺路</text> </view>
				</view>
				<view class="padding margin-top-xs">
					<view class="flex align-center justify-between" style="margin-bottom: 4rpx;">
						<view class="flex align-center">
							<view class="green"></view>
							<view class="item_addName">{{item.shipAddress}}</view>
						</view>
						<view class="item_juli">{{item.startDistance}}km</view>
					</view>
					<view class="flex align-center margin-top justify-between">
						<view class="flex align-center">
							<view class="orgin"></view>
							<view class="item_addName">{{item.deliveryAddress}}</view>
						</view>
						<view class="item_juli">{{item.endDistance}}km</view>
					</view>
					<view class="margin-top flex align-center justify-between">
						<view class="flex align-center">
							<image src="/static/upload/person.png" style="width: 30rpx;height: 31rpx;"></image>
							<view style="margin-left: 16rpx;width: fit-content;" class="item_addName">
								{{item.appointmentNum}}人乘坐·{{item.appointmentType == 1 ? '独享' : '拼车'}}
							</view>
						</view>
						<view class="item_juli">订单里程{{item.kmDistance}}km</view>
					</view>
				</view>

				<view class="margin-tb-sm" style="width: 100%;height:1rpx;background: #F2F2F2;"></view>
				<view class="flex align-center justify-between padding-lr padding-bottom-sm">
					<view style="color: #FF2020;font-size: 32rpx;font-weight: bold;">
						<text>¥</text><text style="font-size: 42rpx;">{{item.driveMoney}}</text>
					</view>
					<view class="item_btn" @tap.stop="jiedan(item)">立即同行</view>
				</view>
			</view>
			<empty v-if="list.length == 0"></empty>
		</view>

		<view class="sos" @click="goTop()">
			<image src="/static/upload/goTop.png" mode=""></image>
		</view>

		<view class="sos" @click="goRefers()" style="bottom: 160rpx;">
			<image src="/static/upload/refers.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import empty from '@/components/empty'
	export default {
		components: {
			empty
		},
		data() {
			return {
				bjShow: false,
				typeSel: 0,
				page: 1,
				limit: 10,
				orderList: [],
				order: {
					shipAddress: ""
				},
				list: [],
				scrollTop: 0,
				driverRouteId: ''
			}
		},
		onLoad(d) {
			if (d.driverRouteId) {
				this.driverRouteId = d.driverRouteId;
			}
		},
		onShow() {
			if (this.driverRouteId) {
				this.getDetail();
			}
		},
		methods: {
			goXC(){
				uni.navigateTo({
					url: '/my/order/xcDetail?driverRouteId=' + this
						.driverRouteId
				})
			},
			goTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			goRefers() {
				if (this.driverRouteId) {
					this.$queue.showLoading('刷新中...')
					this.page = 1;
					this.getDetail();
				}
			},
			xdCheck(e) {
				this.scrollTop = 1;
				console.log('吸顶')
			},
			noXDCheck(e) {
				this.scrollTop = 0;
				console.log('no吸顶')
			},
			goOrder(e) {
				uni.navigateTo({
					url: '/pages/index/orderDet?indentNumber=' + e.ordersId + '&driverRouteId=' + this
						.driverRouteId
				})
			},
			jiedan(item) {
				let userId = this.$queue.getData('userId');
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定抢单吗？',
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定');
							that.$Request.postT(
									'/app/orders/takingOrders?ordersId=' +
									item.ordersId + '&userId=' + userId + '&driverRouteId=' + that
									.driverRouteId)
								.then(res => {
									if (res.code == 0) {
										uni.showToast({
											title: '接单成功',
											icon: 'none'
										})
										setTimeout(function() {
											uni.switchTab({
												url: '/pages/order/order'
											})
										}, 1000)
									} else {
										uni.showToast({
											title: res.msg,
											icon: 'none',
											duration: 1500
										})
									}
								});
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			closeSave() {
				this.bjShow = false;
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认取消发布行程吗？',
					cancelText: '取消',
					confirmText: '确认',
					complete: function(ret) {
						if (ret.confirm) {
							let data = {
								driverRouteId: that.driverRouteId
							}
							that.$Request.postT('/app/driverRoute/deleteDriverRoute', data).then(res => {
								if (res.code == 0) {
									that.$queue.showToast('取消成功！');
									setTimeout(d => {
										uni.navigateBack();
									}, 1500)
								} else {
									that.$queue.showToast(res.msg);
								}
							});

						}
					}
				})
			},
			editSave() {
				this.bjShow = false;
				uni.navigateTo({
					url: '/my/order/editDetail?driverRouteId=' + this.driverRouteId
				});
			},
			typeCheck(index) {
				this.typeSel = index;
				this.page = 1;
				this.taskData()
			},
			getDetail() {
				this.$Request.getT('/app/driverRoute/selectDriverRouteById?driverRouteId=' + this.driverRouteId).then(
					res => {
						if (res.code == 0) {
							this.order = res.data;
							this.taskData()
						}
					});
			},
			// 获取新任务数据
			taskData() {
				let userId = this.$queue.getData('userId');
				let shipProvince = this.order.shipProvince
				let shipCity = this.order.shipCity
				let orderType = 1;
				let sort = this.typeSel == 0 ? '' : this.typeSel;
				let data = {
					page: this.page,
					limit: 10,
					od: this.order.shipAddressLatitude,
					ol: this.order.shipAddressLongitude,
					appointmentType: this.appointmentType ? this.appointmentType : '',
					appointmentNum: '',
					driverRouteId: this.driverRouteId,
					driverUserId: userId,
					// shipProvince: shipProvince,
					// shipCity: shipCity,
					orderType: orderType,
					status: 2,
					sort: sort
				}
				if (shipProvince) {
				    data.shipProvince = shipProvince;
				}
				
				if (shipCity) {
				    data.shipCity = shipCity;
				}
				this.$Request.getT('/app/orders/selectOrdersList', data).then(res => {
					uni.hideLoading()
					if (res.code == 0) {
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list]
						}
					}
					uni.stopPullDownRefresh();
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F5F5;
	}

	.sos {
		width: 100rpx;
		height: 100rpx;
		position: fixed;
		bottom: 290rpx;
		right: 32rpx;
		z-index: 99999;

		image {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}
	}

	.type_item {
		width: 150rpx;
		height: 58rpx;
		background: #FFFFFF;
		border-radius: 29rpx;
		line-height: 58rpx;
		text-align: center;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #999999;
	}

	.showTopView {
		display: flex;
		justify-content: space-between;
		padding-bottom: 20rpx;
	}

	.type_item_sel {
		width: 150rpx;
		height: 58rpx;
		background: #00c18a;
		border-radius: 29rpx;
		line-height: 58rpx;
		text-align: center;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
	}

	.boxa {
		background: #FFFFFF;
		border-radius: 24rpx;
		margin-top: 30rpx;

		.item_time {
			font-family: Source Han Sans CN;
			font-weight: bold;
			font-size: 28rpx;
			color: #242424;
		}

		.item_chakan {
			margin-left: 20rpx;
			background: #F2F2F2;
			border-radius: 6rpx;
			text-align: center;
			padding: 6rpx 14rpx;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 24rpx;
			color: #999999;

		}

		.item_shunlu {
			width: 210rpx;
			height: 80rpx;
			background: #e8fbf6;
			border-radius: 0px 24rpx 0px 50rpx;
			text-align: center;
			line-height: 80rpx;
			font-family: Source Han Sans CN;
			font-weight: bold;
			font-size: 32rpx;
			color: #00c18a;
		}

		.addbox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 30rpx;
			height: 110rpx;
			border-radius: 16rpx;

		}

		.add_cont {
			display: flex;
			align-items: center;
		}

		.add_tit {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.bg {
			background: #F5F5F5;
		}

		.bgs {
			background: #F5F8FF;

		}

		.green {
			width: 16rpx;
			height: 16rpx;
			background: #00c18a;
			border-radius: 50%;
			margin-right: 20rpx;
		}

		.orgin {
			width: 16rpx;
			height: 16rpx;
			background: #FBAC04;
			border-radius: 50%;
			margin-right: 20rpx;
		}

		.btn {
			height: 78rpx;
			background: linear-gradient(87deg, #00c18a 0%, #e8fbf6 100%);
			border-radius: 4rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			margin: 30rpx 30rpx 0;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	.topbox_addview {
		width: 624rpx;
		min-height: 100rpx;
		background: #e8fbf6;
		border-radius: 16rpx;
		border: 1px solid #00c18a;
		margin: 0 auto;
		// display: flex;
		align-items: center;
		padding: 20rpx 30rpx;

		image {
			width: 6rpx;
			height: 24rpx;
			margin-left: 6rpx;
		}


		.topbox_title {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #151515;
		}
	}

	.item_btn {
		width: 150rpx;
		height: 58rpx;
		background: #00c18a;
		border-radius: 29rpx;
		text-align: center;
		line-height: 58rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
	}

	.topbox_addName {
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 28rpx;
		color: #1A1A1A;
		width: 520rpx;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.green {
		width: 16rpx;
		height: 16rpx;
		background: #1FC657;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.orgin {
		width: 16rpx;
		height: 16rpx;
		background: #FBAC04;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.top_view {
		width: 750rpx;
		height: 430rpx;
		background: linear-gradient(to bottom, #92eed4 70%, #c9fff0 90%);
		padding: 40rpx 0rpx;

		.top_title {
			font-family: Source Han Sans CN;
			font-weight: bold;
			font-size: 36rpx;
			color: #242424;
		}

		.top_rightview {
			position: relative;
			z-index: 9;
			width: 100rpx;
			text-align: right;

			image {
				width: 10rpx;
				height: 34rpx;
				margin-right: 20rpx;
				margin-top: 6rpx;
			}

			.top_popuView {
				position: absolute;
				top: 60rpx;
				right: 28rpx;
				z-index: 99;
				min-width: 220rpx;
				min-height: 171rpx;
				background: #FFFFFF;
				box-shadow: 0px 6rpx 12rpx 0px rgba(126, 126, 126, 0.27);
				border-radius: 24rpx 0px 24rpx 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #666666;
			}
		}
	}
</style>