<!--
 * @Author: PoJun
 * @Date: 2023-09-28 10:38:11
 * @LastEditors: PoJun
 * @LastEditTime: 2023-12-25 16:35:22
 * @Message: 账号注册
-->
<template>
    <view class="register">
        <uv-alert type="primary" description="账号注册成功后将自动跳转登录界面" center></uv-alert>
        <view class="register-cont">
            <kirin-form ref="form" :list="list"></kirin-form>
            <view class="uv-m-t-30">
                <uv-button
                    type="primary"
                    text="注册"
                    @click="save"
                    :disabled="checkboxValue.length == 0"
                    shape="circle"
                ></uv-button>
            </view>
        </view>
        <view class="register-agree uv-font-26">
            <view>
                <uv-checkbox-group v-model="checkboxValue">
                    <uv-checkbox name="agree"></uv-checkbox>
                </uv-checkbox-group>
            </view>
            <view>我已仔细阅读并同意</view>
            <view class="register-agree-text" @tap="check('service')">《服务协议》</view>
            <view class="register-agree-text" @tap="check('privacy')">《隐私协议》</view>
        </view>
    </view>
</template>

<script>
import { registerUsername } from "@/config/http.js";
import { registerFormList } from "./constant";
export default {
    data() {
        return {
            list: registerFormList,
            checkboxValue: [],
        };
    },
    onLoad() {},
    methods: {
        async save() {
            const formData = this.$refs.form.getFormData();
            if (!formData) {
                return;
            }
            if (formData.rePassword != formData.credentials) {
                uni.$uv.toast("两次输入密码不一致");
                return;
            }
            if (formData.rePassword.length < 6) {
                uni.$uv.toast("密码长度不能低于6位数");
                return;
            }
            uni.showLoading({ mask: true });
            await registerUsername(formData);
            try {
                await uni.$uv.sleep(500);
                uni.$uv.route({ type: "back" });
            } finally {
                uni.hideLoading();
            }
        },
        check(type) {
            uni.$uv.route({
                url: "/subpkg/agreement/index",
                params: { type },
            });
        },
    },
};
</script>

<style lang="scss">
.register {
    height: calc(100vh - var(--status-bar-height) - 44px);
    /* #ifdef APP-PLUS */
    height: 100vh;
    /* #endif */
    display: flex;
    flex-direction: column;
    &-cont {
        flex: 1;
        padding: 10rpx 25rpx;
    }
    &-agree {
        padding: 100rpx 0;
        display: flex;
        flex-direction: row;
        justify-content: center;
        &-text {
            color: $uv-primary;
        }
    }
}
</style>
