<template>
	<view class="container">
		<!-- 每一个选项区域 -->
		<view class="box">
			<view class="name">
				规则名称：
			</view>
			<view class="val" @click="goPageRuleName">
				<view class="ele" v-if="ruleName=='未设置'">
					{{ruleName}}
				</view>
				<view class="ele black" v-else>
					{{ruleName}}
				</view>
				<view class="right">
					<img src="../../static/right.png">
				</view>
			</view>
		</view>

		<view class="box">
			<view class="name">
				考 勤 组：
			</view>
			<picker :value="index_group" :range="array_group" @change="changeSelect_group">
				<view class="val">
					<view class="ele" v-if="group=='未设置'">
						{{group}}
					</view>
					<view class="ele black" v-else>
						{{group}}
					</view>
					<view class="right">
						<img src="../../static/right.png">
					</view>
				</view>

			</picker>
		</view>

		<view class="box">
			<view class="name">
				打卡时间：
			</view>
			<view class="val" @click="goPagePunchTime">
				<view class="ele" v-if="time=='未设置'">
					{{time}}
				</view>
				<view class="ele black" v-else>
					{{time}}
				</view>
				<view class="right">
					<img src="../../static/right.png">
				</view>
			</view>
		</view>

		<view class="box">
			<view class="name">
				打卡地点：
			</view>
			<view class="val" @click="goPagePunchLocation">
				<view class="ele" v-if="place=='未设置'">
					{{place}}
				</view>
				<view class="ele black" v-else>
					{{place}}
				</view>
				<view class="right">
					<img src="../../static/right.png">
				</view>
			</view>
		</view>

		<view class="box">
			<view class="name">
				提前通知：
			</view>
			<picker :value="index" :range="array" @change="changeSelect">
				<view class="val">
					<view class="ele" v-if="value=='未设置'">
						{{value}}
					</view>
					<view class="ele black" v-else>
						{{value}}
					</view>
					<view class="right">
						<img src="../../static/right.png">
					</view>
				</view>
			</picker>
		</view>


		<!-- 确认按钮区域 -->
		<view class="button" @click="handleConfirm">
			确认
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 规则名称
				ruleName: "未设置",
				// 考勤组
				group: "未设置",
				// 打卡时间
				time: "未设置",
				// 打卡地点
				place: "未设置",
				// 提前通知
				value: "未设置",
				array: ['5分钟', '10分钟', '15分钟', '20分钟'],
				array_group: ['分组一分组一分组一分组一分组一分组一', '分组二', '分组三', '分组四'],
				index: 0,
				index_group: 0
			};
		},
		onLoad() {
			uni.$on('update', (data) => {
				this.ruleName = data
			})

		},
		onUnload() {
			uni.$off('update')
		},
		methods: {
			// 点击确认按钮回调
			handleConfirm() {
				if (this.ruleName == '未设置') {
					uni.showToast({
						title: "请设置规则名称",
						icon: 'none'
					})
					return
				}

				if (this.group == '未设置') {
					uni.showToast({
						title: "请设置考勤组",
						icon: 'none'
					})
					return
				}

				if (this.time == '未设置') {
					uni.showToast({
						title: "请设置打卡时间",
						icon: 'none'
					})
					return
				}

				if (this.place == '未设置') {
					uni.showToast({
						title: "请设置打卡地点",
						icon: 'none'
					})
					return
				}

				if (this.value == '未设置') {
					uni.showToast({
						title: "请设置提前通知时间",
						icon: 'none'
					})
					return
				}

				uni.showModal({
					title: '提示',
					content: '确定新增吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 提前通知选择框点击回调
			changeSelect(e) {
				let index = e.detail.value
				this.value = this.array[index]
			},
			// 考勤组选择框点击回调
			changeSelect_group(e) {
				let index = e.detail.value
				this.group = this.array_group[index]
			},
			// 点击规则名称跳转回调
			goPageRuleName() {
				uni.navigateTo({
					url: "/pages/ruleName/ruleName"
				})
			},
			// 点击打卡时间跳转回调
			goPagePunchTime() {
				uni.navigateTo({
					url: "/pages/punchTime/punchTime"
				})
			},
			// 点击打卡地点跳转回调
			goPagePunchLocation() {
				uni.navigateTo({
					url: "/pages/punchLocation/punchLocation"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		background-color: #fff;

		.box {
			display: flex;
			align-items: center;
			margin: 0 30rpx;
			width: 690rpx;
			height: 90rpx;
			font-size: 30rpx;
			border-bottom: 1rpx solid #CCCCCC;

			.name {
				flex: 1;
			}

			.val {
				flex: 3;
				display: flex;
				align-items: center;

				.ele {
					margin-right: 20rpx;
					display: inline-block;
					width: 460rpx;
					text-align: end;
					color: #A6A6A6;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.black {
					color: #000;
				}

				.right {
					width: 40rpx;
					display: inline-flex;
					justify-content: center;
					align-items: center;

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

		.button {
			margin: auto;
			margin-top: 52rpx;
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			font-size: 32rpx;
			font-weight: 500;
			color: #fff;
			border-radius: 16rpx;
			background-color: #3396FB;
		}
	}
</style>
