<template>
	<view :class="[AppTheme]" class="renzheng">
		<view style="height: 20rpx;"></view>
		<view class="xiu" v-if='!flag'>
			<view class="num1">
				<text>姓名:</text>
				<input id="yuan" type="text" placeholder="请输入姓名" v-model="name">
			</view>
			<!--      <view class="num1">
		            <text>身份证号:</text>
		            <input id="yuan" type="text" placeholder="请输入身份证号" v-model="idno">
		        </view> -->
			<view class="num1">
				<text>手机号:</text>
				<input id="yuan" type="text" placeholder="请输入手机号" v-model="mobile">
			</view>
			<view class="num1">
				<text>支付密码:</text>
				<input id="yuan" type="password" placeholder="请输入支付密码" v-model="pay_password">
			</view>
			<view class="num1">
				<text>确认支付密码:</text>
				<input id="yuan" type="password" placeholder="请再次确认密码" v-model="pay_password_re">
			</view>
			<view class="num1">
				<text>手机验证码:</text>
				<input class="codes" id="yuan" type="text" placeholder="请输入验证码" v-model="code">
				<button class="code codeBut" @click="getcode" v-model="ma">{{ma}}</button>
			</view>
		</view>
		<view class="but" v-if='!flag' v-cloak>
			<button class="bg-linear-gradient" @click="tijiao">确定</button>
		</view>


		<view class="xiu" v-if='flag'>
			<view class="num1">
				<text>姓名:</text>
				<view>{{ name }}</view>
			</view>
			<!--  <view class="num1">
		            <text>身份证号:</text>
		            <view>{{ idno }}</view>
		        </view> -->
			<view class="num1">
				<text>手机号:</text>
				<view>{{ mobile }}</view>
			</view>
		</view>
		<view class="but" v-if='btn' v-cloak>
			<button>实名认证中</button>
		</view>
	</view>
</template>

