<template>
	<view class="black">
		<view class="content">

			<view class="logInView">
				<view
					style="color: #3C3C3C; font-size: 36rpx; font-weight: bold; padding-left: 40rpx; padding-top: 30rpx;">
					选择角色</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 class="phoneView">
					<image src="../../static/img/icon_shouji@2x.png" class="icon"></image>
					<!-- 手机号 -->
					<input type="text" class="phone" placeholder="请输入手机号" v-model="phoneValue" @confirm="phoneDone" />

				</view>

				<!-- 验证码 -->
				<view class="phoneView">
					<image src="../../static/img/icon_yanheng@2x.png" class="icon"></image>
					<!-- 验证码 -->
					<view class="codeBg">
						<input type="text" class="code codeINput" 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>

				<!-- 登录 -->
				<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>

		</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>
	.black{
		background-color: #140B0A;
	}
	.content {
		min-height: 100vh;
		background: url('http://dmsimg.66km.com/yypb/home_yypb1.png') no-repeat;
		background-size: 100%;
	}

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

	/* #endif */

	.logInView {
		position: fixed;
		top: 374rpx;
		left: 60rpx;
		width: 630rpx;
		height: 588rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
	}

	.roleSelect {
		padding-top: 30rpx;
		display: flex;
		justify-content: space-around;
		text-align: center;
	}

	.role_S {
		color: #FF4F00;
		font-size: 28rpx;
		border-bottom: 3rpx #FF4F00 solid;
		height: 66rpx;
		/* width: 41%; */
		line-height: 66rpx;
	}

	.role_N {
		color: #3C3C3C;
		font-size: 28rpx;
		height: 66rpx;
		/* width: 41%; */
		line-height: 66rpx;
	}

	.phoneView {
		display: flex;
		justify-content: flex-start;
		margin: 0rpx 40rpx;
		height: 106rpx;
		border-bottom: 1rpx #CCCCCC solid;

	}

	.icon {
		width: 44rpx;
		height: 44rpx;
		margin-right: 20rpx;
		padding-top: 44rpx;
		padding-bottom: 22rpx;
	}

	.phone,
	.codeBg {
		/* margin: 44rpx 22rpx 0rpx; */
		padding-top: 44rpx;
		padding-bottom: 22rpx;
		color: #3C3C3C;
		font-size: 28rpx;
	}

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

	.logInBtn_S {
		margin: 30rpx;
		width: 550rpx;
		height: 76rpx;
		border-radius: 10rpx;
		background-color: #FF4F00;
		color: #FFFFFF;
		font-size: 30rpx;
		font-weight: bold;
		line-height: 76rpx;
		text-align: center;
	}

	.logInBtn_N {
		margin: 30rpx 40rpx;
		width: 550rpx;
		height: 76rpx;
		border-radius: 10rpx;
		background-color: #F4F5F7;
		color: #999999;
		font-size: 30rpx;
		font-weight: bold;
		line-height: 76rpx;
		text-align: center;
	}

	.logOutBtn {
		margin-bottom: 30rpx;
		margin-left: 258rpx;
		width: 112rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		font-size: 28rpx;
		color: #999999;
	}
	.codeINput{
		width: 350rpx;
	}
</style>
