<template>
	<view class="content">
		<view class="container">
			<view class="title_">账号登录</view>
			<view style="text-align: center;">
				<image src="../../static/imgs/hh.png" style="width: 80%; height: 200px;  margin: 40px auto; "></image>
			</view>
			<view class="tab-list">
				<view :class="{ 'acv' :tabindex == index }" class="tabbox" v-for="(item,index) in tablist" :key="index"
					@click="getindex(index)">{{item}}</view>
			</view>
			<view class="input-po">
				<view class="lift-num">+86</view>
				<input type="text" placeholder="输入手机号" v-model="appuser.username" />
			</view>

			<view class="input-po">
				<input type="password" placeholder="输入密码" v-model="appuser.password" />
			</view>
			<!-- 服务协议 -->
			<view class="fw-c-box">
				<view class="qiu" v-if="show == false " @click="show=true"></view>
				<view class="xqiu" v-if="show == true " @click="show=false">
					<u-icon name="checkmark" color="#fff" size="14"></u-icon>
				</view>
				<view class="size-login">我已阅读并同意 <text style="color:#4AA76F;;" @click="gopv">《用户服务协议》</text> 和 <text
						style="color:#4AA76F;" @click="gopv">《隐私政策》</text> </view>
			</view>

			<view class="anniu" @click="toLogin">
				登录
			</view>

		</view>
	</view>
</template>

<script>
	import headers from '../../components/header/headers.vue'
	import tabbar from '../../components/tabbar/tabbar.vue'
	import request from '../../utils/request'
	export default {
		data() {
			return {
				titles: "默认",
				msg: "1",
				List: [],
				show: false,
				status: 'loading',
				appuser: {
					username: '',
					password: ''
				},
				tabindex: 0,
				tablist: [
					'管理端',
					'教练端'
				],
				baseUrl: this.$baseUrl,
				codeShow: true,
				count: '',
				timer: null
			}
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		onShow() {
			if (uni.getStorageSync("App-Token")) {
				let loginType = uni.getStorageSync("loginType")
				if (loginType == 0) {
					uni.navigateTo({
						url: "/pages/index/index"
					})
				} else {
					uni.navigateTo({
						url: "/pages/teacher/index"
					})
				}
			}
		},
		components: {
			tabbar
		},
		methods: {
			getindex(id) {
				this.tabindex = id
			},
			getCode() {
				let TIME_COUNT = 60;
				if (!this.timer) {
					this.count = TIME_COUNT;
					this.isGrey = true;
					this.codeShow = false;
					this.dis = true;
					this.timer = setInterval(() => {
						if (this.count > 0 && this.count <= TIME_COUNT) {
							this.count--;
						} else {
							this.dis = false;
							this.isGrey = false;
							this.codeShow = true;
							clearInterval(this.timer);
							this.timer = null;
						}
					}, 1000);
				}
			},
			// 跳转隐私协议
			gopv() {
				uni.navigateTo({
					url: '/pagesLogin/login/webview'
				})

			},
			// 登录接口
			toLogin() {
				if (!this.appuser.username || !this.appuser.password) {
					uni.showToast({
						title: "请先输入登录账号信息",
						icon: "none"
					})
					return;
				}
				if (!this.show) {
					uni.showToast({
						title: "请先阅读并勾选隐私协议",
						icon: "none"
					})
					return;
				}

				if (this.tabindex == 0) {
					this.appuser.types = 2
				}
				if (this.tabindex == 1) {
					this.appuser.types = 3
				}
				this.appuser.type = 0
				request({
					url: '/loginApp',
					method: 'post',
					data: this.appuser
				}).then((res) => {
					if (res.code == 200) {
						uni.setStorageSync("App-Token", res.token)
						uni.setStorageSync("loginType", this.tabindex)
						if (this.tabindex == 0) {

							uni.navigateTo({
								url: "/pages/index/index"
							})

						} else if (this.tabindex == 1) {
							uni.navigateTo({
								url: "/pages/teacher/index"
							})
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'error'
						})
					}
				})
			},
			goBack() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #fff;
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #fff;
		box-sizing: border-box;
		padding: 36px;
	}

	.title_ {
		color: #333333;
		font-weight: bold;
		font-size: 24px;
	}

	.input-po {
		width: 100%;
		box-sizing: border-box;
		padding: 20px 0px;
		border-bottom: 1px solid #DDDDDD;
		display: flex;
		align-items: center;
		justify-content: space-between;

		input {
			width: 70%;
		}

	}

	.lift-num {
		border-right: 1px solid #DDDDDD;
		box-sizing: border-box;
		padding-right: 10px;
		margin-right: 10px;
	}

	.fw-c-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 12px;
		margin-top: 40px;
	}

	.qiu {
		width: 16px;
		height: 16px;
		border: 1px solid #DDDDDD;
		margin-right: 5px;
		border-radius: 50%;
	}

	.xqiu {
		width: 16px;
		height: 16px;
		border: 1px solid #4AA76F;
		background: #4AA76F;
		margin-right: 5px;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.size-login {}

	.anniu {
		width: 100%;
		height: 38px;
		background: #4AA76F;
		border-radius: 4px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;
		margin: 20px 0px;
	}

	.r-color {
		font-size: 14px;
		color: #E63030;
		text-align: center;
		margin-bottom: 200px;
	}

	.wx-img {
		width: 50px;
		height: 50px;
		border-radius: 50%;
		margin: 10px auto;
		overflow: hidden;
		padding: 0;

		image {
			width: 100% !important;
			height: 100% !important;
		}
	}

	.tab-list {
		width: 100%;
		margin: 10px auto;
		align-items: center;
		color: #999;
		display: flex;

	}

	.acv {
		color: #4AA76F !important;
		font-weight: bold;
	}

	.tabbox {

		margin-right: 10px;
	}
</style>