<template>
    <div class="page">
        <!-- pages/login/login.wxml -->
        <!-- <view class="login-page">
            <view></view>
            <view class="title">
                <text class="t1">乐业观山湖</text>
                <text class="t2">安全、便捷的就业、创业服务平台</text>
            </view>
            <view class="unit-name">观山湖区人力资源和社会保障局</view>
            <button class="login-btn" @click="login">授权手机号登录</button>
        </view> -->
        <view class="login-page">
            <NavBar :showIcon="false" :showTitle="true" title="登录"></NavBar>
            <view class="title">
                <text class="t1">乐业观山湖</text>
                <text class="t2">安全、便捷的就业、创业服务平台</text>
            </view>
            <view class="box">
                <text class="box-text">观山湖区人力资源和社会保障局</text>
                <button class="login-btn" @click="login">授权手机号登录</button>
            </view>
        </view>
        <!-- {{ res }} -->
    </div>
</template>

<script setup>
import NavBar from "@/components/navBar/index.vue";
import { xinhuaMpLogin, getLoginUserApi } from "@/api/user.js";
import { setToken, removeToken } from "@/utils/token";
const res = ref("");
const login = () => {
    removeToken();
    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?steps=1"
                            });
                        }
                    });
                })
                .catch(err => {
                    res.value = err;
                });
        },
        fail(err) {
            test.value = err;
        }
    });
};
</script>

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