<template>
	<view style="height: 100%;">
		<view class="title">
			应到：{{list.length}}人
		</view>
		<view style="padding: 26rpx;overflow: hidden;">
			<view class="cate">
				<view class="cateList">
					<view v-for="item in cateList" :class="{active:item.value == cate}" :key="item.value" class="item"
						@click="cateItemClick(item)">
						{{item.label}}({{item.num}})
					</view>
				</view>
			</view>
		</view>
		<view style="height:calc(100% - 200rpx);overflow: auto;">
			<view class="list">
				<template v-for="(item, index) in list">
					<view class="item" @click="popupShow(item)" :key="index" v-show="cateList.length&&cateList[cate].show(item)">
						<view class="right">
							<image src="@/static/image/test/image2.png" mode="aspectFill"
								style="width: 160rpx;height: 160rpx;border-radius:10rpx"></image>
							<view class="des">
								<view class="top">
									<view class="status"
										:style="{backgroundColor:cate == 0?'#0FAF76':cate == 1?'#EF2D2D':'#F49D19' }">
										{{cateList.find(e=>e.value == cate)?cateList.find(e=>e.value == cate).label:''}}
									</view>
									<view class="name">
										{{item.name}}
									</view>
								</view>
								<view class="depart">
									系部：{{item.majorName}}
								</view>
								<view class="bottom">
									<view class="major">专业：{{item.depName}}</view>
									<view class="class">班级：{{item.personSetName}}</view>
								</view>
							</view>
						</view>
					</view>
				</template>
			</view>
		</view>
		<u-popup :show="show" mode="center" :round="10">
			<view class="popupInfo">
				<image src="/static/image/test/image.png" mode="widthFix" style="width: 480rpx;border-radius:10rpx">
				</image>
				<view class="top">
					<view class="status" :style="{backgroundColor:cate == 0?'#0FAF76':cate == 1?'#EF2D2D':'#F49D19' }">
						{{cateList.find(e=>e.value == cate)?cateList.find(e=>e.value == cate).label:''}}
					</view>
					<view class="name">
						{{popupInfo.name}}
					</view>
				</view>
				<view class="depart">
					系部：{{popupInfo.majorName}}
				</view>
				<view class="bottom">
					<view class="major">专业：{{popupInfo.depName}}</view>
					<view class="class">班级：{{popupInfo.personSetName}}</view>
				</view>
				<view class="closeBox">
					<image @click="show = false" src="/static/image/close.png" class="close"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		detail,
		page
	} from '@/api/work/rollCall.js'
	export default {
		data() {
			return {
				list: [],
				alarmList: [],
				cateList: [],
				cate: 0,
				checkboxValue: [],

				show: false,
				popupInfo: {},
			}
		},
		async mounted() {
			const {
				personSetId,
				taskId
			} = this.options
			// 班级人员
			if (personSetId) {
				await detail({
					personSetId,
					pageSize: 1000,
					pageNum: 1
				}).then(res => {
					if (res.code != 200) return
					this.list = res.data.list
				})
			}
			// 监控行为列表
			if (taskId) {
				page({
					taskId,
					pageSize: 1000,
					pageNum: 1
				}).then(res => {
					if (res.code != 200) return
					this.alarmList = res.data.list
					this.list = this.list.map(e => {
						e.alarmTypes = []
						// alarmType：lie_on_table 趴桌子    class_room_call 点名(实到)
						let arr = this.alarmList.filter(e1 => e1.personId == e.personId)
						e.alarmTypes = arr.map(e=>e.alarmType)
						return e
					})
					this.cateList = [{
							value: 0,
							label: '实到',
							show:(item)=>item.alarmTypes.includes('class_room_call'),
							num: this.list.filter(e=>e.alarmTypes.includes('class_room_call')).length,
						},
						{
							value: 1,
							label: '未到',
							show:(item)=>!item.alarmTypes.includes('class_room_call'),
							num: this.list.filter(e=>!e.alarmTypes.includes('class_room_call')).length
						},
						{
							value: 2,
							label: '趴桌子',
							show:(item)=>item.alarmTypes.includes('lie_on_table'),
							num: this.list.filter(e=>e.alarmTypes.includes('lie_on_table')).length,
						},
					]
				})
			}
		},
		methods: {
			cateItemClick(item) {
				this.cate = item.value
			},
			popupShow(item) {
				this.popupInfo = item
				this.show = true
			}
		}
	}
</script>

<style scoped lang="scss">
	.popupInfo {
		padding: 30rpx;
		box-sizing: border-box;
		position: relative;

		.top {
			margin-top: 20rpx;
			font-size: 32rpx;
			display: flex;

			.status {
				display: inline-block;
				font-size: 24rpx;
				line-height: 46rpx;
				color: #fff;
				padding: 0 12rpx;
				border-radius: 8rpx;
				margin-right: 12rpx;
			}

			.name {
				font-size: 32rpx;
				font-weight: 700;
			}
		}

		.depart {
			margin-top: 22rpx;
			font-size: 26rpx;
		}

		.bottom {
			font-size: 26rpx;
			margin-top: 18rpx;
			display: flex;
			justify-content: space-between;
			margin-bottom: 12rpx;

			.major {}

			.class {}
		}

		.closeBox {
			width: 100%;
			position: absolute;
			left: 0;
			bottom: -98rpx;
			text-align: center;

			.close {
				width: 60rpx;
				height: 60rpx;
			}

		}
	}

	.title {
		display: flex;
		color: #333333;
		padding: 26rpx;
		background: #fff;
		border-top: 1rpx solid rgba(0, 0, 0, 0.03);
		font-size: 30rpx;
	}

	.cate {
		font-size: 28rpx;
		overflow-x: auto;

		.cateList {
			display: flex;
			width: auto;

			.item {
				background-color: #fff;
				border-radius: 37rpx;
				padding: 0 56rpx;
				line-height: 74rpx;
				margin-right: 30rpx;
				white-space: nowrap;
				color: #333;

				&.active {
					background-color: #2388FF;
					color: #fff;
				}
			}
		}
	}

	.list {
		padding: 0 26rpx;
		margin-bottom: 60rpx;

		.item {
			display: flex;
			margin-bottom: 28rpx;

			&:last-child {
				margin-bottom: 0;
			}

			.right {
				padding: 30rpx;
				flex: 1;
				background-color: #fff;
				border-radius: 18rpx;
				display: flex;

				.des {
					flex: 1;
					padding-left: 24rpx;
					font-size: 26rpx;
					color: #333;

					.top {
						font-size: 32rpx;
						display: flex;

						.status {
							display: inline-block;
							font-size: 24rpx;
							line-height: 46rpx;
							color: #fff;
							padding: 0 12rpx;
							border-radius: 8rpx;
							margin-right: 12rpx;
						}

						.name {
							font-size: 32rpx;
							font-weight: 700;
						}
					}

					.depart {
						margin-top: 28rpx;
						font-size: 26rpx;
					}

					.bottom {
						font-size: 26rpx;
						margin-top: 18rpx;
						display: flex;
						justify-content: space-between;

						.major {}

						.class {}
					}
				}
			}
		}
	}
</style>