<template>
	<view class="container">

		<!-- 顶部分段器区域 -->
		<view class="control" v-if="flag">
			<uni-segmented-control :current="current" :values="items" styleType="text" @clickItem="onClickItem"
				activeColor="#0082FC"></uni-segmented-control>
		</view>
		<!-- 头部月份区域 -->
		<view class="header">
			<view class="title">
				<view class="month">
					{{month}}月汇总
				</view>
				<view class="right" @click="goToDetail">
					<img src="../../static/right.png" alt="">
				</view>
			</view>
			<view class="state">
				<view class="err">
					<view class="number">
						0
					</view>
					<view class="mes">
						异常次数（次）
					</view>
				</view>
				<view class="success">
					<view class="number">
						1
					</view>
					<view class="mes">
						打卡成功（次）
					</view>
				</view>
			</view>
		</view>

		<!-- 日历区域 -->
		<view class="calendar">
			<view class="calendar_title">
				每日记录
				<span>（5月）</span>
			</view>

			<view class="calendar_body">
				<uni-calendar :showMonth="false" @change="change" :selected="list" />
			</view>

			<view class="calendar_foot" v-if="current==1">

				<!-- 每一条记录区域 -->
				<view class="foot_item" v-for="item in list2" :key="item.id">
					<view>
						{{item.msg}}
					</view>
					<view class="box">
						<view class="circular" v-if="item.status==1"></view>
						<view class="circular color" v-else></view>
						{{item.status==0?"未打卡":"已打卡"}}
						<span>{{item.time}}</span>
					</view>
				</view>
			</view>

			<!-- 环形图区域 -->
			<view class="progress" v-if="current==0">
				<view class="chart">
					<progressBar :progress_txt="progress_txt" :progress_total="progress_total" />
				</view>

				<view class="look">
					<view class="info">
						查看明细
					</view>
					<img src="../../static/right.png">
				</view>
			</view>
		</view>

		<!-- 异常人员名单区域 -->
		<view class="errPeople" v-if="current==0">
			<!-- 标题区域 -->
			<view class="e_header">
				<view class="left">
					异常人员名单
				</view>
				<view class="right">
					<view class="icon">
						<img src="../../static/notice.png">
					</view>
					<view class="info">
						通知
					</view>
				</view>
			</view>

			<!-- 选择时间区域 -->
			<view class="e_calendar">
				<!-- 双左箭头区域 -->
				<view class="double" @click="handleDoubleLeft">
					<img src="../../static/double_left.png">
				</view>
				<!-- 左箭头区域区域 -->
				<view class="single" @click="handleLeft">
					<img src="../../static/left.png">
				</view>
				<!-- 时间区域 -->
				<view class="time">
					{{year}}-{{comMonth}}
				</view>
				<!-- 双右箭头区域 -->
				<view class="single2" @click="handleRight">
					<img src="../../static/right2.png">
				</view>
				<!-- 右箭头区域 -->
				<view class="double" @click="handleDoubleRight">
					<img src="../../static/double_right.png">
				</view>
			</view>

			<view class="e_list">
				<view class="e_box" v-for="item in errList" :key="item.id">
					<view class="e_img">
						<img :src="item.peopleImg">
					</view>
					<view class="e_name">
						{{item.name}}
					</view>
					<view class="e_msg">
						未打卡{{item.num}}次
					</view>
				</view>

			</view>

		</view>

	</view>
</template>

