<!-- 注册 -->
<template>
	<view class="container flex-items-plus flex-column">
		<global-loading />
<!--		<view class="login-logoBox">
			<image class="login-logo" src="http://36.138.125.206:8081/ceres-local-file/image/logo_wechat.png"></image>
		</view>-->
    <view
      class="login-title"
      :style="{'top': topHeight + 'px'}"
    >
      <view class="login-top-info">
        <view class="backBox">
          <image
            src="http://36.138.125.206:8081/ceres-local-file/image/title_black_back.png"
            class="back"
            @click="back"
          ></image>
        </view>
        <view class="fs32 font-color-252744">{{$t('page.register')}}</view>
      </view>
    </view>
    <image class="login-top" src="http://36.138.125.206:8081/ceres-local-file/image/login_top.png"/>
    <image class="login-bottom" src="http://36.138.125.206:8081/ceres-local-file/image/login_bottom.png"/>
		<view style="margin-top: 200rpx">
			<view class="iphoneNum-box flex-row-plus flex-items">
				<view>
					<image class="loginIcon" src="http://36.138.125.206:8081/ceres-local-file/image/login_phone_label.png"></image>
				</view>
				<view style="margin-left: 20rpx;">
					<input v-model="phone" class="iphoneNum-inputbox" placeholder-class="iphoneNum-input" type="number"
						maxlength="11" :placeholder="$t('common.entermobilephone')" />
				</view>
			</view>
			<view class="flex-row-plus mar-top-30">
				<view class="code-box">
					<view>
						<image class="loginIcon" src="http://36.138.125.206:8081/ceres-local-file/image/login_psd_label.png"></image>
					</view>
					<view style="margin-left: 20rpx;">
						<input v-model="RegisterQuery.code" :maxlength="4" class="codeNum-inputbox" placeholder-class="codeNum-input"
							:placeholder="$t('common.enterverificationcode')" />
					</view>
          <view :class="disabled === true ? 'on' : ''" :disabled="disabled" class="getcode" @click="codede">
            {{text}}
          </view>
				</view>

			</view>
		</view>
		<view class="registerBut" @click="onregister">{{$t('page.register')}}</view>
		<view class="flex-row-plus mar-top-30">
			<text class="fs28 font-color-252744">{{$t('client.alreadyhasaccount')}}</text>
			<view class="fs28 font-color-f5be51" @click="gologin">{{$t('client.tologin')}}</view>
		</view>
		<view class="agreement">
      <view style="display: flex;align-items: center">
        <image v-if="!agreement" src="http://36.138.125.206:8081/ceres-local-file/image/icon_cart_select_normal.png" mode="" @click="agreement=true"></image>
        <image v-else src="http://36.138.125.206:8081/ceres-local-file/image/icon_cart_select_active.png" mode="" @click="agreement=false"></image>
        <text class="fs28 font-color-595B6B">{{$t('client.registermeansagree')}}</text><br/>
      </view>
      <view style="margin-top: 10rpx">
        <text class="fs28 font-color-f5be51" @click="protocol('app_user_agreement')">{{$t('client.appuserservice')}}</text>{{$t('common.and')}}
        <text class="fs28 font-color-f5be51" @click="protocol('app_privacy_agreement')">{{$t('client.appsafeservice')}}</text>
      </view>
		</view>

	</view>
</template>

