<template>
	<view class="login">
		<!-- <u-navbar :is-back="false" :border-bottom="false" :background="{background:'rgba(0,0,0,0)'}"></u-navbar> -->
		<view class="login-top u-flex-col u-col-center u-row-center">
			<image src="../../static/images/logo.png" mode=""></image>
			<text>内核招聘</text>
		</view>
		<button class="login-btn1" @click="tologin">微信授权登录</button>
		<view class="login-btn2" @click="totel">
			手机号登录/注册
		</view>
		<view class="xieyi-box u-flex u-row-center">
			<u-checkbox-group v-model="xieyi">
				<u-checkbox shape="circle" active-color="#0C66C2"></u-checkbox>
			</u-checkbox-group>
			<view class="u-flex">
				<text class="text1">登录代表您已同意</text>
				<text class="text2" @click.stop="toxieyi(1)">《用户协议》</text>
				<text class="text1">、</text>
				<text class="text2" @click.stop="toxieyi(2)">《隐私协议》</text>
			</view>
		</view>
		<view class="other-login u-flex u-row-center">
			<image src="../../static/images/jingli-img.png" mode=""></image>
			<text>项目经理登录</text>
		</view>
	</view>
</template>

<script>
	import {
		conn
	} from '@/utils/WebIM.js'
	import {
		third,
		third_mobile
	} from "../../units/inquire.js"
	export default {
		data() {
			return {
				xieyi: false
			}
		},
		onLoad() {

		},
		methods: {
			toxieyi(type) {
				uni.navigateTo({
					url: "/pagesA/xieyi?type=" + type
				})
			},
			totel() {
				if (!this.xieyi) {
					this.$u.toast("请勾选协议")
					return
				}
				uni.navigateTo({
					url: "/pagesA/tel-login"
				})
			},
			tologin() {
				let that = this
				if (!this.xieyi) {
					this.$u.toast('请先阅读并同意用户协议')
					return
				}
				wx.login({
					success(res) {
						console.log(res.code);
						if (res.code) {
							third({
								code: res.code
							}).then(res => {
								that.$u.toast("登录成功")
								var options = {
									user: res.data.userinfo.user_no,
									pwd: res.data.userinfo.emchat_password,
									appKey: conn.appkey,
									success: function(res2) {
										uni.setStorageSync('user_no', res.data.userinfo.user_no)
										uni.setStorageSync('pwd', res.data.userinfo
											.emchat_password)
									},
									error: function() {}
								};
								conn.open(options);
								console.log(res);
								if (res.data.is_mobile == 1) {
									uni.setStorageSync("token", res.data.userinfo.token)
									uni.setStorageSync("user_id", res.data.userinfo.id)
									uni.setStorageSync("is_profile", res.data.userinfo.group_info
										.is_profile)
									setTimeout(() => {
										uni.switchTab({
											url: "/pages/index/index"
										})
									}, 800)
								} else {
									setTimeout(() => {
										uni.navigateTo({
											url: "/pagesA/tel-login?openid=" + res.data
												.openid
										})
									}, 800)
								}
							})
						} else {
							that.$u.toast(res.msg)
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.login {
		.other-login {
			width: 270rpx;
			height: 84rpx;
			background: rgba(1, 139, 141, 0.06);
			border-radius: 42rpx;
			margin: 106rpx auto;

			image {
				width: 39rpx;
				height: 39rpx;
				margin-right: 8rpx;
			}

			text {
				font-size: 26rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #018B8D;
			}
		}

		.xieyi-box {
			.text1 {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #141414;
			}

			.text2 {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #0C66C2;
			}
		}

		.login-btn2 {
			width: 650rpx;
			line-height: 96rpx;
			border-radius: 16rpx;
			border: 1rpx solid #0C66C2;
			margin: 44rpx auto;
			text-align: center;
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #0C66C2;
		}

		.login-btn1 {
			width: 650rpx;
			line-height: 96rpx;
			height: 96rpx;
			background: #0C66C2;
			border-radius: 16rpx;
			margin: 0 auto;
			font-size: 32rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}

		.login-top {
			height: 478rpx;

			image {
				width: 150rpx;
				height: 150rpx;
				margin-bottom: 20rpx;
			}

			text {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #222222;
			}
		}
	}
</style>