<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" v-if="info.user_num !== '0'">人员名单({{ listData.length }}人)</view>
			<!-- 筛选区域 -->
			<view class="list-search" v-if="info.user_num !== '0'">
				<!-- 身份筛选区域 -->
				<picker style="width: 50%;" :range="statusList" range-key="text" @change="bindPickerChange($event, 1)">
					<view class="list-search-item">
						{{ statusList[result_status].text }}
						<view class="right-img"><img src="../../static/bottom.png" /></view>
					</view>
				</picker>
				<!-- 上车状态筛选区域 -->
				<picker style="width: 50%;" :range="typeList" range-key="text" @change="bindPickerChange($event, 2)">
					<view class="list-search-item2">
						{{ 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'

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

onLoad(options => {
	if (isWeixin()) {
		filterIdentity()
		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 result_status = ref(0)

const statusList = 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,
			userzz_state: result_status.value
		}
	})
	// console.log(res)
	listData.value = res.data
}

// 下拉框的选择回调事件
const bindPickerChange = (e, type) => {
	if (type === 1) {
		result_status.value = e.detail.value
	} else if (type === 2) {
		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-search {
			display: flex;
			padding: 20rpx 0;

			.list-search-item,
			.list-search-item2 {
				flex: 1;
				display: flex;
				justify-content: flex-start;

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

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

			.list-search-item2 {
				justify-content: flex-end;
			}
		}

		.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>
