<template>
	<view class="login">
		<view class="login-logo">
			<image class="logo" :src="configList?.applet_info?.paramValueImage" mode="aspectFill"></image>
			<image class="d" :src="configList?.logo_icon?.paramValueImage" mode="aspectFill"></image>
		</view>
		<view class="login-submit">
			<up-button class="mt24" type="primary" text="微信授权登陆" @tap="loginWx" shape="circle"
				color="#FFBF60"></up-button>
			<up-button @click="cancelLogin" class="mt24" type="primary" text="取消登录" shape="circle"
				color="#FFBF60"></up-button>
		</view>
		<view class="flex-rowc">
			<view class="select">
				<image mode="widthFix"></image>
			</view>
			<view class="size-26">
				<text>我已阅读并同意猫爸狗妈</text>
				<text @click="privacyPolicy('login_xy')" class="main-color">《注册协议》</text>
				<text>与</text>
				<text @click="privacyPolicy('login_ys')" class="main-color">《隐私政策》</text>
			</view>
		</view>
	</view>

	<up-popup :show="show" @close="close" :round="10">
		<view style="padding: 10rpx 20rpx;min-height: 50vh;" v-html="content"></view>
	</up-popup>

</template>

<script setup>
	import {
		getOpenIdKey,
		getToken,
		setIsLogin,
		setOpenIdKey,
		setStorage,
		setToken
	} from "../../utils/auth";
	import {
		getOpenId,
		getPersonalInfo,
		getPhoneNumber
	} from "../../api/system/user";
	import {
		computed,
		onMounted,
		ref
	} from "vue"
	import {
		useStore
	} from 'vuex'

	const store = useStore()
	const value = ref(false)
	const configList = computed(() => {
		return store.getters.configList
	})
	const show = ref(false)
	const content = ref('')

	// 微信授权登陆
	const loginWx = () => {
		store.dispatch("login")
	}



	// 获取openid
	// if (!getOpenIdKey() && !getToken()) {
	// 	uni.login({
	// 		provider: 'weixin',
	// 		success: async (res) => {
	// 			const {
	// 				code,
	// 				data
	// 			} = await getOpenId(res.code)
	// 			if (code === 200 && data) {
	// 				let resData = JSON.parse(data)
	// 				setOpenIdKey(resData.openId)
	// 			}
	// 		},
	// 		fail: function(error) {
	// 			// 授权失败处理
	// 			uni.showToast('授权失败，请授权后再试')
	// 		}
	// 	});
	// }
	// 获取token
	const onGetPhoneNumber = async (e) => {
		// uni.login({
		// 	success: res => {
		// 		console.log("====>", res)
		// 	}
		// })
		getPhoneNumber({
			phoneCode: e.detail.code
		})
		// if (e.detail.errMsg === "getPhoneNumber:ok") {
		// 	if (getOpenIdKey()) {
		// 		try {
		// 			const {
		// 				data
		// 			} = await getPhoneNumber({
		// 				"openId": getOpenIdKey(),
		// 				"code": e.detail.code,
		// 				sourceType: 1
		// 			})
		// 			setToken(data.token)
		// 			setIsLogin(true)
		// 			await getUserInfo()
		// 		} catch (e) {
		// 			uni.showToast({
		// 				icon: 'error',
		// 				title: '获取手机号失败'
		// 			})
		// 		}
		// 	}
		// }
	}

	// // h获取用户信息
	// const getUserInfo = async () => {
	// 	const {
	// 		data
	// 	} = await getPersonalInfo()
	// 	setStorage('userInfo', data)
	// 	uni.navigateBack()
	// }

	const cancelLogin = () => {
		uni.switchTab({
			url: "/pages/workbenchManage/index"
		})
	}

	const close = () => {
		show.value = false
	}
	
	const privacyPolicy = (key) => {
		content.value = configList.value[key]?.paramValueArea || "";
		show.value = true;
	}
</script>

<style scoped lang="scss">
	@import "index";
	@import "@/style/index.scss";

	.select {
		width: 24rpx;
		height: 24rpx;
		border-radius: 50%;
		border: 1rpx solid #C7C7C7;
		margin-right: 8rpx;

		.active {
			background-color: $mainColor;
		}
	}

	.footer {
		color: #C7C7C7;
		position: fixed;
		bottom: 100rpx;

	}
</style>