<template>
	<view id="warp">
		<view class="t_login_passList bor_bot">
			<view class="input_icon">头像:</view>
			<view class="input_img">
				<image src="/static/images/common/logo.png"></image>
			</view>
		</view>
		<view class="t_login_passList bor_bot">
			<view class="input_icon">名字:</view>
			<input
				class="input_css"
				v-model="name"
				border="none"
				disabled
				placeholder="请输入名字"
			></input>
		</view>
		<view class="t_login_passList">
			<view class="input_icon"><text>*</text> 手机号:</view>
			<input
				class="input_css"
				v-model="changePhone"
				type="number"
				border="none"
				placeholder="请输入手机号"
			></input>
		</view>
		<!-- <view class="t_login_passList">
			<view class="input_icon">验证码</view>
			<input
				class="input_css2"
				v-model="code"
				type="number"
				border="none"
				placeholder="请输入验证码"
			></input>
			<view class="code">
				<view v-if="!isGetCode" @tap="getCode" style="color:#1B64F8FF">获取验证码</view> 
				<view v-else style="color:#B2B2B2">{{codeTime}} 秒后重发</view>
			</view>
		</view> -->
		<view class="t_login_passList">
			<view class="input_icon"><text>*</text> 公司名称:</view>
			<input
				class="input_css"
				v-model="companyName"
				border="none"
				placeholder="请输入公司名称"
			></input>
		</view>
		<view class="t_login_passList" @tap="onChooseLocation">
			<view class="input_icon">公司位置:</view>
			<input
				class="input_css3"
				v-model="localtionName"
				disabled
				border="none"
				placeholder="点击选择"
			></input>
			<view class="code3">
				<uni-icons type="forward" size="20"></uni-icons>
			</view>
		</view>
		<view class="btn_css">
			<button class="btn"  @tap="registerOk">完成入驻</button>
		</view>
	</view>
</template>
<script>
	const {urlList,https} = require('@/static/api');
	export default {
		data() {
			return {
				// account:'',      //手机号
				// code:'',        //验证码
				// isGetCode:false,   //是否已经获取验证码
				// codeTime:60,
				avatarUrl:'',     //头像
				name:'',          //名字
				changePhone:'',   //更换的手机号
				companyName:'',   //公司名称
				localtionName:'',   //车场位置
				longitude:'',
				latitude:'',
			};
		},
		onLoad(options) {
			let info = JSON.parse(options.userInfo);
			let avatarUrl = info.avatarUrl;
			this.avatarUrl = avatarUrl;
			this.name = info.name;
		},
		methods:{
			// 完成入驻
			registerOk(){
				const _that = this;
				if(_that.changePhone == ''){
					if(_that.localtionName == ''){
						uni.showToast({
							title:'请输入手机号码',
							icon:'none',
							duration:1500
						})
						return;
					};
				};
				if(_that.companyName == ''){
					uni.showToast({
						title:'请填写公司名称',
						icon:'none',
						duration:1500
					})
					return;
				};
				uni.login({
					success:function(val){
						let postData = {
							jsCode : val.code,
							avatarUrl: _that.avatarUrl,
							userName: _that.name,
							phone:_that.changePhone,
							companyName:_that.companyName,
							longitude:_that.longitude,
							latitude:_that.latitude,
							address:_that.localtionName,
						};
						https(urlList.register,'POST',postData,'正在注册...').then(data => {
							console.log('注册',data)
							uni.redirectTo({
								url: `/pages/registerOk/registerOk`
							})
						}).catch(err => {
							uni.showToast({
								title:err,
								icon:'none',
								duration:1500
							})
						})
					}
				});
			},
			// 选择公司位置
			onChooseLocation(){
				const _that = this;
				uni.chooseLocation({
				    success: function (res) {
						let {longitude,latitude} = res;
						https(urlList.getLocationName+'/'+longitude+'/'+latitude,'GET','','').then(data => {
							console.log('地址名称',data)
							_that.localtionName = data.data;
							_that.longitude = longitude;
							_that.latitude = latitude;
						}).catch(err => {
							uni.showToast({
								title:err,
								icon:'none',
								duration:1500
							})
						})
				    }
				});
			},
			// 获取验证码
			// getCode(){
			// 	const iphone = this.account;
			// 	const that = this;
			// 	if( !/^1[3456789]\d{9}$/.test(iphone) ){
			// 		uni.showToast({
			// 			title:'请输入手机号',
			// 			icon:'none',
			// 			duration:1500
			// 		})
			// 		return;
			// 	};
			// 	https(urlList.getPhoneCode+'/'+iphone,'GET','','正在获取验证码').then(data => {
			// 		that.isGetCode = true;
			// 		uni.showToast({
			// 			title:'验证码获取成功',
			// 			icon:'none',
			// 			duration:1500,
			// 		});
			// 		let time = 60;
			// 		let Interval = setInterval(function () {
			// 			time--;
			// 			if (time > 0) {
			// 				that.codeTime = time;
			// 			} else {
			// 				clearInterval(Interval);
			// 				that.isGetCode = false;
			// 				that.codeTime = 60;
			// 			}
			// 		}, 1000)
			// 	}).catch(err => {
			// 		uni.showToast({
			// 			title:err,
			// 			icon:'none',
			// 			duration:1500
			// 		})
			// 	})
			// },
		}
	}
</script>

<style lang="scss" scoped>
	#warp{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.t_login_passList{
		width:650rpx;
		padding: 20rpx 0rpx;
		border-bottom: 1rpx solid #e6e6e6;
		display: flex;
		flex-direction: row;
		align-items: center;
		.input_icon{
			width: 260rpx;
			margin-top: 5rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			padding-left: 10rpx;
			text{
				color: red;
			}
		}
		.input_img{
			width:370rpx;
			display: flex;
			justify-content: flex-end;
			image{
				width: 80rpx;
				height: 80rpx;
			}
		}
		.input_css{
			width:340rpx;
			height: 70rpx;
			// border: 1rpx solid red;
		}
		// .input_css2{
		// 	width: 200rpx;
		// 	height: 70rpx;
		// }
		// .code{
		// 	margin-left: 20rpx;
		// 	width: 200rpx;
		// 	display: flex;
		// 	justify-content: flex-end;
		// 	border-left: 1rpx solid #e6e6e6;
		// 	font-size: 31rpx;
		// }
		.input_css3{
			width: 280rpx;
			height: 70rpx;
			// border: 1rpx solid red;
		}
		.code3{
			margin-left: 20rpx;
			width: 50rpx;
			display: flex;
			justify-content: flex-end;
		}
		
	}
	.btn_css{
		width: 650rpx;
		position: fixed;
		bottom: 20rpx;
		display: block;
		.btn{
			background-color:#1B64F8FF;
			color: white;
		}
	}
</style>