<template>
    <div class="page">
        <NavBar :showTitle="true" title="登录" />
        <!-- pages/login/login.wxml -->
        <view class="login-page">
            <nav-bar class="nav-bar">
                <template #title>   <text class="student">登录</text> </template>
            </nav-bar>
            <view class="title">
                <img src="@/static/image/icon/login.png" alt="" />
                <text class="t2">安全、便捷的就业、创业服务平台</text>
                <view class="title-label">用户端</view>
            </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 } from "@/api/user.js";
import { setToken, getToken } from "@/utils/token";
import { removeToken } from "@/utils/token";
const res = ref("");

onLoad(() => {
    removeToken();
    uni.removeStorageSync("userInfo");
});
const login = () => {
    xma.xh.getUserProfile({
        range: ["ACCOUNT", "MOBILE",'CITIZEN'],
        success(info) {
            console.log('infoinfoinfo',info);
            xinhuaMpLogin({ encryptedData: info.data.uMobile, userType: "consumer",name: info.data.uName,citizenId:info.data.uIdCardNo })
                .then(data => {
                    if(data.code !== 200) return
                    res.value = data;
                    console.log("datadatadata", data);
                    setToken(data.data);
                    uni.switchTab({
                        url: "/pages/postionList/index"
                    });
                })
                .catch(err => {
                    res.value = err;
                });
        },
        fail(err) {
            test.value = err;
        }
    });
    getLoginUserApi().then(res => {
        console.log(res);
    });
};
</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;
        }
        .t2 {
            font-size: 24rpx;
            color: #1b2026;
            margin-top: 28rpx;
        }
        .title-label{
            font-size: 20rpx;
            width: 124rpx; 
            padding: 12rpx 28rpx;
            color: #FFFFFF;
            background: rgba(0, 102, 223, 0.7);
            border-radius: 40rpx;
            margin: 28rpx auto;
        } 
    }
    .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>