<script>
	import mineApi from "@/api/mine/index.js"
	export default {
		data() {
			return {
				primary: this.$theme.primary,
				btn: false,
				flag: false,
				name: "",
				idno: "",
				mobile: "",
				pay_password: "",
				pay_password_re: "",
				code: "",
				ma: "获取验证码",
				time: 30,
				fromGoToOrder: '',
				settingFile: getApp().globalData.siteinfo
			};
		},
		onLoad(options) {
			this.fromGoToOrder = options.goRenZheng;
			var wxUserInfo = uni.getStorageSync('wxUserInfo');
			console.log(JSON.stringify(wxUserInfo))
			var userInfo = uni.getStorageSync('userInfo');
			console.log(JSON.stringify(userInfo))

			if (wxUserInfo) {
				if (wxUserInfo.is_auth == 2) {
					this.name = wxUserInfo.name;
					this.idno = wxUserInfo.idno;
					this.mobile = wxUserInfo.mobile;
					this.flag = true;
				}
			}
			var userInfo = uni.getStorageSync('userInfo');
			console.log(JSON.stringify(userInfo))

			if (userInfo) {
				if (userInfo.is_auth == 2) {
					this.name = userInfo.name;
					this.idno = userInfo.idno;
					this.mobile = userInfo.mobile;
					this.flag = true;
				}
			}
			// var renzheng = $api.getStorage('renzheng');
			// console.log(JSON.stringify(renzheng));

			mineApi.rzIndex().then(ret => {
				if (ret.status == 200) {
					if (ret.data.vip.is_auth == 1) {
						this.name = ret.data.vip.name;
						this.idno = ret.data.vip.idno;
						this.mobile = ret.data.vip.mobile;
						this.flag = true;
					}
				}
			})

			mineApi.vipinfo().then(ret => {
				if (ret.status == 200) {
					if (ret.data.is_auth == 1) {
						this.btn = true;
					}
				}
			})
		},
		methods: {
			// 验证名字是否有效
			panname(name) {
				if (name == "") {
					this.$u.toast("请填写名字")
					return
				}
			},
			// 验证手机号
			isMobile(mobile) {
				if (mobile == "") {
					this.$u.toast("请输入手机号")
					return;
				} else {
					if (!/^0{0,1}(13[0-9]|15[0-9]|17[0-9]|18[0-9]|19[0-9]|16[0-9]|14[0-9])[0-9]{8}$/.test(mobile)) {
						this.$u.toast("输入手机号有误")
						return
					} else {

					}
				}
			},
			getcode: function() {
				this.isMobile(this.mobile)
				mineApi.getAuthSmsCode({
					mobile: this.mobile
				}).then(ret => {
					if (ret.status == 200) {
						this.$u.toast(ret.msg)
						this.ma = this.time + "s"
						var timeId = setInterval(() => {
							if (this.time > 0) {
								this.time--
								this.ma = this.time + "s"
							} else {
								this.ma = "获取验证码"
								clearInterval(timeId)
							}

						}, 1000)
					} else {
						this.$u.toast(ret.msg)
					}
				})
			},

			// 提交验证
			tijiao: function() {
				this.panname(this.name)
				// panidno(this.idno)
				this.isMobile(this.mobile)

				if (!this.pay_password) {
					this.$u.toast('请填写支付密码')
					return
				} else if (!this.pay_password_re) {
					this.$u.toast('请确认支付密码')
					return
				} else if (this.pay_password != this.pay_password_re) {
					this.$u.toast('两次支付密码不一致')
					return
				} else if (!this.code) {
					this.$u.toast('请先输入验证码')
					return
				}

				let data = {
					name: encodeURI(this.name),
					mobile: this.mobile,
					idno: this.idno,
					pay_password: this.pay_password,
					pay_password_re: this.pay_password_re,
					code: this.code
				}

				mineApi.auth(data).then(ret => {
					this.$u.toast(ret.msg)
					if (ret.status == 200) {
						if (this.fromGoToOrder == 'user') {
							uni.setStorageSync('renzheng', ret.data);
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/user/user'
								})
							}, 1000)
						} else {
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								});
							}, 1000)
						}

					}
					if (ret.status == 0) {
						// this.$u.toast(ret.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.renzheng {
		width: 100%;
		min-height: 100%;
		background: #f1f1f1;
	}

	.xiu {}

	.num1 {
		/*display: flex;*/
		// height: calc(256rpx / 3);
		position: relative;
		display: flex;
		align-items: center;
		background-color: white;
		height: 110rpx;
		padding: 0 30rpx;
		border-bottom: 1px solid #f1f1f1;
	}

	.num2 {
		width: 100%;
		/*display: flex;*/
		height: calc(256rpx / 3);
		display: flex;
		align-items: center;
		background-color: white;
		padding: 0 30rpx;
		border-bottom: 1px solid #f1f1f1;
	}

	.num2 text {
		width: 250rpx;
		display: block;
		/*width: 46.5rpx;*/
		font-size: 30rpx;
		// background-color: blue;
	}

	.num2 input {
		font-size: 27rpx;
		padding-left: 58rpx;
		color: #999999;
	}

	.code {
		width: 25%;
		height: 55rpx;
		font-size: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.num1 text {
		display: block;
		width: 30%;
		/*width: 46.5rpx;*/
		/*background-color: blue;*/
		font-size: 30rpx;
		color: #303133;
	}

	.num1 input {
		font-size: 27rpx;
		color: #999999;
		width: 35%;
	}

	.but {
		width: 100%;
		text-align: center;
	}

	.but button {
		margin: 50rpx auto;
		width: 690rpx;
		height: 80rpx;
		font-size: 31rpx;
		color: white;
		font-weight: 600;
		// background: $tab-color;
		border-radius: 10rpx;
		// box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}

	.codeBut {
		border: 1rpx solid #999999;
		background-color: white;
		border-radius: 8rrpx;
	}
</style>