<script>
	import progressBar from '../../components/chocolate-progress-bar/chocolate-progress-bar.vue'
	export default {
		components: {
			progressBar
		},
		data() {
			return {
				flag: false,
				list: [{
						date: "2022-11-20",
						info: ''
					},
					{
						date: "2022-11-21",
						info: '',
						data: {
							custom: '自定义信息',
							name: '自定义消息头'
						}
					},
					{
						date: "2022-11-22",
						info: ''
					}
				],
				list2: [{
						id: 1,
						msg: "规则：课间操考勤打卡09:00 - 09:15",
						status: 0,
						time: "09:25:25"
					},
					{
						id: 2,
						msg: "规则：考勤打卡19:00 - 20:15",
						status: 1,
						time: "19:25:25"
					},
				],
				month: null,
				items: ['团队统计', '我的统计'],
				current: 1,
				year: null,
				month: null,
				errList: [{
						id: 1,
						peopleImg: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13579194276%2F1000&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671596163&t=52c9def84f0fa7832bfc5824364917e0",
						name: "程佳欢",
						num: 20
					},
					{
						id: 2,
						peopleImg: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13579194276%2F1000&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671596163&t=52c9def84f0fa7832bfc5824364917e0",
						name: "程欢",
						num: 10
					},
					{
						id: 3,
						peopleImg: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13579194276%2F1000&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671596163&t=52c9def84f0fa7832bfc5824364917e0",
						name: "张三",
						num: 30
					},
					{
						id: 4,
						peopleImg: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13579194276%2F1000&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671596163&t=52c9def84f0fa7832bfc5824364917e0",
						name: "李四",
						num: 30
					},
				],
				progress_txt: 50,
				progress_total: 70
			};
		},
		onLoad() {
			this.getTime()
			if (this.flag) {
				this.current = 0
			}
		},
		computed: {
			comMonth() {
				if (this.month) {
					let month = this.month < 10 ? '0' + this.month : this.month
					console.log(month);
					return month
				}
			}
		},
		methods: {
			// 获取当前年份
			getTime() {
				let date = new Date()
				let year = date.getFullYear()
				let month = date.getMonth() + 1
				this.year = year
				this.month = month
			},
			// 点击日历日期回调
			change(e) {
				console.log('change 返回:', e)
			},
			onClickItem(e) {
				console.log(e.currentIndex);
				this.current = e.currentIndex
				// if (e.currentIndex == 0) {
				// 	this.list = this.list2
				// } else {
				// 	this.list = this.list3
				// }
			},
			// 跳转统计详情页面
			goToDetail() {
				if (this.current == 1) {
					uni.navigateTo({
						url: `/pages/statDetail/statDetail?month=${this.month}`
					})
				} else {
					uni.navigateTo({
						url: "/pages/particulars/particulars"
					})
				}
			},
			handleDoubleLeft() {
				if (this.year <= 2000) {
					uni.showToast({
						title: "不能选择2000年之前",
						icon: 'none'
					})
				} else {
					this.year -= 1
				}
			},
			handleLeft() {
				if (this.month <= 1) {
					if (this.year <= 2000) {
						uni.showToast({
							title: "不能选择2000年之前",
							icon: 'none'
						})
					} else {
						this.year -= 1
						this.month = 12
					}
				} else {
					this.month -= 1
				}
			},

			handleRight() {
				if (this.month >= 12) {
					if (this.year >= 2025) {
						uni.showToast({
							title: "不能选择2025年之后",
							icon: 'none'
						})
					} else {
						this.year += 1
						this.month = 1
					}
				} else {
					this.month += 1
				}
			},
			handleDoubleRight() {
				if (this.year >= 2025) {
					uni.showToast({
						title: "不能选择2025年之后",
						icon: 'none'
					})
				} else {
					this.year += 1
				}
			},
		}
	}
