<template>
	<view>
		<view class="agreement" v-if="showAgreement">
			<u-checkbox v-model="agreement"></u-checkbox>
			<view class="agreement-text">
				我已阅读并同意 <text class="agreement-name" @click="onAgreement">{{agreementName}}</text>
			</view>
		</view>
		<u-popup v-model="popAgreement" closeable border-radius="14" mode="center" width="82%" height="86%">
			<slot />
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				popAgreement: false,
				agreement: this.value,
			}
		},
		props: {
			value: {
				type: Boolean,
				default: false
			},
			// 显示协议
			showAgreement: {
				type: Boolean,
				default: false
			},
			agreementName: {
				type: String,
				default: ''
			}
		},
		methods: {
			onAgreement() {
				this.popAgreement = true
			},
		},
		watch: {
			agreement(value) {
				this.$emit('input', value)
			}
		}
	}
</script>

<style scoped lang="scss">
	.agreement {
		display: flex;
		align-items: center;
		margin: 40rpx 0;

		.agreement-text {
			padding-left: 0rpx;
			color: $u-tips-color;
			font-size: 24rpx;
			margin-left: -20rpx;;

			text {
				color: #333333;
				cursor: pointer;
			}
			
			.agreement-name{
				color: #1890FF;
			}
		}
	}
</style>
