<template>
	<view>
		<!-- <view style="width: 100%;height: 180rpx;"></view> -->
		<view class="input">
<!-- 			<view class="zcasfdasf">设置密码</view>
			<view class="tejHdgasd">设置密码后,就可以使用手机号码与密码登录了~</view> -->
			<view class="cwjs-cells item-flex" style="margin-top: 80rpx;">
				<view class="cwjs-item center" style="margin-left:30rpx;">
					<input type="text" v-model="phone" placeholder="请输入手机号码" maxlength="11"
						placeholder-style='color:#AAAAAA;' />
				</view>
			</view>
			<view class="cwjs-cells item-flex" style="margin-top:30rpx;">
				<view class="cwjs-item center" style="margin-left:30rpx;display: flex;">
					<input type="text" v-model="msg" placeholder="请输入验证码" maxlength="4"
						placeholder-style='color:#AAAAAA;' />
					<view class="mamay">
						<view class="sada" v-if="sendAuthCode" style="font-size: 30rpx;" @click="getAuthCode">获取验证码
						</view>
						<text class="sada" v-if="!sendAuthCode">
							重新发送({{ auth_time }})
							<!-- <text></text> -->
						</text>
					</view>
				</view>
			</view>
			<view style="margin-top:30rpx" class="cwjs-cells item-flex">
				<view class="cwjs-item center" style="margin-left:30rpx;">
					<input class="cwjs-item cwjs-input" v-model="username" password="true" placeholder="请设置6~12位的登录密码"
						placeholder-style='color:#AAAAAA' maxlength="12" />
				</view>
			</view>

		</view>
		<view class="button" @tap="bindWxBLogin">确认</view>
	</view>
</template>
<script>
	var util = require("../../utils/util.js");
	var config = require("../../config");
	var app = getApp();
	var WXB_SESSION_LOGIN_DATA = 'weapp_session_login_data';
	export default {
		data() {
			return {
				username: '', //获取到的密码
				phone: '',
				auth_time: 0,
				sendAuthCode: true,
				msg: '',
				code:''
			}
		},
		onLoad: function(options) {
			// this.phone = options.username
		},
		methods: {
			bindWxBLogin() {
				if(this.code!=this.msg){
					util.showNone("验证码错误");
					return false;
				}
				if (this.username.length < 6) {
					util.showNone("密码小于6位，请重试");
					return false;
				} else {
					var loginParams = {
						username: this.phone, //手机号
						newpassword: this.username, //密码
					}
					
					uni.request({
						url: config.service.forgotPassword,
						header: {
							'content-type': 'application/json'
						},
						data: loginParams,
						method: "POST",
						success: function(result) {
							if (result.data.code == 10000) {
								uni.reLaunch({
									url: '/pages/login/index',
								})
							} else {
								util.showNone(result.data.message);
								return false;
							}
						}
					})
					
					
				}
			},
			//获取验证码
			getAuthCode() {
				if (this.phone == '') {
					uni.showToast({
						title: '手机号不能为空',
						icon: 'none'
					});
					return
				}
				this.code=''
				uni.request({
					url: config.service.sendCode + "/" + this.phone,
					method: "GET",
					header: {
						'content-type': 'application/json',
					},
					success: (data) => {
						console.log(data)
						// 成功地响应会话信息
						if (data.data.code == 0) {
							util.showSuccess('发送成功');
							this.code=data.data.data
							this.sendAuthCode = false;
							this.auth_time = 60;
							var auth_timetimer = setInterval(() => {
								this.auth_time--;
								if (this.auth_time <= 0) {
									this.sendAuthCode = true;
									clearInterval(auth_timetimer);
								}
							}, 1000);
						} else {
							util.showNone(data.data.msg);
							return false;
						}
					},
				})
			},
		}
	};
</script>

