<template>
	<view>
		<!-- 背景图 -->
		<view class="top">
			<image src="../icon/bg.png" mode="aspectFill"></image>
		</view>

		<view class="section_1">
			<view class="user">
				<view class="name">{{name}}</view>
				<view class="inner">
					<view class="text">工号：{{staff_num}}</view>
					<view class="text">部门：{{section}}</view>
				</view>
			</view>
			<view class="result">
				<uni-icons type="checkbox" size="100" color="#52C41A"></uni-icons>
				<view class="text">
					正常
				</view>
			</view>
		</view>

		<view class="section_2">
			<view class="btn_list">
				<view class="btn" @click="post_result(1)" :style="state?'':'background-color: #ccc;'">
					<view class="icon">
						<uni-icons type="download-filled" size="30" color="#fff"></uni-icons>
					</view>
					<view class="text">
						入矿
					</view>
				</view>
				<view class="btn" @click="post_result(2)" :style="state?'':'background-color: #ccc;'">
					<view class="icon">
						<uni-icons type="home-filled" size="30" color="#fff"></uni-icons>
					</view>
					<view class="text">
						堂食
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				staff_num: "",
				section: "",
				name: "",

				// 提交状态
				state: true
			};
		},
		onLoad() {
			function GetQueryString(name) {
				let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				if (window.location.hash.indexOf("?") < 0) {
					return null;
				}
				let r = window.location.hash.split("?")[1].match(reg);
				if (r != null) return decodeURIComponent(r[2]);
				return null;
			}

			// 调用方法
			// alert(GetQueryString("参数名1"));
			// alert(GetQueryString("参数名2"));
			this.staff_num = GetQueryString("staff_num")
			this.name = GetQueryString("name")
			this.section = GetQueryString("section_fullname")

		},
		methods: {
			post_result(type) {
				if (this.state) {
					console.log(type)

					this.$api.qr_code_scanningRecord({
						staff_num: this.staff_num,
						type: type
					}).then((res) => {
						uni.showToast({
							icon: "none",
							title: "记录成功"
						})
						this.state = false
					})

				} else {
					uni.showToast({
						icon: "none",
						title: "已经提交过了，请不要重复提交！"
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.top {
		z-index: -1;
		position: fixed;
		top: 0;
		left: 0;

		image {
			width: 750rpx;
			height: 746rpx;
		}
	}

	.section_1 {
		margin: 0 auto;
		margin-top: 50rpx;
		width: 700rpx;
		height: 640rpx;
		background-image: url('../icon/section_1.png');
		background-size: cover;

		.user {
			padding-top: 90rpx;
			padding-bottom: 30rpx;

			.name {
				font-size: 42rpx;
				font-weight: 700;
				text-align: center;
				margin-bottom: 20rpx;
			}

			.inner {
				display: flex;
				justify-content: space-between;
				line-height: 40rpx;

				box-sizing: border-box;
				padding: 0 100rpx;

				.text {
					font-size: 28rpx;
					color: #666;
				}
			}
		}

		.result {
			margin-top: 20rpx;
			text-align: center;

			.text {
				margin-top: 20rpx;
				color: #52C41A;
				font-size: 40rpx;
				font-weight: 700;
			}
		}
	}

	.section_2 {
		margin: -26rpx auto 0;
		box-sizing: border-box;
		padding: 50rpx 20rpx;
		width: 650rpx;
		height: 420rpx;
		background-image: url('../icon/section_2.png');
		background-size: cover;

		.btn_list {
			margin-top: 50rpx;
			display: flex;
			justify-content: space-around;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 270rpx;
				height: 100rpx;
				background-color: #009DD1;
				border-radius: 20rpx;

				.icon {
					margin-right: 20rpx;
				}

				.text {
					font-size: 46rpx;
					font-weight: 700;
					color: #fff;
				}
			}

			.btn:nth-child(2) {
				background-color: #FF7E00;
			}
		}
	}
</style>
