<template>
	<view class="protocol_box">
		<view class="select" :class="{active: agree}" @click="agreeClick"><button class="mini-btn" type="warn"
				size="mini" open-type="agreePrivacyAuthorization">按钮</button></view>
		我已阅读并同意
		<view v-for="(item, index) in protocolArr" :key="index">

			<text @click="protocolClick(index)">{{protocolArr[index]}}</text>

			<span v-if="index < (protocolArr.length - 1)">{{"和"}}</span>

		</view>

	</view>
</template>

<script>
	export default {
		props: {
			// 是否同意
			agree: {
				type: Boolean,
				default: false
			},
			// 协议数组
			protocolArr: {
				type: Array,
				default: function() {
					return [];
				}
			},
			data() {
				return {
					resolvePrivacyAuthorization: null,
				}
			}
		},
		async created() {
			await this.checkPrivacySetting();
		},
		methods: {
			// 进入时获取隐私是否需要弹出隐私协议
			checkPrivacySetting() {
				if (uni.getPrivacySetting) {
					uni.getPrivacySetting({
						success: (res) => {
							console.log('getPrivacySetting', res);
							uni.onNeedPrivacyAuthorization((resolve) => {
								this.resolvePrivacyAuthorization = resolve;
							});
						},
						fail: () => {},
						complete: () => {},
					});
				}
			},
			// 是否同意勾选
			agreeClick() {
				console.log(this.agree, "2")
				if (this.agree == false) {
					this.resolvePrivacyAuthorization({
						buttonId: "agree-btn",
						event: "agree",
					});
				}
				this.$emit('click')
			},
			// protocolClick(tag) {
			// 	this.$emit('protocolClick', tag)
			// }
		}
	}
</script>




<style lang="scss" scoped>
	//主题色 #ea552d
	$themeColor: #49A992;



	.protocol_box {

		display: flex;
		flex-wrap: wrap;


		justify-content: center;
		align-items: center;

		margin-top: 40rpx;
		margin-left: 2%;
		width: 96%;
		font-size: 28rpx;
		color: #333333;
		font-size: 13px;




		.select {
			width: 36rpx;
			height: 36rpx;
			background-image: url("./ic_nor.png");
			background-position: center center;
			background-repeat: no-repeat;
			background-size: 100% auto;
			margin-right: 15rpx;
			margin-top: 2px;


			&.active {
				background-image: url("./ic_sel.png");
			}
		}

		text {


			color: $themeColor;
			font-size: 13px;

			white-space: pre-wrap;



		}


	}
</style>