<template>
    <div>
        <p>
            手机号
            <input type="text" v-model="phone" />
        </p>
        <button @click="getSmsCodeFn">获取验证码</button>
        <p>
            验证码
            <input type="text" v-model="code" />
        </p>

        <button @tap="login">登录</button>
    </div>
</template>

<script setup>
import { testLogin, getSmsCode, getLoginUserApi } from "@/api/user";
import { setToken, removeToken } from "@/utils/token";
const phone = ref("");
const code = ref("");
const getSmsCodeFn = () => {
    const a = getSmsCode({ username: phone.value });
};
const login = async () => {
    removeToken();
    const loginRes = await testLogin({
        username: phone.value,
        code: code.value,
        userType: "business"
    });
    if (loginRes.code === 200) {
        setToken(loginRes.data);
        const userInfoRes = await getLoginUserApi();
        // 已经判断是否注册过企业
        if (userInfoRes.data) {
            const { status } = userInfoRes.data;
            switch (status) {
                case 0:
                    uni.navigateTo({
                        url: `/pages/user/businessLicense/fillIn?steps=1`
                    });
                    break;
                default:
                    uni.switchTab({
                        url: "/pages/user/index"
                    });
                    break;
            }
        } else {
            uni.navigateTo({
                url: `/pages/user/businessLicense/fillIn?steps=1`
            });
        }
    }
};
</script>

<style lang="scss" scoped></style>
