<template>
	<view class="page-agreement">
		<view class="popup-agreement">
			<view class="a-header">
				<text>隐私政策</text>
			</view>
			<view class="a-body">
				<scroll-view scroll-y="true" show-scrollbar="true">
					<view style="padding-bottom:25rpx">
						<text>尊敬的用户，您好</text>
					</view>
					<view>
						<text>为了加强对您个人信息的保护，根据最新法律法规要求，我们更新了隐私政策，请您仔细阅读并确认</text>
						<uni-link :href="protocols.protocolUrl" style="color: #3877F8">“隐私相关政策”</uni-link>
						<text>及</text>
						<uni-link :href="protocolf.protocolUrl" style="color: #3877F8">“用户注册协议”</uni-link>
						<text>我们将严格按照政策内容使用和保护您的个人信息，为您提供更好的服务，感谢您的信任。</text>
					</view>
				</scroll-view>
			</view>
			<view class="a-footer">
				<view @click="handleSure" class="a-btn-child">
					同意，继续使用
				</view>
				<view @click="handleReject" class="t-btn-child">
					<text>不同意，退出app</text>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
import { loadDevice, loadLocation, loadNetwork, loadUuid } from '@/utils/index.js'
export default {
	name: "Agreement",
	data() {
		return {
			userAgreement: '',
			protocols: {
				"protocolName": "隐私协议",
				"protocolUrl": "https://buyer.meimeiyouxin.com/article/detail?id=13717799279001600"
			},
			protocolf: {
				"protocolName": "用户服务协议",
				"protocolUrl": "https://buyer.meimeiyouxin.com/article/detail?id=13719927043339059"
			}
		}
	},
	async onShow() {
		await this.init()
	},
	methods: {
		// 拒绝授权
		handleReject() {
			plus.runtime.disagreePrivacy();
			if (uni.getSystemInfoSync().osName === 'ios') {
				plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
			} else if (uni.getSystemInfoSync().osName === 'android') {
				plus.runtime.quit();
			}
		},
		// 同意授权
		handleSure() {
			uni.setStorage({
				key: "m-agreement",
				data: 'true',
				success: function () {
					const platform = uni.getSystemInfoSync()
					if (platform.osName === 'ios') {
						loadNetwork()
						loadDevice()
						loadLocation()
						loadUuid()
					}
					uni.navigateBack({
						delta: 1
					})

				}
			})
		},
		// 初始化首页信息
		async init() {
			const self = this
			self.$request('/app/version/getSetting', 'POST').then(res => {
				const { protocol } = res.result
				if (protocol) {
					const protocolList = JSON.parse(protocol)
					protocolList.map((item) => {
						if (item.protocolName == '隐私协议') {
							self.protocols = item
						} else if (item.protocolName == '用户服务协议') {
							self.protocolf = item
						}
					})
				}
			}).catch(err => {
				console.log(err, '请求出错')
			})
		},
		Go(item) {
			const { protocolUrl, protocolName } = item
			const items = {
				name: protocolName,
				url: protocolUrl
			}
			uni.navigateTo({
				url: '/subPackage/webview/webview?mydata=' + encodeURIComponent(JSON.stringify(items))
			})
		}
	},

}
</script>

<style lang="less" src='./index.less'></style>
