<template>
    <div>
        <p>
            手机号
            <input type="text" v-model="phone" />
        </p>
        <button @tap="login">登录</button>
    </div>
</template>

<script setup>
import { testLogin, getSmsCode, getLoginUserApi } from "@/api/user";
import { setToken } from "@/utils/token";
getLoginUserApi;
const phone = ref("");
const login = async () => {
    const a = await getSmsCode({ username: phone.value });
    const loginRes = await testLogin({
        username: phone.value,
        code: "000000"
    });
    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>
