<template>
	<view class="container">
		<!-- 顶部搜索框区域 -->
		<view class="search">
			<uni-search-bar bgColor="#fff" placeholder="请输入名字或院系" cancelButton="none" v-model="searchValue" @input="input"
				@clear="clear" @blur="blur">
			</uni-search-bar>
		</view>

		<view class="list">
			<!-- 分段器区域 -->
			<view class="control">
				<uni-segmented-control :current="current" :values="items" styleType="text" @clickItem="onClickItem"
					activeColor="#0082FC"></uni-segmented-control>
			</view>
			<!-- 列表区域 -->
			<view class="listbox">
				<!-- 每一个盒子区域 -->
				<view class="item" v-for="item in list" :key="item.id">
					<view class="left">
						<img :src="item.url">
					</view>
					<view class="center">
						<view class="name">
							{{item.name}}
						</view>
						<view class="college">
							{{item.college}}
						</view>
					</view>
					<view class="right">
						{{item.status==1?"正常":"缺卡"}}
					</view>
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchValue: "",
				items: ['打卡成功（50/150人）', '打卡失败（28/150人）'],
				current: 0,

				list: [],
				list2: [{
						id: 1,
						url: "../../static/ceshi.jpg",
						name: "张三",
						college: "文法学院",
						status: 1
					},
					{
						id: 2,
						url: "../../static/ceshi.jpg",
						name: "李四",
						college: "文法学院",
						status: 1
					},
					{
						id: 3,
						url: "../../static/ceshi.jpg",
						name: "王五",
						college: "文法学院",
						status: 1
					},
				],
				list3: [{
						id: 1,
						url: "../../static/ceshi.jpg",
						name: "伍六七",
						college: "文法学院",
						status: 2
					},
					{
						id: 2,
						url: "../../static/ceshi.jpg",
						name: "喜羊羊",
						college: "文法学院",
						status: 2
					},
					{
						id: 3,
						url: "../../static/ceshi.jpg",
						name: "灰太狼",
						college: "文法学院",
						status: 2
					},
				]
			}
		},
		onLoad(options) {
			this.list = this.list2
		},
		methods: {
			onClickItem(e) {
				console.log(e.currentIndex);
				if (e.currentIndex == 0) {
					this.list = this.list2
				} else {
					this.list = this.list3
				}
			},
			// 搜索框失焦回调
			blur(res) {
				uni.showToast({
					title: '搜索：' + res.value,
					icon: 'none'
				})
			},
			// 搜索框输入时的回调
			input(res) {
				console.log('----input:', res)
			},
			// 清除搜索框内容时的回调
			clear(res) {
				uni.showToast({
					title: 'clear事件，清除值为：' + res.value,
					icon: 'none'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-top: 20rpx;

		.search {
			width: 750rpx;
			height: 90rpx;
			border-radius: 171rpx;
			background-color: #fff;
		}

		.list {
			margin-top: 20rpx;
			width: 750rpx;
			background-color: #fff;

			.control {
				display: flex;
				flex-direction: column;
				justify-content: center;
				width: 750rpx;
				height: 102rpx;
			}

			.listbox {
				.item {
					display: flex;
					align-items: center;
					margin: 0 30rpx;
					height: 114rpx;
					border-bottom: 1rpx solid #E5E5E5;
					background-color: #fff;

					.left {
						flex: 1;
						display: flex;
						justify-content: center;
						align-items: center;

						img {
							width: 70rpx;
							height: 70rpx;
							border-radius: 35rpx;
						}
					}

					.center {
						flex: 5;
						display: flex;
						flex-direction: column;
						justify-content: space-evenly;
						margin-left: 10rpx;
						height: 90rpx;

						.name {
							font-size: 28rpx;
						}

						.college {
							font-size: 24rpx;
							color: #808080;
						}
					}

					.right {
						flex: 1;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 28rpx;
					}
				}
			}
		}
	}

	// 解决输入框不居中问题
	::v-deep .uni-searchbar {
		padding: 10rpx;
	}
</style>
