<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.token);
        const userInfoRes = await getLoginUserApi();
        // 已经判断是否注册过企业
        if (userInfoRes.data?.companyId) {
            uni.switchTab({
                url: "/pages/user/index"
            });
        } else {
            uni.navigateTo({
                url: "/pages/user/businessLicense/fillIn"
            });
        }
        console.log(userInfoRes);
    } else {
        uni.showToast({
            title: loginRes.message
        });
    }
};
</script>

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