<template>
    <div class="page">
        <NavBar :showIcon="false" :showTitle="true" title="登录"></NavBar>
        <!-- pages/login/login.wxml -->
        <view class="login-page">
            <view></view>
            <view class="title">
                <text class="t1">乐业观山湖</text>
                <text class="t2">安全、便捷的就业、创业服务平台</text>
            </view>
            <button class="login-btn" @click="login">授权手机号登录</button>

            <view class="unit-name">观山湖区人力资源与社会保障局</view>
        </view>
        <!-- {{ res }} -->
    </div>
</template>

<script setup>
import NavBar from "@/components/navBar/index.vue";
import { xinhuaMpLogin, getLoginUserApi } from "@/api/user.js";
import { setToken } from "@/utils/token";
const res = ref("");
const login = () => {
    xma.xh.getUserProfile({
        range: ["ACCOUNT", "MOBILE"],
        success(info) {
            xinhuaMpLogin({ encryptedData: info.data.uMobile, userType: "business" })
                .then(data => {
                    res.value = data;
                    if (data.code == 200) {
                        xma.showToast({
                            title: "登录成功",
                            icon: "success",
                            duration: 2000
                        });
                    }
                    setToken(data.data);
                    getLoginUserApi().then(el => {
                        if (el.data && el.data.status !== 0) {
                            uni.switchTab({
                                url: "/pages/user/index"
                            });
                        } else {
                            uni.navigateTo({
                                url: "/pages/user/businessLicense/fillIn"
                            });
                        }
                    });
                })
                .catch(err => {
                    res.value = err;
                });
        },
        fail(err) {
            test.value = err;
        }
    });
};
</script>

<style lang="scss" scoped>
.page {
    height: 100%;
    background-color: #eaf5ff;
    background-image: url("https://lygsh-image.wjzpgz.com/login/loginBG.png");
    background-repeat: no-repeat;
    background-position: 50% 50%;
    background-size: auto 100%;
}
.login-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .student {
        font-size: 36rpx;
        font-weight: 600;
        color: #1b2026;
        text-align: center;
    }
    .title {
        display: flex;
        flex-direction: column;
        margin-top: 176rpx;
        text-align: center;
        .t1 {
            font-size: 80rpx;
            font-weight: normal;
            font-family: ysbth;
            color: #0e2761;
        }
        .t2 {
            font-size: 24rpx;
            font-weight: 500;
            color: #1b2026;
        }
    }
    .login-btn {
        // position: fixed;
        // bottom: 336rpx;
        // left: 50%;
        margin-top: 371 * 2rpx;
        width: 640rpx;
        height: 96rpx;
        font-size: 34rpx;
        line-height: 96rpx;
        color: #ffffff;
        background-color: #1f86ff;
    }
    .unit-name {
        margin-top: 240rpx;
        font-size: 24rpx;
        font-weight: 500;
        color: #1b2026;
    }
}
</style>
