<template>
	<view class="member-page">
		<image class="member-bg" src="https://imgs.agrimedia.cn/jiuye-haibao.png" mode="aspectFit"></image>
		<view class="page-overlay">
			<view class="back-btn" :style="{ top: statusBarHeight + 12 + 'px' }" @click="$tools.goBack(1)">
				<text class="back-arrow">‹</text>
			</view>
			<view class="action-wrap" :style="{ paddingBottom: safeBottom + 16 + 'px' }">
				<view class="agreement-row" @click="toggleAgreement">
					<view class="agreement-check" :class="{ 'agreement-check--active': agreedMemberProtocol }">
						<text v-if="agreedMemberProtocol" class="agreement-check-icon">✓</text>
					</view>
					<view class="agreement-text">
						<text>我已阅读</text>
						<text class="agreement-link" @click.stop="goMemberAgreement">《会员服务协议》</text>
					</view>
				</view>
				<view class="open-btn" :class="{ 'open-btn--disabled': !agreedMemberProtocol }" @click="handleOpenMember">开通会员</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 20,
				safeBottom: 0,
				agreedMemberProtocol: false
			}
		},
		onLoad() {
			const systemInfo = uni.getSystemInfoSync()
			this.statusBarHeight = systemInfo.statusBarHeight || 20
			const safeAreaInsets = systemInfo.safeAreaInsets || {}
			this.safeBottom = safeAreaInsets.bottom || 0
		},
		methods: {
			toggleAgreement() {
				this.agreedMemberProtocol = !this.agreedMemberProtocol
			},
			goMemberAgreement() {
				this.$tools.goNext('/pageOne/mes/agreement?name=' + encodeURIComponent('会员服务协议.docx') + '&docKey=memberAgreement')
			},
			handleOpenMember() {
				if (!this.agreedMemberProtocol) {
					uni.showToast({
						title: '请先勾选会员服务协议',
						icon: 'none'
					})
					return
				}
				uni.showToast({
					title: '支付正在对接中…',
					icon: 'none'
				})
			}
		}
	}
</script>

<style scoped>
	page {
		background: #1c0d0d;
	}

	.member-page {
		position: relative;
		width: 100%;
		min-height: 100vh;
		overflow: hidden;
		background: #f23f3e;
	}

	.member-bg {
		position: absolute;
		inset: 0;
		width: 100%;
		height: 100%;
	}

	.page-overlay {
		position: relative;
		min-height: 100vh;
	}

	.back-btn {
		position: fixed;
		left: 24rpx;
		width: 72rpx;
		height: 72rpx;
		border-radius: 36rpx;
		background: #f23f3e;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 10;
	}

	.back-arrow {
		color: #ffffff;
		font-size: 52rpx;
		line-height: 1;
		margin-top: -4rpx;
	}

	.action-wrap {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		padding-left: 32rpx;
		padding-right: 32rpx;
	}

	.agreement-row {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 24rpx;
		padding-left: 8rpx;
	}

	.agreement-check {
		width: 34rpx;
		height: 34rpx;
		border-radius: 50%;
		border: 2rpx solid rgba(255, 255, 255, 0.85);
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 16rpx;
		background: rgba(255, 255, 255, 0.08);
		flex-shrink: 0;
	}

	.agreement-check--active {
		background: #f8e2b7;
		border-color: #f8e2b7;
	}

	.agreement-check-icon {
		font-size: 22rpx;
		font-weight: 700;
		color: #8b4b17;
		line-height: 1;
	}

	.agreement-text {
		font-size: 26rpx;
		color: #ffffff;
		line-height: 1.6;
	}

	.agreement-link {
		color: #ffffff;
		text-decoration: underline;
		margin-left: 4rpx;
	}

	.open-btn {
		height: 96rpx;
		border-radius: 48rpx;
		background: linear-gradient(135deg, #f8e2b7 0%, #d8b06b 100%);
		color: #6b2b10;
		font-size: 32rpx;
		font-weight: 700;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 16rpx 32rpx rgba(0, 0, 0, 0.18);
	}

	.open-btn--disabled {
		background: linear-gradient(135deg, rgba(248, 226, 183, 0.55) 0%, rgba(216, 176, 107, 0.55) 100%);
		color: rgba(107, 43, 16, 0.7);
		box-shadow: none;
	}
</style>