</script>

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

		.control {
			margin-bottom: 20rpx;
			width: 750rpx;
			height: 90rpx;
			background-color: #fff;
		}

		.header {
			margin: 0 auto;
			width: 690rpx;
			height: 236rpx;
			background-color: #fff;

			.title {
				display: flex;
				height: 92rpx;

				.month {
					flex: 8;
					margin: 30rpx 0 0 30rpx;
					font-size: 32rpx;
					font-weight: 500
				}

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

					img {
						width: 15rpx;
						height: 30rpx
					}
				}
			}

			.state {
				display: flex;
				height: 144rpx;

				.err {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.number {
						font-size: 46rpx;
						font-weight: 700;
					}

					.mes {
						font-size: 28rpx;
						color: #999999;
					}
				}

				.success {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;

					.number {
						font-size: 46rpx;
						font-weight: 700;
					}

					.mes {
						font-size: 28rpx;
						color: #999999;
					}
				}
			}
		}

		.calendar {
			margin: 0 auto;
			margin-top: 30rpx;
			width: 693rpx;
			background-color: #fff;

			.calendar_title {
				padding-left: 30rpx;
				height: 100rpx;
				line-height: 100rpx;
				font-size: 32rpx;
				font-weight: 500;

				span {
					font-size: 26rpx;
					color: #999999
				}
			}

			.calendar_body {
				height: 690rpx;
				background-color: skyblue;
			}

			.calendar_foot {
				padding: 0 30rpx;

				.foot_item {
					box-sizing: border-box;
					padding: 30rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-evenly;
					height: 130rpx;
					font-size: 24rpx;
					color: #808080;

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

						.circular {
							margin-right: 18rpx;
							width: 12rpx;
							height: 12rpx;
							border-radius: 6rpx;
							background-color: #31C20E;
						}

						.color {
							background-color: #999999;
						}

						span {
							margin-left: 18rpx;
						}
					}
				}
			}

			.progress {
				position: relative;
				display: flex;
				justify-content: center;
				padding: 0 30rpx;
				height: 121px;

				.chart {
					margin-top: 20rpx;
					width: 170px;
					height: 100%;
				}

				.look {
					position: absolute;
					top: 40rpx;
					right: 36rpx;
					display: flex;
					align-items: center;
					width: 150rpx;
					height: 42rpx;

					.info {
						margin-right: 15rpx;
						font-size: 28rpx;
						color: #A6A6A6;
					}

					img {
						width: 16rpx;
						height: 24rpx;
					}
				}
			}
		}

		.errPeople {
			margin: 0 auto;
			margin-top: 32rpx;
			width: 690rpx;
			border-radius: 7rpx;
			background-color: #fff;

			.e_header {
				display: flex;
				align-items: center;
				width: 690rpx;
				height: 121rpx;

				.left {
					flex: 1;
					margin-left: 30rpx;
					font-size: 32rpx;
					font-weight: 500;
				}

				.right {
					flex: 1;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					margin-right: 32rpx;

					.icon {
						margin-right: 10rpx;
						width: 26rpx;
						height: 26rpx;
						line-height: 26rpx;

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

					.info {
						width: 56rpx;
						height: 41rpx;
						font-size: 28rpx;
						color: #2A82E4;
					}
				}
			}

			.e_calendar {
				display: flex;
				justify-content: flex-end;
				align-items: center;

				.double {
					margin-right: 30rpx;
					width: 40rpx;
					height: 40rpx;

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

				.single {
					width: 40rpx;
					height: 40rpx;

					img {
						width: 80%;
						height: 70%;
					}
				}

				.single2 {
					margin-right: 30rpx;
					width: 40rpx;
					height: 40rpx;

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

				.time {
					width: 180rpx;
					height: 44rpx;
					font-size: 32rpx;
					text-align: center;
				}
			}

			.e_list {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-evenly;
				align-items: center;
				margin-top: 20rpx;
				padding: 30rpx;
				width: 630rpx;

				.e_box {
					display: flex;
					flex-direction: column;
					justify-content: space-evenly;
					align-items: center;
					margin-bottom: 20rpx;
					width: 180rpx;
					height: 190rpx;

					.e_img {
						width: 100rpx;
						height: 100rpx;

						img {
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
					}

					.e_name {
						font-size: 28rpx;
					}

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

	// 修改选中日期盒子圆角
	::v-deep .uni-calendar-item--isDay {
		border-radius: 50rpx;
	}

	::v-deep .uni-calendar-item--checked {
		border-radius: 50rpx;
	}
</style>
