<template>
	<view style="min-height: 100vh;background-color: #f0f2f5;">
		<view style="padding: 40rpx;" v-html="content"></view>
		<view style="height: 200rpx;"></view>
		<view class="login-btn-box">
			<button class="main-center cross-center login-btn" :style="{'opacity':readUserAgreement?'1':'0.39'}"
				v-if="content" @click="login">
				<image style="width: 40rpx;height: 40rpx;margin-right: 10rpx;"
					src="https://t17.9026.com/web/statics/image/index/wxlogin.png" mode=""></image>同意
			</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				url:'',
				content: ''
			};
		},
		computed: {
			...mapState({
				readUserAgreement: state => state.user.readUserAgreement
			})
		},
		onReachBottom() {
			this.$store.commit('user/readUserAgreement', true);
		},
		onLoad(option) {
			this.url=option.url
			this.$request({
				url:this.$api.index.setting_list,
				method:'post'
			}).then(res=>{
				if(res.code===0){
					this.content=res.data.vice_agreement
				}
			})
		},
		methods: {
			login(e) {
				if (!this.readUserAgreement) {
					uni.showToast({
						title: '请阅读完用户隐私协议再登录',
						icon: 'none'
					})
					return
				}
				uni.navigateBack()
				// // #ifdef MP-TOUTIAO
				// this.getUserInfo(e);
				// // #endif
				// // #ifdef MP-WEIXIN
				// this.$user.getUserProfile(e).then(res => {
				// 	console.log(res)
				// 	this.getUserInfo(res);
				// }).catch(res => {
				// 	console.log(res)
				// })
				// // #endif
			},
			getUserInfo(e) {
				// #ifdef H5
				if (this.$jwx.isWechat()) {
					this.$request({
						url: this.$api.registered.url,
						method: 'get',
						data: {
							scope: 'snsapi_userinfo',
							response_type: 'code',
							url: `${window.location.href}`
						}
					}).then(res => {
						if (res.code === 0) {
							this.$storage.setStorageSync('_USER_SIGN', true);
							window.location.replace(res.data.url);
						} else {
							uni.navigateTo({
								url: '/pages/registered/sign'
							});
						}
					});
				} else {
					uni.navigateTo({
						url: '/pages/registered/sign'
					});
				}
				// #endif
				// #ifdef MP
				this.$store.commit('user/showLoginModal', false);
				const resolve = this.$user.getUserInfoResolve;
				const reject = this.$user.getUserInfoReject;
				this.$event.on(this.$const.EVENT_USER_LOGIN, true).then(() => {
					this.$jump({
						open_type: 'redirect',
						url:this.url
					})
				});
				// #ifdef MP-WEIXIN
				if (e.detail.errMsg !== 'getUserInfo:ok') {
					this.$store.commit('user/showLoginModal', true);
					return reject(e.detail.errMsg);
				} else {
					return resolve(e);
				}
				// #endif

				// #ifdef MP-ALIPAY
				my.getOpenUserInfo({
					success(openUserInfo) {
						const response = JSON.parse(openUserInfo.response);
						e.detail = {
							rawData: JSON.stringify(response.response),
							encryptedData: '',
							iv: '',
							signature: '',
						};
						return resolve(e);
					},
					fail(failE) {
						console.log('getOpenUserInfo:', failE);
					},
				});
				// #endif

				// #ifdef MP-BAIDU
				e.detail.rawData = JSON.stringify(e.detail.userInfo);
				e.detail.encryptedData = '';
				e.detail.iv = '';
				e.detail.signature = '';
				return resolve(e);
				// #endif

				// #ifdef MP-TOUTIAO
				uni.login({
					success() {
						uni.getUserInfo({
							success(result) {
								e.detail = {
									rawData: result.rawData,
									encryptedData: '',
									iv: '',
									signature: '',
								};
								return resolve(e);
							},
							fail(e) {
								console.log('getUserInfo fail:', e);
							},
						});
					},
					fail(e) {
						console.log('login fail:', e);
					},
				});
				// #endif
				// #endif
			},
		}
	}
</script>

<style lang="scss" scoped>
	.login-btn-box {
		position: fixed;
		bottom: 0rpx;
		left: 50%;
		transform: translateX(-50%);

		width: 100%;
		height: auto;
		padding: 10rpx 0;
		background-color: #fff;
	}

	.login-btn {
		margin: 0 auto;

		width: 678rpx;
		height: 82rpx;
		background: #A18253;

		border-radius: 2rpx;
		margin: 20rpx auto;
		text-align: center;
		font-size: 30rpx;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 82rpx;
	}
</style>
