<template>
	<view class="content">
		<view class="container">
			<view class="my-header">
				<view class="my-icons"> </view>
				<view class="my-text"></view>
				<view class="my-icons"></view>
			</view>
			<view class="top-box"></view>
			<!-- 顶部区域 -->

			<!-- #ifdef MP-WEIXIN -->
			<button class="dl-box" open-type='getPhoneNumber' @getphonenumber="getPhone">手机号快捷登录</button>
			<!-- #endif -->
			<!-- #ifdef MP-ALIPAY -->
			<button class="dl-box" open-type="getPhoneNumber" @getphonenumber="getUserLogin">手机号快捷登录</button>
			<!-- #endif -->
			<button class="kk-box" @click="goback">我再看看</button>
			<view class="dbottom">
				<view class="quanzi" v-if="qindex == false " @click="qindex =! qindex"></view>
				<view class="lanquanzi" v-if="qindex == true" @click="qindex =! qindex"><u-icon name="checkbox-mark"
						color="#ffffff" size="14"></u-icon></view>
				<text>请仔细阅读</text>
				<text class="lan">《用户协议》</text>
				<text>和</text>
				<text class="lan">《隐私政策》</text>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request'
	export default {
		data() {
			return {
				title: '',
				qindex: false,
				baseUrl: this.$baseUrl,
				appltType: uni.getStorageSync("appltType"),
			}
		},
		onLoad() {
			console.log(this.$baseUrl);

		},
		components: {},
		methods: {
			// 获取支付宝userid
			getUserLogin(e) {
				// if (this.qindex == false) {
				// 	uni.showToast({
				// 		icon: "none",
				// 		title: "请阅读并勾选用户协议",
				// 		duration: 2000
				// 	})
				// 	return;
				// }
				console.log(e)

				let _this = this;
				my.getAuthCode({
					scopes: 'auth_base',
					success: res => {
						const authCode = res.authCode;
						console.log(res)
						request({
							url: "clientApi/sign/alipayLogin/getUserid",
							method: 'post',
							data: {
								authCode: authCode,
								storeId: 0,
								staffId: "",
								phone: "18457621459",
							},
						}).then((resp) => {
							console.log(resp)
							if (resp.code == 200) {

								uni.setStorageSync('App-Token', resp.data.token);
								uni.setStorageSync('chainStoreId', resp.data.chainStoreId);

								uni.navigateTo({
									url: '/pages/index/index'
								})
							}
							console.log("swq", uni.getStorageSync(
								'App-Token'));
						})
					},
					fail: err => {
						console.log('my.getAuthCode 调用失败', err)
					}
				});
			},
			wxlogin() {},
			getPhone(e) {
				let that = this
				// if (this.privacyPolicyChecked == false) {
				// 	uni.showToast({
				// 		icon: "none",
				// 		title: "请阅读并勾选用户协议",
				// 		duration: 2000
				// 	})
				// 	return;
				// }
				console.log(e)
				uni.login({
					provider: 'weixin',
					success(res) {
						if (res.code) {
							uni.setStorageSync('c1', res.code);
							console.log('weixin', res.code);
						} else {
							console.log('登录失败！' + res.errMsg)
						}

						// console.log(e);
						uni.checkSession({
							success: () => {
								uni.request({
									url: that.baseUrl + "clientApi/sign/mpWxLogin",
									method: "POST",
									data: {
										code: uni.getStorageSync('c1'),
										encryptedIv: e.detail.iv,
										encryptedData: e.detail.encryptedData,
										userInfo: {
											storeId: 12,
											staffId: "",
											phone: '16548796325'
										},

										type: 'phone',
										inviteId: uni.getStorageSync('inviteId') ? uni
											.getStorageSync(
												'inviteId') : null
									},
									success: (rex) => {
										console.log('请求成功', rex)
										if (uni.getStorageSync("y_type") ==
											'yaoqingyouli') {
											this.activeRecommendRecords()

										}
										if (rex.data.code == 200) {

											uni.setStorageSync('App-Token', rex.data.data
												.token);
											uni.setStorageSync('chainStoreId', rex.data
												.data
												.chainStoreId);

											uni.navigateTo({
												url: '/pages/index/index'
											})
										}
										console.log("swq", uni.getStorageSync(
											'App-Token'));
									},
									fail: (res) => {
										console.log("fail", res);
										uni.showToast({
											icon: "error",
											title: "登录失败，请重新点击并授权！",
											duration: 2000
										})
									}
								})
							},
							fail: () => {
								uni.showToast({
									icon: 'error',
									duration: 2000,
									title: "登录状态过期，重新登录"
								});
							}
						})
					}
				})
			},
			async activeRecommendRecords() {
				let res = await request({
					url: "clientApi/sign/alipayLogin/getUserid",
					method: 'post',
					data: {
						storeId: uni.getStorageSync("y_storeId"),
						type: uni.getStorageSync("y_type"),
						userId: uni.getStorageSync("y_userId"),
					},
				})

			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #ffffff;

	}

	.container {
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.my-header {
		width: 100%;
		height: 88px;
		background: #3c91f4;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #000;
		box-sizing: border-box;
		padding: 0px 15px;
		padding-top: 40px;
		z-index: 99999;

		.my-icons {
			width: 20px;

		}

		position: fixed;
		top: 0px;
	}

	.dl {
		height: 40px;
		background: #2F72F7;
		border-radius: 50px;


	}

	.top-box {
		width: 100%;
		height: 60vh;
		background: url('http://47.95.206.185:83/lgoin.png')center no-repeat;
		background-size: 100% 100%;
		background-attachment: fixed;

	}

	.dl-box {
		width: 80%;
		height: 45px;
		background: #2F72F7;
		color: white;
		border-radius: 50px;
		margin: 0 auto;
	}

	.kk-box {
		width: 80%;
		height: 45px;
		background: #F0F3FA;
		color: #333333;
		border-radius: 50px;
		border: 1px solid #F0F3FA;
		margin: 10px auto;
	}

	.dbottom {
		width: 100%;
		text-align: center;
		font-size: 12px;
		color: #333333;
		margin-top: 40px;
		position: fixed;
		bottom: 45px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.quanzi {
		width: 14px;
		height: 14px;
		border: 1px solid #666666;
		border-radius: 50%;
		margin-right: 10px;
	}

	.lanquanzi {
		width: 14px;
		height: 14px;
		border: 1px solid #0078FF;
		border-radius: 50%;
		margin-right: 10px;
		background: #0078FF;
		color: white;
	}

	.lan {
		color: #0078FF;
	}

	.jiuzhong {
		width: 90%;
		margin: 10px auto;
		display: flex;
		align-items: center;
	}

	.dist {
		display: flex;
		align-items: center;
		margin: 0px 10px;
	}

	.d-zi {
		font-size: 14px;
	}

	.d-qian {
		width: 14px;
		height: 14px;
		margin-right: 5px;
		overflow: hidden;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid #666666;
		color: white;
	}

	.d-qian-lan {
		width: 14px;
		height: 14px;
		margin-right: 5px;
		overflow: hidden;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #0078FF;
		border: 1px solid #0078FF;
		color: white;
	}
</style>
