<template>
	<view class="container">
		<!-- 车牌号区域 -->
		<view class="box">
			<view class="left">车牌号</view>
			<view class="right">{{ info.car_number }}</view>
		</view>

		<!-- 人数区域 -->
		<view class="box">
			<view class="left">容量</view>
			<view class="right">{{ info.contain }}</view>
		</view>

		<!-- 发车日期区域 -->
		<view class="box">
			<view class="left">发车日期</view>
			<view class="right">{{ info.yy_date }}</view>
		</view>

		<!-- 发车时间区域 -->
		<view class="box">
			<view class="left">发车时间</view>
			<view class="right">{{ info.ci_time }}</view>
		</view>

		<!-- 扫码开始时间区域 -->
		<view class="box">
			<view class="left">扫码开始时间</view>
			<view class="right">{{ info.sm_start }}</view>
		</view>

		<!-- 扫码结束时间区域 -->
		<view class="box">
			<view class="left">扫码结束时间</view>
			<view class="right">{{ info.sm_end }}</view>
		</view>

		<!-- 预约截止时间区域 -->
		<view class="box">
			<view class="left">预约截止时间</view>
			<view class="right">{{ info.yy_end }}</view>
		</view>

		<!-- 路线区域 -->
		<view class="box">
			<view class="left">路线</view>
			<view class="right2">{{ info.route }}</view>
		</view>

		<!-- 终点站区域 -->
		<view class="box">
			<view class="left">站点</view>
			<view class="right2">{{ info.route_end }}</view>
		</view>

		<!-- 状态区域 -->
		<view class="box">
			<view class="left">状态</view>
			<view class="right">{{ info.state_str }}</view>
		</view>

		<!-- 提前一天预约区域 -->
		<view class="box">
			<view class="left">可否提前一天预约</view>
			<view class="right">{{ info.before_state == 0 ? '不可以' : '可以' }}</view>
		</view>

		<!-- 人员名单区域 -->
		<view class="list">
			<view class="list-title">
				<view class="list-title-left">人员名单（{{ typeList[result_state].text }}{{ listData.length }}人）</view>

				<picker style="width: 38%;" :range="typeList" range-key="text" @change="bindPickerChange">
					<view class="list-title-right">
						{{ typeList[result_state].text }}
						<view class="right-img"><img src="../../static/bottom.png" /></view>
					</view>
				</picker>
			</view>

			<view class="list-item" v-for="(item, index) in listData" :key="index">
				<view class="item-img"><img src="../../static/man.png" /></view>
				<view class="item-info">
					<view class="info-name">
						<view>{{ item.user_name }}</view>
					</view>
					<view class="info-mes">
						{{ item.user_zz }}
						<span>{{ item.yy_time }}</span>
					</view>
				</view>
				<view v-if="item.yy_state === '1'" class="item-type"><img src="../../static/subscribe.png" /></view>
				<view v-else class="item-type"><img src="../../static/pass2.png" /></view>
			</view>

			<!-- 无数据时展示的区域 -->
			<view class="list-nodata" v-if="listData.length == 0">
				<img src="../../static/no-bus.png" />
				<view>暂无数据</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'

import { myRequest } from '@/util/api.js'

import { isWeixin } from '@/util/isWeixin.js'

onLoad(options => {
	if (isWeixin()) {
		let userInfo = JSON.parse(uni.getStorageSync('bus-userInfo'))
		if (userInfo.user_zz !== '司机') {
			uni.redirectTo({
				url: '/pages/404/404?message=暂无权限'
			})
		} else {
			info.value = JSON.parse(options.info)
			idRef.value = info.value.id
			// 获取人员列表
			getData()
		}
	} else {
		uni.redirectTo({
			url: '/pages/404/404?message=请在微信客户端打开链接'
		})
	}
})

// 带过来的预约详情数据
const info = ref({})

// 参数id
const idRef = ref(null)

// 人员列表数组
const listData = ref([])

// 人员名单筛选状态
const result_state = ref(0)

const typeList = ref([
	{
		text: '全部',
		value: 0
	},
	{
		text: '已预约未上车',
		value: 1
	},
	{
		text: '已上车',
		value: 2
	}
])

// 获取人员名单请求
const getData = async () => {
	const res = await myRequest({
		url: '/appqueryAppointeds.action',
		data: {
			id: idRef.value,
			result_state: result_state.value
		}
	})
	// console.log(res)
	listData.value = res.data
}

// 下拉框的选择回调事件
const bindPickerChange = e => {
	result_state.value = e.detail.value
	getData()
}
</script>

<style lang="scss" scoped>
.container {
	background-color: #fff;

	.box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
		height: 98rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #e6e6e6;

		.left {
			flex: 1;
			color: #999999;
		}

		.right {
			flex: 1;
			display: flex;
			justify-content: flex-end;
		}
		.right2 {
			flex: 3;
			display: flex;
			justify-content: flex-end;
		}
	}

	.list {
		padding: 13rpx 30rpx;

		.list-title {
			display: flex;
			margin-top: 20rpx;
			height: 41rpx;
			color: #999999;
			font-size: 28rpx;

			.list-title-left {
				flex: 1;
			}

			.list-title-right {
				flex: 1;
				display: flex;
				justify-content: flex-end;
				color: #000;

				.right-img {
					margin-left: 27rpx;
					margin-top: -5rpx;
					width: 17rpx;
					height: 12rpx;

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

		.list-item {
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 29rpx 0 26rpx 0;
			height: 155rpx;
			border-bottom: 1rpx solid #e6e6e6;

			.item-img {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;

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

			.item-info {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;
				margin-left: 6rpx;
				height: 100rpx;

				.info-name {
					display: flex;
					align-items: center;
					font-size: 32rpx;

					.info-name-img {
						margin-left: 26rpx;
						width: 30rpx;
						height: 35rpx;

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

				.info-mes {
					font-size: 24rpx;
					color: #999999;

					span {
						margin-left: 26rpx;
						color: #a6a6a6;
					}
				}
			}

			.item-type {
				width: 104rpx;
				height: 41rpx;

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

		.list-nodata {
			padding: 50rpx 0;
			background-color: #fff;
			text-align: center;
			color: #999999;

			img {
				width: 500rpx;
			}
		}
	}
}
</style>
