<template>
	<view class="content">

		<view class="zdyNav">
		  <view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		  <view class="nav">

			  <view >登录</view>
			  
		  </view>
		</view>
		<view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
		<view style="height: 44px;"></view>

		<image class="topImg" src="../../static/img/dl_bg@2x.png" mode=""></image>

		<view style="color: #3C3C3C; font-size: 40rpx; font-weight: bold; padding-left: 48rpx;">选择角色</view>

		<!-- 选择角色 -->
		<view class="roleSelect">
			<view class="role_S" v-if="roleType == 1" @click="roleTypeFirst">运营陪伴</view>
			<view class="role_N" v-else @click="roleTypeFirst">运营陪伴</view>

			<view class="role_S" v-if="roleType == 2" @click="roleTypeSecond">连锁门店</view>
			<view class="role_N" v-else @click="roleTypeSecond">连锁门店</view>
		</view>


		<view style="color: #3C3C3C; font-size: 40rpx; font-weight: bold; padding-left: 48rpx;">登录</view>


		<!-- 手机号 -->
		<input type="text" class="phone" placeholder="请输入手机号" v-model="phoneValue" @confirm="phoneDone" />

		<!-- 验证码 -->
		<view class="codeBg">
			<input type="text" class="code" placeholder="请输入验证码" v-model="codeValue" @confirm="codeDone" />
			<view @click="send" v-if="phoneValue.length == 11 && code_time == 0" style="color: #FF4F00; font-size: 28rpx;">获取验证码</view>
			<view style="color: #999999; font-size: 28rpx;" v-if="phoneValue.length != 11 && code_time == 0">获取验证码</view>
			<view style="color: #999999; font-size: 28rpx;" v-if="code_time > 0">重新获取({{code_time}}s)</view>
			
		</view>


		<!-- 登录 -->
		<view class="logInBtn_S" @click="logIn" v-if="phoneValue.length == 11 && codeValue != ''">登录</view>
		<view class="logInBtn_N" v-else>登录</view>
		<!-- 取消登录 -->
		<view class="logOutBtn" @click="goIndex">取消登录</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				roleType: 1, //1 运营陪伴 2 连锁门店
				phoneValue: '',
				codeValue: '',
				code_time: 0 ,// 倒计时
				iStatusBarHeight:'',
			}
		},
		onLoad() {
			 this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
		},
		methods: {
			roleTypeFirst() {
				this.roleType = 1
				console.log('运营陪伴');
			},
			roleTypeSecond() {
				this.roleType = 2
				console.log('连锁门店');
			},
			phoneDone(e) {
				this.phoneValue = e.target.value;
			},
			codeDone(e) {
				this.codeValue = e.target.value;
			},
			// 发送验证码
			send() {
				console.log('发送验证码');
				this.$http('accompany/superusers/sendSms', {
					phone: this.phoneValue,

				}, 'GET').then(res => {
					if(res.code!=0){
							uni.showModal({
								title: '提示',
								content: res.msg,
								success: function (res) {
									
								}
							})
						} else {
							this.code_time = 60
							let coder = setInterval(() => {
								if (this.code_time > 0) {
									this.code_time--
								}
								if (this.code_time == 0) {
									clearInterval(coder)
								}
							}, 1000)
						}
					})

			},
			logIn() {

				uni.showLoading({
					title: '登录中'
				})
				this.$http('accompany/superusers/phoneLogin', {
					phone: this.phoneValue,
					code: this.codeValue,
					type: this.roleType,
				}, 'POST').then(res => {

					uni.setStorage({
						key: 'logInData',
						data: res.data,
						success: function() {
					
						}
					})
					uni.setStorage({
						key: 'userInfo',
						data: res.data.userInfo,
						success: function() {

						}
					})
                    if(this.roleType==1){
						uni.navigateTo({
							url: '../index/index'
						})
					}else{
						uni.navigateTo({
							url: '../shop/shopIndex/index'
						})
					}
					
				})
			}
			
			,goIndex(){
				uni.navigateTo({
					url: '../logIn/home'
				})
			}
		}
	}
</script>

<style>
	.content {
		background-color: #FFFFFF;
		min-height: 100vh;

	}

	/* #ifdef H5 */
	.content {
		background-color: #FFFFFF;
		min-height: calc(100vh - 44px);
	}

	/* #endif */

	.zdyNav{
		position: fixed;
		left: 0;
		top: 0;
		background: #FFFFFF;
		z-index: 11;
	}
	.status_bar{
		background: #FFFFFF;
	}
	.nav{
		width: 100vw;
		height: 44px;
		background: #FFFFFF;
		text-align: center;
		font-size: 34rpx;
		line-height: 44px;
	}
	.topImg {
		padding-left: 152rpx;
		height: 256rpx;
	}

	.roleSelect {
		padding: 24rpx 48rpx;
		display: flex;
		justify-content: space-between;
		text-align: center;
	}

	.role_S {
		color: #FF4F00;
		font-size: 28rpx;
		border: 2rpx #FF4F00 solid;
		border-radius: 50rpx;
		height: 88rpx;
		width: 41%;
		line-height: 88rpx;
	}

	.role_N {
		color: #3C3C3C;
		font-size: 28rpx;
		background-color: #F4F5F7;
		border-radius: 50rpx;
		height: 88rpx;
		width: 41%;
		line-height: 88rpx;
	}

	.phone,
	.codeBg {
		margin: 0rpx 48rpx;
		padding-top: 48rpx;
		padding-bottom: 22rpx;
		color: #3C3C3C;
		font-size: 28rpx;
		border-bottom: 2rpx #F4F5F7 solid;
	}

	.codeBg {
		display: flex;
		justify-content: space-between;
	}

	.logInBtn_S {
		margin: 50rpx 48rpx;
		width: 100vw-96rpx;
		height: 88rpx;
		border-radius: 50rpx;
		background-color: #FF8700;
		color: #FFFFFF;
		font-size: 30rpx;
		font-weight: bold;
		line-height: 88rpx;
		text-align: center;
	}

	.logInBtn_N {
		margin: 50rpx 48rpx;
		width: 100vw-96rpx;
		height: 88rpx;
		border-radius: 50rpx;
		background-color: #F4F5F7;
		color: #999999;
		font-size: 30rpx;
		font-weight: bold;
		line-height: 88rpx;
		text-align: center;
	}

	.logOutBtn {
		position: fixed;
		bottom: 130rpx;
		left: 275rpx;
		width: 200rpx;
		height: 42rpx;
		text-align: center;
		line-height: 42rpx;
		font-size: 30rpx;
		color: #999999;
	}
</style>
