<template>
	<view>
		<!-- 头部 -->
		<headContent>
			<template #left>
				<view class="head-revers-back iconfont" @click.stop="reversBackBtn()">&#xe604;</view>
			</template>
		</headContent>

		<view class="page-content">
			<text class="login-title">设置密码</text>
			<setPswd @submitPswd="submitPswd" />
		</view>

		<load ref="loadRef" />
	</view>
</template>

<script>
	import setPswd from "./modules/set-pswd.vue"

	import {
		reverseBack
	} from "@/utils/common.js"
	import {
		Api_setPassword,
		Api_submitRegister
	} from "@/api/index.js"
	export default {
		name: 'submit-register',
		components: {
			setPswd
		},
		data() {
			return {
				type: '',
				account: '',
				accountCode: '',
				invitationCode: ''

			};
		},
		onLoad(opt) {
			// type=0&account=13133111133&invitationCode=1&accountCode=123456
			this.type = opt?.type;
			this.account = opt?.account;
			this.accountCode = opt?.accountCode;
			this.invitationCode = opt?.invitationCode;
		},
		mounted() {

		},
		methods: {
			reversBackBtn() {
				reverseBack()
			},

			submitPswd(e) {

				uni.showLoading({
					title: ''
				})
				const obj = {
					type: this.type == 1 ? 'email' : 'mogile',
					user_string: this.account,
					invitationCode: this.invitationCode,
					password: e.newPassword,
					re_password: e.confirmPassword
				}
				Api_submitRegister(obj).then(res => {
					setTimeout(() => {
						uni.showToast({
							title: '注册成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/login/index'
							});
						}, 300)
					}, 200)
				}).catch(err => {}).finally(() => {
					uni.hideLoading()
				})


			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "~./common.scss";
</style>