<template>
	<view class="control-index">
		<view class="control-off">
			<view class="control-off-icon">
				<uni-icons type="icon-yiping" custom-prefix="iconfont" color="#fff" size="20"></uni-icons>
			</view>
			<view class="control-off-label">{{title}}</view>
			<view class="control-off-btn">开门</view>
		</view>
		<view class="common-charts">
			<view class="common-chart-title">劳务考勤</view>
			<view class="control-week">
				<view class="control-week-item">
					<view class="control-week-icon">
						<uni-icons type="icon-jinchang" custom-prefix="iconfont" color="#fff" size="20"></uni-icons>
					</view>
					<view class="control-week-content">
						<view class="label">周进场</view>
						<view class="number">1280</view>
					</view>
				</view>
				<view class="line"></view>
				<view class="control-week-item orange">
					<view class="control-week-icon">
						<uni-icons type="icon-chuqu" custom-prefix="iconfont" color="#fff" size="20"></uni-icons>
					</view>
					<view class="control-week-content">
						<view class="label">周出场</view>
						<view class="number">1280</view>
					</view>
				</view>
			</view>
			<view class="common-chart-box">
				<u-echart ref="echart"></u-echart>
			</view>
		</view>
		<view class="control-list">
			<view class="control-title">
				<text class="label">进出记录</text>
				<view class="date" @click="open">
					<text class="date-value">{{filterDate[0]||'开始日期'}}</text>
					<text class="line">至</text>
					<text class="date-value">{{filterDate[1]||'结束日期'}}</text>
				</view>
			</view>
			<view class="fans-list">
				<view class="fans-item" v-for="(item,index) in list" :key="item.id">
					<image class="fans-avatar" :src="item.avatar" mode="aspectFill">
					</image>
					<view class="fans-content">
						<view class="fans-name">{{item.name}}</view>
						<view class="fans-organization">{{item.date}}</view>
					</view>
					<view class="control-state">
						<text class="in control-status" v-if="item.type === 1">进场</text>
						<text class="out control-status" v-else>出场</text>
					</view>
				</view>
			</view>
		</view>
		<uv-calendar ref="calendar" mode="range" @confirm="confirm"></uv-calendar>
	</view>
</template>

<script>
	import uEchart from './uEchart.vue'
	export default {
		props: ['title'],
		data() {
			return {
				filterDate: [],
				list: [{
					avatar: 'https://wx4.sinaimg.cn/mw690/006cSBLKly1gqqd7n1y77j30j60j676h.jpg',
					name: '林夕三',
					date: '2024-01-01 21:00:05',
					type: 2
				}, {
					avatar: 'https://wx4.sinaimg.cn/mw690/006cSBLKly1gqqd7n1y77j30j60j676h.jpg',
					name: '林夕三',
					date: '2024-01-01 18:06:05',
					type: 1
				}, {
					avatar: 'https://wx4.sinaimg.cn/mw690/006cSBLKly1gqqd7n1y77j30j60j676h.jpg',
					name: '林夕三',
					date: '2024-01-01 21:00:05',
					type: 2
				}, {
					avatar: 'https://wx4.sinaimg.cn/mw690/006cSBLKly1gqqd7n1y77j30j60j676h.jpg',
					name: '林夕三',
					date: '2024-01-01 18:06:05',
					type: 1
				}]
			}
		},
		components: {
			uEchart
		},
		mounted() {
			setTimeout(() => {
				this.$refs.echart.initCharts({
					type: 'column',
					categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月'],
					series: [{
						name: '进场人数',
						data: [86, 122, 93, 98, 91, 88, 95, 102, 110, 80]
					}],
					animation: true,
					background: "#FFFFFF",
					color: ["#1890FF"],
					padding: [15, 0, 0, 0],
					enableScroll: false,
					legend: {
						show: false
					},
					xAxis: {
						disableGrid: true
					},
					yAxis: {
						gridType: "dash",
						data: [{
							min: 0
						}]
					},
					extra: {
						column: {
							type: "group",
							width: 10,
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "custom",
							seriesGap: 5,
							linearOpacity: 0.5,
							barBorderCircle: true,
							customColor: [
								"#1890FF",
								"#EB88E2"
							]
						}
					}
				})
			}, 500)
		},
		methods: {
			open() {
				this.$refs.calendar.open();
			},
			confirm(e) {
				this.filterDate = e;
			}
		}
	}
</script>

<style lang="scss">
	.control-index {
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;

		.control-week {
			display: flex;
			margin-bottom: 40rpx;

			.line {
				width: 20rpx;
			}

			.control-week-item {
				background: #d4edff;
				display: flex;
				align-items: center;
				padding: 20rpx;
				flex: 1;
				width: 0;
				overflow: hidden;
				border-radius: 8rpx;

				&.orange {
					background: #fdd8b7;

					.control-week-icon {
						background: #ffa300;
					}

					.control-week-content {
						color: #ffa300;
					}
				}
			}

			.control-week-icon {
				width: 72rpx;
				height: 72rpx;
				border-radius: 8rpx;
				background: #4cb0fc;
				text-align: center;
				line-height: 72rpx;
			}

			.control-week-content {
				margin-left: 20rpx;
				color: #4cb0fc;
			}

			.label {
				font-size: 24rpx;
			}

			.number {
				font-size: 32rpx;
			}
		}

		.control-list {
			background: #fff;
			padding: 30rpx 30rpx 10rpx 30rpx;
			border-radius: 16rpx;
			box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
			margin-top: 30rpx;
		}

		.control-state {
			position: absolute;
			top: 20rpx;
			right: 20rpx;

			.control-status {
				padding: 6rpx 20rpx;
				color: #fff;
				border-radius: 8rpx;
				font-size: 24rpx;
				font-weight: 300;
			}

			.in {
				background: $uni-primary;
			}

			.out {
				background: $uni-warning;
			}
		}

		.fans-list {
			padding: 0;
		}

		.control-title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 30rpx;

			.label {
				font-size: 32rpx;
				font-weight: 500;
			}

			.date {
				font-size: 24rpx;
				font-weight: 300;
				color: $uni-secondary-color;
				border: 1px solid $uni-border-1;
				padding: 6rpx 10rpx;
				border-radius: 8rpx;
				width: 340rpx;
				display: flex;
				align-items: center;
			}

			.line {
				margin: 0 10rpx;
			}

			.date-value {
				flex: 1;
				width: 0;
				overflow: hidden;
				text-align: center;
			}
		}

		.control-off {
			background: #fff;
			padding: 30rpx;
			border-radius: 16rpx;
			box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
			display: flex;
			align-items: center;
		}

		.control-off-icon {
			width: 80rpx;
			height: 80rpx;
			background: $uni-primary;
			border-radius: 12rpx;
			text-align: center;
			line-height: 80rpx;
		}

		.control-off-label {
			flex: 1;
			font-size: 32rpx;
			font-weight: 500;
			margin-left: 20rpx;
		}

		.control-off-btn {
			width: 120rpx;
			height: 60rpx;
			border-radius: 60rpx;
			color: #fff;
			background: $uni-primary;
			text-align: center;
			line-height: 60rpx;
		}
	}
</style>