<template>
	<view class="content">
		<view class="headbox">
			<text class="headtitle" v-if="checked==1">供货商注册</text>
			<text class="headtitle" v-if="checked==0">业务管理员注册</text>
			<view class="logobox">
				<image src="../../static/img/logo.png" mode="aspectFill"></image>
			</view>
		</view>
		<view class="acountbox" v-if="checked==1">
			<view class="inacount">
				<text class="acoutitle">账号</text>
				<input type="text" v-model="form.account" class="checkword" placeholder="请输入您的账号"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">密码</text>
				<input type="text" v-model="form.password" :password="true" class="checkword" placeholder="至少6位数的字母数字组合"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">确认密码</text>
				<input type="text" v-model="form.surepwd" :password="true" class="checkword" placeholder="至少6位数的字母数字组合"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
		</view>
		<view class="acountbox" v-if="checked==0">
			<view class="inacount">
				<text class="acoutitle">姓名</text>
				<input type="text" v-model="form.realName" class="checkword" placeholder="输入业务员真实姓名"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">账号</text>
				<input type="text" v-model="form.account" class="checkword" placeholder="请输入您的账号"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">密码</text>
				<input type="text" v-model="form.password" :password="true" class="checkword" placeholder="至少6位数的字母数字组合"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">确认密码</text>
				<input type="text" v-model="form.surepwd" :password="true" class="checkword" placeholder="至少6位数的字母数字组合"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
			<view class="inacount">
				<text class="acoutitle">联系电话</text>
				<input type="text" v-model="form.mobile" class="checkword" placeholder="请输入业务员联系电话"
					placeholder-style="font-size:30rpx;color:#BEBDBB" />
			</view>
		</view>
		<view class="logininbtn" @click="submiitForm">
			<text>注册账号</text>
		</view>
		<view class="acountall"><text>已有账户?</text><text style="color: #D05C39;padding-left: 10rpx;padding-right: 43rpx;"
				@click="loginIn">马上登录</text></view>
		<view class="flex1 checkag">
			<u-checkbox-group @change="checkboxChange">
				<u-checkbox name="gou" activeColor="#D8AB5A">
				</u-checkbox>
			</u-checkbox-group>
			<text>我已阅读并同意</text><text style="color: #D05C39;" @click="moveAgreement">用户协议</text><text>和</text><text style="color: #D05C39;" @click="privacyPolicy">隐私政策</text>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: 0,
				gou: false,
				form: {
					account: '',
					acountname: '',
					password: '',
					surepwd: '',
					mobile: ''
				},
			}
		},
		onLoad(o) {
			if (o.checked) {
				this.checked = o.checked
			}
			if (o.form) {
				let form = JSON.parse(o.form)
				this.form = Object.assign(this.form, form);
				this.checked = form.checked
			}
		},
		methods: {
			checkboxChange(n) {
				if (n.length > 0) {
					this.gou = true
				} else {
					this.gou = false
				}
			},
			submiitForm() {
				if (!this.gou) {
					this.$toast("清先阅读用户协议和隐私协议")
					return
				}
				let form = this.form
				if(this.checked==1){
					if(this.form.name.length==0){
						this.$toast("请输入您的账号")
						return
					}
					if(this.form.name.password==0){
						this.$toast("请输入至少6位数的字母数字组合的密码")
						return
					}
					if(this.form.password!=this.form.surepwd){
						this.$toast("两次密码输入不一样")
						return
					}
				}else if(this.checked==0){
					if(this.form.realName.length==0){
						this.$toast("请输业务员真实姓名")
						return
					}
					if(this.form.account.length==0){
						this.$toast("请输入您的账号")
						return
					}
					if(this.form.mobile.length==0){
						this.$toast("请输入业务员联系电话")
						return
					}
					if(this.form.password!=this.form.surepwd){
						this.$toast("两次密码输入不一样")
						return
					}
				}
				
				this.$load("加载中")

				if (this.checked == 0) {
					uni.$u.http.post('/api/Account/register',
						form, {
							custom: {
								auth: true
							}
						}).then((res) => {
						uni.hideLoading()
						this.$toast("注册成功")
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/login/login"
							})
						}, 1000)
					}).catch((err) => {
						uni.hideLoading()
						this.$toast(err.msg)
					})
				} else if (this.checked == 1) {
					uni.$u.http.post('/api/Supplier/register',
						form, {
							custom: {
								auth: true
							}
						}).then((res) => {
						uni.hideLoading()
						this.$toast("注册成功")
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/login/login"
							})
						}, 1000)
					}).catch((err) => {
						uni.hideLoading()
						this.$toast(err.msg)
					})
				}
			},
			moveAgreement(){
				uni.navigateTo({
					url:"/pages/bsinessadmin/useragreement"
				})
			},
			privacyPolicy(){
				uni.navigateTo({
					url:"/pages/bsinessadmin/privacypolicy"
				})
			},
			loginIn() {
				uni.navigateTo({
					url: "/pages/bsinessadmin/login"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {

		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.headbox {
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
	}

	.headtitle {
		font-size: 60rpx;
		font-weight: 600;
		padding-bottom: 36rpx;
	}

	.logobox {
		width: 269rpx;
		height: 191rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.acountbox {
		.inacount {
			flex: 1;
			display: flex;
			padding: 35rpx 20rpx;
			box-sizing: border-box;
			// width: 606rpx;
			margin-top: 40rpx;
			background-color: #F6F6F6;
			border-radius: 20rpx;
			font-size: 30rpx;
			color: #1F242A;

			input {
				width: 360rpx;
			}
		}

		.acoutitle {
			font-weight: 600;
		}

		.checkword {
			padding-left: 20rpx;
			color: #1F242A;
			font-size: 30rpx;
		}
	}

	.logininbtn {
		margin-top: 80rpx;
		// width: 606rpx;
		flex: 1;
		border-radius: 20rpx;
		border: 1rpx solid #BEBDBB;
		height: 100rpx;
		text-align: center;
		color: #BEBDBB;
		line-height: 100rpx;
	}

	.acountall {
		display: flex;
		justify-content: flex-end;
		margin-top: 30rpx;
		font-size: 24rpx;
	}

	.checkag {
		margin-top: 200rpx;
		font-size: 28rpx;
		padding-bottom: 130rpx;
	}
</style>