<style lang="scss">
	.cwjs-logo {
		display: block;
		width: 219rpx;
		height: 158rpx;
		margin: 54rpx auto 66rpx;
	}

	.cwjs-tips {
		font-size: 24rpx;
		padding: 80rpx 0;
		color: #8a8a8a;
	}

	.cwjs-form {
		position: relative;
		margin: 0;
		background-color: #fff;
		border-radius: 10px;
		padding: 20rpx 40rpx 113rpx;
	}

	.zcasfdasf {
		height: 48rpx;
		font-size: 48rpx;
		font-weight: 400;
		color: #303030;
		line-height: 48rpx;
		margin-top: 80rpx;
	}

	.tejHdgasd {
		height: 28rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #303030;
		line-height: 28rpx;
		margin-top: 28rpx;

	}

	.cwjs-cells {
		width: 600rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		margin: 0 auto;
		height: 88rpx;
		overflow: hidden;
		border: 1rpx solid #BFC7D3;
		position: relative;
		border-radius: 12rpx;
		padding-left: 20rpx;
	}

	.center {
		flex: 1;
		display: flex;
	}

	.texteasda {
		height: 88rpx;
		line-height: 88rpx;
		font-size: 28rpx;
		color: #000;
	}

	.cwjs-input {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 28rpx;
		color: #000;
	}

	.images {
		display: block;
		width: 40rpx;
		height: 21rpx;
		margin-right: 30rpx;
		margin-top: 33.5rpx;
	}

	.mod-btn {
		position: absolute;
		bottom: -80rpx;
		left: 50%;
		margin-left: -80rpx;
	}

	.mod-btn .button {
		width: 160rpx;
		height: 160rpx;
		background: linear-gradient(180deg, rgba(116, 197, 230, 1) 0%, rgba(64, 147, 201, 1) 100%);
		border: 10rpx solid rgba(255, 255, 255, 1);
		border-radius: 100%;
		font-size: 36rpx;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.mod-btn .button::after {
		content: ""
	}

	.retPassword {
		display: inline;
		width: auto;
		font-size: 28rpx;
		color: rgba(64, 147, 201, 1);
		line-height: 40rpx;
		float: right;
	}

	.retPassword:active {
		background-color: #fff;
	}

	.appliyAdmin {
		position: absolute;
		left: 50%;
		margin-left: -57rpx;
		bottom: 100rpx;
		width: 114rpx;
		font-size: 28rpx;
		color: rgba(255, 255, 255, 1);
		line-height: 40rpx;
	}

	/* 头部 */

	.head {
		width: 750rpx;
		height: 355rpx;
	}

	.background {
		width: 750rpx;
		height: 400rpx;
		position: absolute;
		top: -3rpx;
		left: 0;
	}

	.logo {
		width: 123rpx;
		height: 107rpx;
		display: block;
		position: absolute;
		top: 84rpx;
		left: 313.5rpx;
	}

	.head text {
		font-size: 34rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #2343BD;
		position: absolute;
		top: 222rpx;
		left: 203rpx;
	}

	/* 输入框 */
	.input {
		width: 100%;
		height: auto;
		padding: 0 90rpx;
		box-sizing: border-box;
	}

	.logo_input {
		width: 34rpx;
		height: 38rpx;
		position: absolute;
		top: 25rpx;
		left: 0;
	}

	/* 登录 */
	.button {
		width: 630rpx;
		height: 86rpx;
		background: #2671E2;
		box-shadow: 0px 2rpx 20rpx 0px rgba(38, 113, 226, 0.5);
		border-radius: 49rpx;
		text-align: center;
		line-height: 89rpx;
		color: #fff;
		margin: 0 auto;
		margin-top: 239rpx;
		font-size: 34rpx;
	}

	.footer {
		width: 100%;
		height: 157rpx;
		position: absolute;
		bottom: 0;
		left: 0;
	}

	.agreeBox {
		font-size: 28rpx;
		color: #88909E;
		margin: 0 auto;
		margin-top: 30rpx;
		position: relative;
		display: flex;

	}

	checkbox {
		transform: scale(0.5);
	}

	checkbox-group {
		display: inline;
	}

	navigator {
		display: inline
	}

	.agreeBox image {
		width: 26rpx;
		height: 26rpx;
		display: block;
		position: absolute;
		top: 9rpx;
		left: 18rpx;
		margin-right: 19rpx;
	}

	.imagesBox {
		width: 80rpx;
		height: 88rpx;
	}

	.chooseBox {
		width: 60rpx;
		height: 60rpx;
	}

	.login {
		text-decoration: underline;
		text-align: center;
		margin-top: 40px;
		color: #88909E;
		font-size: 28rpx;
	}

	.textbox {
		width: 569rpx;
		display: flex;
		margin-top: 40rpx;
	}

	.textbox-1 {
		width: 30%;
		font-size: 30rpx;
		color: #999999;
	}

	.textbox-11 {
		width: 30%;
		text-align: right;
		font-size: 30rpx;
		color: #999999;
	}

	.textbox-2 {
		width: 40%;
	}
</style>