<script>
	import sendVerifyCode from "@/mixins/SendVerifyCode";
	const NET = require('../../utils/request')
	const API = require('../../config/api')
	export default {
		data() {
			return {
				getCodeisWaiting: false,
				// 注册
				phone: '',
				RegisterQuery: {
					account: "",
					code: "",
				},
				// 获取验证码
				VerifyQuery: {
					phone: "",
					type: ""
				},
				agreement: false,
        topHeight: 10,
			}
		},
		mixins: [sendVerifyCode],
		onLoad() {
      // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
      let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
      this.topHeight = menuButtonInfo.top
      // #endif
      // #ifdef APP
      this.topHeight = 50
      // #endif
		},
		methods: {
			// 注册账号
			getRegister() {
				let phoneCodeVerification = /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
				if (this.phone == '') {
					uni.showToast({
						title: '请输入手机号！',
						duration: 2000,
						icon: 'none'
					});
				} else if (!phoneCodeVerification.test(this.phone)) {
					uni.showToast({
						title: '请输入正确的手机号！',
						duration: 2000,
						icon: 'none'
					});
				} else if (this.RegisterQuery.code == '') {
					uni.showToast({
						title: '请获取验证码！',
						duration: 2000,
						icon: 'none'
					});
				} else if(!this.agreement){
					uni.showToast({
						title: '请先阅读并同意《用户服务协议和个人隐私协议》',
						duration: 2000,
						icon: 'none'
					});
				} else {
					// uni.showLoading({
					// 	mask: true,
					// 	title: '正在注册...',
					// 	duration: 2000,
					// })
					NET.request(API.Login, {
						type: 1,
						phone: this.phone,
						verificationCode: this.RegisterQuery.code,
					}, 'POST').then(res => {
						uni.hideLoading()
						uni.showToast({
							title: '注册成功！',
							duration: 2000,
							icon: 'none'
						});
						const item = res.data
						uni.setStorageSync('storage_key', item);
						setTimeout(function() {
							uni.switchTab({
								url: '../../pages/tabbar/user/index'
							})
						}, 600)
						// uni.navigateTo({
						// 	url: 'accountLogin'
						// })
					}).catch(res => {
						uni.showToast({
							title: res.data.message,
							duration: 2000,
							icon: 'none',
						});
					})
				}
			},
			// 获取验证码
			getVerify() {
				let phoneCodeVerification = /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
				if (this.phone == '') {
					uni.showToast({
						title: '请输入手机号！',
						duration: 2000,
						icon: 'none'
					});
				} else if (!phoneCodeVerification.test(this.phone)) {
					uni.showToast({
						title: '请输入正确的手机号！',
						duration: 2000,
						icon: 'none'
					});
				} else {
					this.VerifyQuery.phone = this.phone
					NET.request(API.Verify, {
						phone: this.VerifyQuery.phone,
					}, 'GET').then(res => {
						this.sendCode()
					}).catch(res => {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 1000
						});
					})
				}

			},
			// 注册
			onregister() {
				this.getRegister()
			},
			// 获取验证码
			codede() {
				this.getVerify()
			},

			getCode() {
				uni.hideKeyboard()
				if (this.getCodeisWaiting) {
					return;
				}
				if (this.phone == "" || this.phone == null) {
					uni.showToast({
						title: '手机号不能为空',
						icon: 'none'
					})
					return false;
				} else if (!(/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(this.phone))) {
					uni.showToast({
						title: '输入的手机号错误',
						icon: 'none'
					})
					return false;
				}
				this.getCodeisWaiting = true;

			},
			// 跳转登录
			gologin() {
				uni.navigateTo({
					url: 'login'
				})
			},
			// 多商户用户协议
			protocol(type) {
				uni.navigateTo({
					url: 'protocol?type=' + type
				})
			},

      // 返回上一级
      back() {
        uni.navigateBack()
      }
		}
	}
</script>
<style lang="scss" scoped>
	.container {
		background-color: #FFFFFF;
		height: 100vh;

		.login-logoBox {
			margin-top: -200rpx;

			.login-logo {
				width: 518rpx;
				height: 100rpx;
			}
		}


		.iphoneNum-box {
      display: flex;
      align-items: center;
			height: 98rpx;
			width: 620rpx;
      background: #f2f2f6;
      border-radius: 50rpx;
			.loginIcon {
				width: 44rpx;
				height: 44rpx;
        margin-left: 47rpx;
        margin-top: 10rpx;
			}

			input {
				font-size: 28rpx;
			}

			.iphoneNum-input {
				color: #BCBDC6;
				font-size: 28rpx;
				font-weight: 400;
			}

			.iphoneNum-inputbox {
				width: 400rpx;
			}
		}

		.code-box {
      display: flex;
      height: 98rpx;
      width: 620rpx;
      background: #f2f2f6;
      border-radius: 50rpx;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.loginIcon {
				width: 44rpx;
				height: 44rpx;
        margin-top: 10rpx;
        margin-left: 47rpx;
			}

			input {
				font-size: 28rpx;
			}

			.code-lab {
				width: 200rpx;
			}

			.codeNum-input {
				color: #BCBDC6;
				font-size: 28rpx;
				font-weight: 400;
				width: 300rpx;
			}

			.codeNum-inputbox {
				width: 300rpx;
			}
		}

		.getcode {
			//background-color: #C5AA7B;
			height: 100rpx;
			width: 230rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			margin-left: 20rpx;
			color: #252744;
		}

		.getcodeActive {
			background-color: #DDDDDD;
			height: 100rpx;
			width: 220rpx;
			border-radius: 44rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			margin-left: 20rpx;
			color: #333333;
		}

		.registerBut {
			background: #252744;
			color: #FFFFFF;
      border-radius: 50rpx;
			height: 98rpx;
			width: 620rpx;
			text-align: center;
			line-height: 98rpx;
			margin-top: 90rpx;
      font-size: 32rpx;
		}

		.agreement {
			margin: 120rpx 50rpx;
			line-height: 50rpx;
			image{
				width: 40rpx;
				height: 40rpx;
				margin-right: 15upx;
			}
		}
	}

  .login-title {
    width: 100%;
    position: fixed;
    z-index: 99;
    left: 0;

    .login-top-info {
      position: relative;
      width: 100%;
      height: 60rpx;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .backBox {
      position: absolute;
      left: 10rpx;
      top: 0rpx;

      .back {
        width: 20rpx;
        height: 34rpx;
        padding: 15rpx 10rpx;
      }
    }
  }

  .login-top{
    width: 325rpx;
    height: 263rpx;
    position: fixed;
    top: 0;
    right: 0;
  }

  .login-bottom{
    width: 646rpx;
    height: 376rpx;
    position: fixed;
    bottom: 0;
    left: 0;
  }

</style>
