<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 open-type="getPhoneNumber" class="login-btn1" @getphonenumber="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 {third} 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(e) {
				if (e.detail.code) {
					var phoneCode = e.detail.code
					uni.login({
						success: (code) => {
							third({
								code: code.code
							}).then(res=>{
								if (res.code == 1) {
									uni.setStorageSync("token", res.data.token)
									if (!res.data.phone || 1) {
										this.$u.post('/api/Member/bind_Phone', {
											code: phoneCode
										}).then(res => {
											if (res.code == 1) {
												this.$u.toast("登录成功")
												this.$u.post('/api/Member/member_info').then(
													res => {
														uni.setStorageSync("hx_username",
															res.data.hx_username)
														this.$WebIM.conn.open({
															user: res.data
																.hx_username,
															pwd: "888888",
														}).then(() => {
															console.log(
																"login success"
															);
														}).catch((reason) => {
															console.log(
																"login fail",
																reason);
														});
													})
												this.setcity()
												setTimeout(() => {
													uni.navigateBack()
												}, 800)
											} else {
												this.$u.toast(res.msg)
												uni.removeStorageSync('token')
											}
										})
									} else {
										this.$u.toast("登录成功")
										this.setcity()
										setTimeout(() => {
											uni.navigateBack()
										}, 800)
									}
								} else {
									this.$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>