<template>
	<view class="view-container" :style="themeColor">
		<!-- 加载状态 -->
		<view v-if="loading" class="loading-state">
			<view class="loading-spinner"></view>
		</view>

		<!-- 空状态 -->
		<view v-else-if="!content" class="empty-state">
			<view class="empty-icon">📄</view>
			<text class="empty-title">暂无内容</text>
			<text class="empty-desc">该协议内容暂未设置</text>
			<button class="empty-button" @click="getcontent">重新加载</button>
		</view>

		<!-- 内容状态 -->
		<rich-text v-else :nodes="content"></rich-text>

		<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>
	</view>
</template>

<script>
import htmlParser from '@/common/js/html-parser';
import scroll from '@/common/js/scroll-view.js';
export default {
	data() {
		return {
			content: '',
			type: '',
			uniacid: 0,
			loading: true
		};
	},
	mixins: [scroll],
	onLoad(option) {
		this.type = option.type
		this.uniacid = option.uniacid ? option.uniacid : 0

		this.isIphoneX = this.$util.uniappIsIPhoneX()
		this.getcontent()
	},
	onShow() {

	},
	methods: {
		getcontent() {
			this.loading = true
			// privacy  content
			var data = {
				type: this.type
			}
			if (this.uniacid > 0) data.uniacid = this.uniacid
			this.$api.sendRequest({
				url: '/api/config/agreement',
				data: data,
				success: res => {
					console.log(res.data.title)
					uni.setNavigationBarTitle({
						title: res.data.title
					})
					this.content = res.data.content
					this.loading = false
				},
				fail: () => {
					this.loading = false
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.view-container {
	padding: 40rpx;
	background: #ffffff;
	border-radius: 12rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06), 0 1rpx 2rpx rgba(0, 0, 0, 0.09);
	margin: 4rpx 20rpx;
	// max-width: 800rpx;
	margin-left: auto;
	margin-right: auto;
	min-height: 100vh;
	position: relative;
	overflow: hidden;
}

// 增强纸张纹理效果
.view-container::before {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="0.5" fill="%23f5f5f5" opacity="0.3"/><circle cx="75" cy="75" r="0.3" fill="%23f0f0f0" opacity="0.2"/><circle cx="15" cy="85" r="0.4" fill="%23f8f8f8" opacity="0.25"/><circle cx="85" cy="15" r="0.2" fill="%23ebebeb" opacity="0.3"/><path d="M0 0L200 200M200 0L0 200" stroke="%23f2f2f2" stroke-width="0.3" fill="none" opacity="0.15"/></pattern></defs><rect width="200" height="200" fill="url(%23grain)"/></svg>');
	opacity: 0.4;
	pointer-events: none;
}

// 加载状态样式
.loading-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 60vh;
	padding: 40rpx;

	.loading-spinner {
		width: 50rpx;
		height: 50rpx;
		border: 4rpx solid #f3f3f3;
		border-top: 4rpx solid #6c8ebf;
		border-radius: 50%;
		animation: spin 1s linear infinite;
		margin-bottom: 24rpx;
	}
}

@keyframes spin {
	0% {
		transform: rotate(0deg);
	}

	100% {
		transform: rotate(360deg);
	}
}

// 空状态样式
.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 60vh;
	padding: 40rpx;
	text-align: center;

	.empty-icon {
		font-size: 120rpx;
		margin-bottom: 32rpx;
		opacity: 0.6;
	}

	.empty-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #4e5969;
		margin-bottom: 16rpx;
	}

	.empty-desc {
		font-size: 24rpx;
		color: #8492a6;
		margin-bottom: 40rpx;
		line-height: 1.6;
	}

	.empty-button {
		width: 200rpx;
		height: 70rpx;
		line-height: 70rpx;
		background-color: #6c8ebf;
		color: white;
		border: none;
		border-radius: 35rpx;
		font-size: 26rpx;
		font-weight: 500;
		box-shadow: 0 2rpx 8rpx rgba(108, 142, 191, 0.3);
		transition: all 0.3s ease;

		&:hover {
			background-color: #5a78a8;
			transform: translateY(-2rpx);
			box-shadow: 0 4rpx 12rpx rgba(108, 142, 191, 0.4);
		}
	}
}

::v-deep .mescroll-totop {
	right: 27rpx !important;
	bottom: 120rpx !important;
}
</style>