<template>
	<view class="container">
		<!-- 分段器区域 -->
		<uni-segmented-control :current="activeCurrent" :values="controlList" @clickItem="onClickItem" styleType="text" activeColor="#0061FF"></uni-segmented-control>
		<!-- 预约记录区域 -->
		<view class="body">
			<!-- 每一条预约记录区域 -->
			<view class="body_box" v-for="item in list" :key="item.id" @click="handleClick(item)">
				<view class="box_title">
					<view class="title_msg">
						<view class="msg_name">{{ item.name }}</view>
						<view class="msg_time">/{{ item.time }}</view>
					</view>
					<view class="title_type" v-if="item.type == '待审核'">{{ item.type }}</view>
					<view class="title_type red" v-if="item.type == '已拒绝'">{{ item.type }}</view>
					<view class="title_type green" v-if="item.type == '已推送'">{{ item.type }}</view>
				</view>
				<view class="box_info">
					<view class="info_box">
						<view class="box_key">来访时间</view>
						<view class="box_value">{{ item.time }}</view>
					</view>
					<view class="info_box">
						<view class="box_key">访问事由</view>
						<view class="box_value">{{ item.desc }}</view>
					</view>
				</view>
				<view class="box_btn" v-if="item.type == '待审核'">
					<view class="button" @click.stop="handleCancel">取消预约</view>
				</view>
			</view>
		</view>

		<!-- 详情弹窗区域 -->
		<uni-popup ref="popup" type="center" :is-mask-click="false">
			<view class="popup_box">
				<!-- 弹窗标题区域 -->
				<view class="pop_header">
					预约详情
					<view class="header_icon" @click="closePop">×</view>
				</view>

				<!-- 弹窗详细信息区域 -->
				<view class="pop_info">
					<view class="info_key">状态：</view>
					<view class="info_value blue" v-if="popObj.type == '待审核'">{{ popObj.type }}</view>
					<view class="info_value red" v-if="popObj.type == '已拒绝'">{{ popObj.type }}</view>
					<view class="info_value green" v-if="popObj.type == '已推送'">{{ popObj.type }}</view>
				</view>

				<view class="pop_info">
					<view class="info_key">访客姓名：</view>
					<view class="info_value">{{ popObj.name }}</view>
				</view>

				<view class="pop_info">
					<view class="info_key">访客手机号：</view>
					<view class="info_value">136562262626</view>
				</view>

				<view class="pop_info">
					<view class="info_key">来访时间：</view>
					<view class="info_value">{{ popObj.time }}</view>
				</view>

				<view class="pop_info">
					<view class="info_key">证件号：</view>
					<view class="info_value">2662626262626262626</view>
				</view>

				<view class="pop_info">
					<view class="info_key">访问事由：</view>
					<view class="info_value">{{ popObj.desc }}</view>
				</view>

				<view class="pop_info">
					<view class="info_key">车牌号：</view>
					<view class="info_value">无</view>
				</view>

				<view class="pop_info">
					<view class="info_key">同行人数：</view>
					<view class="info_value">无</view>
				</view>

				<view class="pop_info">
					<view class="info_key">受访学生：</view>
					<view class="info_value">张三（262626）</view>
				</view>
			</view>
		</uni-popup>

		<!-- 底部导航栏区域 -->
		<tabber />
	</view>
</template>

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

// 分段器当前索引
const activeCurrent = ref(0)
// 分段器数组
const controlList = ['全部', '待审核', '已拒绝', '已推送']
// 预约记录数组
const list = ref([
	{
		id: 1,
		name: '张三',
		time: '2023-12-13  10:23',
		type: '待审核',
		desc: '给孩子送棉被'
	},
	{
		id: 2,
		name: '张三',
		time: '2023-12-13  10:23',
		type: '已拒绝',
		desc: '给孩子送棉被'
	},
	{
		id: 3,
		name: '张三',
		time: '2023-12-13  10:23',
		type: '已推送',
		desc: '给孩子送棉被'
	}
])
// 弹窗元素标记
const popup = ref(null)

// 弹窗详细信息
const popObj = ref({})

onLoad(() => {})

// 点击每一条预约记录时的回调
const handleClick = (item) => {
	popObj.value = item
	popup.value.open()
}

// 切换分段器时的回调
const onClickItem = (e) => {
	console.log(e)
}

// 点击取消按钮回调
const handleCancel = () => {
	console.log('取消')
}

// 点击弹窗 x 图标时的回调
const closePop = () => {
	popup.value.close()
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background-color: #f1f6fe;

	.body {
		padding: 0 20rpx;

		.body_box {
			padding: 0 20rpx 0 30rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			width: 710rpx;
			border-radius: 15rpx;
			background-color: #fff;

			.box_title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 83rpx;
				font-size: 28rpx;
				border-bottom: 1rpx solid #e6e6e6;

				.title_msg {
					display: flex;
					align-items: center;

					.msg_name {
						font-weight: bold;
					}

					.msg_time {
						margin-left: 15rpx;
						color: #a6a6a6;
						font-size: 24rpx;
					}
				}

				.title_type {
					color: #0061ff;
				}

				.red {
					color: #d43030;
				}

				.green {
					color: #00baad;
				}
			}

			.box_info {
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;
				height: 140rpx;

				.info_box {
					display: flex;
					align-items: center;
					font-size: 24rpx;

					.box_key {
						color: #a6a6a6;
					}

					.box_value {
						margin-left: 95rpx;
					}
				}
			}

			.box_btn {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				height: 130rpx;
				border-top: 1rpx solid #e6e6e6;

				.button {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 160rpx;
					height: 80rpx;
					color: #0061ff;
					font-size: 28rpx;
					border-radius: 10rpx;
					border: 1rpx solid #0061ff;
				}
			}
		}
	}

	.popup_box {
		padding-bottom: 50rpx;
		width: 710rpx;
		border-radius: 22rpx;
		background-color: #fff;

		.pop_header {
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			height: 94rpx;
			font-size: 28rpx;
			border-bottom: 1rpx solid #e6e6e6;

			.header_icon {
				position: absolute;
				top: 18rpx;
				right: 25rpx;
				font-size: 40rpx;
			}
		}

		.pop_info {
			display: flex;
			align-items: center;
			margin-top: 22rpx;
			padding: 0 35rpx;
			font-size: 28rpx;

			.info_key {
				color: #999999;
			}

			.info_value {
			}

			.blue {
				color: #0061ff;
			}

			.red {
				color: #d43030;
			}

			.green {
				color: #00baad;
			}
		}
	}
}

// 修改顶部分段器样式
::v-deep {
	.segmented-control {
		height: 100rpx;
		background-color: #fff;
	}
}
</style>
