<template>
	<view class="container">
		<!-- 内容区域 -->
		<scroll-view class="content" scroll-y>
			<view class="agreement-list">
				<view class="agreement-item" v-for="(item, index) in agreementList" :key="index" @click="goToDetail(item)">
					<text class="agreement-name">{{ item.name }}</text>
					<text class="arrow-right">></text>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getServiceAgreementList, getAgreementTypeList } from '@/api/serviceAgreement'
export default {
	data() {
		return {
			agreementList: [
				{ id: 1, name: '用户服务协议', type: 'userService' },
				{ id: 2, name: '用户注册协议', type: 'userRegister' },
				{ id: 3, name: '隐私政策保护', type: 'privacy' }
			]
		}
	},
	onLoad() {
		this.loadAgreementList()
	},
	methods: {
		async loadAgreementList() {
			try {
				uni.showLoading({ title: '加载中...' })
				const [listRes, typeRes] = await Promise.all([
					getServiceAgreementList(),
					getAgreementTypeList().catch(() => ({ code: 0 }))
				])
				uni.hideLoading()
				
				if (listRes.code === 200 && listRes.data) {
					this.agreementList = Array.isArray(listRes.data) ? listRes.data : []
				} else {
					this.agreementList = []
				}
				
				// 如果有协议类型列表，可以用于筛选等功能
				if (typeRes.code === 200 && typeRes.data) {
					console.log('协议类型列表', typeRes.data)
				}
			} catch (e) {
				uni.hideLoading()
				console.error('加载服务协议列表失败', e)
				this.agreementList = []
			}
		},
		goBack() {
			uni.navigateBack()
		},
		goToDetail(item) {
			uni.navigateTo({
				url: `/pages_user/serviceAgreementDetail?type=${item.type}&id=${item.id}`
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background: #f5f5f5;
	display: flex;
	flex-direction: column;
}

.navbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx 24rpx;
	background: #fff;
	border-bottom: 1rpx solid #f0f0f0;
	
	.nav-left {
		width: 60rpx;
		
		.back-icon {
			font-size: 36rpx;
			color: #333;
			font-weight: bold;
		}
	}
	
	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
	
	.nav-right {
		display: flex;
		align-items: center;
		gap: 24rpx;
		width: 60rpx;
		justify-content: flex-end;
		
		.more-icon {
			font-size: 32rpx;
			color: #333;
		}
		
		.eye-icon {
			font-size: 32rpx;
			color: #333;
		}
	}
}

.content {
	flex: 1;
}

.agreement-list {
	background: #fff;
	margin: 24rpx;
	border-radius: 16rpx;
	overflow: hidden;
	
	.agreement-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 32rpx 24rpx;
		border-bottom: 1rpx solid #f0f0f0;
		
		&:last-child {
			border-bottom: none;
		}
		
		.agreement-name {
			font-size: 28rpx;
			color: #333;
		}
		
		.arrow-right {
			font-size: 32rpx;
			color: #999;
		}
	}
}
</style>











