<script setup lang="ts">


import { md5 } from 'js-md5'
import CpmdHeader from '@/components/CpmdHeader.vue';
import { ElMessage } from 'element-plus';

import { onMounted, onUnmounted, reactive, ref } from 'vue'

import { useRoute, useRouter } from 'vue-router'
import { userLoginApi } from '@/api/login';

import { userInfoStore } from '@/stores'
const userInfo = userInfoStore()

//定义账号
const account = ref<string>('')
//定义密码
const password = ref<string>('')





//此处应该是唯一的报告ID
const id = ref<string>('')
//持久化设置 菜单状态
//刚进入页面就将高度设置为页面需要的
onMounted(() => {

})
//跳转到注册页面的方法
const router = useRouter()

const registerFun = () => {
    router.push({ name: 'register' })
}




//轮旋切换页面的方法

//退出页面销毁 方法
onUnmounted(() => {

})



//登录方法
const loginFun = async () => {
    //先判断是否是字段都填写了
    if (account.value == '') {
        ElMessage({
            message: '账号不能为空',
            type: 'warning'
        })
        return
    }
    if (password.value == '') {
        ElMessage({
            message: '密码不能为空',
            type: 'warning'
        })
        return
    } else if (password.value.length < 6) {
        ElMessage({
            message: '密码最少6位',
            type: 'warning'
        })
        return
    }
    let params = {
        userNo: account.value,
        password: md5(password.value)
    }
    const res: any = await userLoginApi(params)
    if (res.code == 200) {
        if (res.data.type == '3') {
            userInfo.saveToken(res.data.token)
            userInfo.saveUserInfo(res.data.user)
            ElMessage({ message: `${res.msg}`, type: 'success' })
            //跳转到首页
            router.push({ name: 'homeView' })
        } else {
            ElMessage({ message: `请使用普通账户登录`, type: 'error' })
        }
        //登录成功后将信息存入缓存  

    } else {
        ElMessage({ message: `${res.msg}`, type: 'error' })
    }

}
</script>

<template>
    <div class="home_header_out">
        <div class=" home_header_inner">
            <CpmdHeader />
            <div class="report_top">
                <div class="report_jt">
                    <span>用户登录</span>

                </div>
                <!-- <img class="xlts_img" src="../assets/report/report_top.png" /> -->
            </div>
        </div>
        <div class="kply">
            <div class="kply_inner">
                <div style="padding: 20px 200px;">

                    <div style="margin-top:10px">
                        <div class="user_account">账号:</div>
                        <div class="input_cus"> <el-input v-model="account" style="width: 100%" placeholder="请输入账号" />
                        </div>
                    </div>
                    <div style="margin-top:10px">
                        <div class="user_account">密码:</div>
                        <div><el-input v-model="password" type="password" style="width: 100%" placeholder="请输入密码"
                                show-password />
                        </div>
                    </div>
                    <div class="go_register">
                        <span @click="registerFun">
                            没有账号，去注册
                        </span>
                    </div>
                    <div class="start_button_out">
                        <div @click="loginFun" class="start_button_self">登录</div>
                    </div>


                </div>

            </div>

        </div>

    </div>


</template>
<style lang="scss" scoped>
:deep(.el-input__wrapper) {
    align-items: center;
    border-radius: 60px !important;
    border: 8px solid #B2F2D2 !important;
    padding-left: 20px;

}

:deep(.el-input__wrapper .is-fous) {
    box-shadow: none
}

:deep(.el-input__inner) {
    height: 40px;
    font-size: 20px;
}


.home_header_out {
    // position: relative;
    padding-bottom: 60px;
    width: 100%;
    min-width: 1200px;
    background-image: url('../assets/home/bg_ty.png');
    background-repeat: no-repeat;
    background-size: contain;
    background-color: #FAFAFA; //估计是需要动态

    //获取屏幕宽度home_header_out 这个div的宽度--然后宽度*1000再除1920即为当前div的宽度
    .home_header_inner {
        min-height: 1;
        left: 0;
        right: 0;
        margin: auto;
        // height: 100px;
        width: 1200px;


        .report_top {
            width: 860px;
            margin-top: 20px;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            margin-left: 170px;

            .xlts_img {
                width: 200px;
            }

            .report_jt {
                display: flex;
                flex-direction: column;
                font-size: 40px;
                font-weight: 700;
                letter-spacing: 3px;
            }
        }
    }

    .kply {
        width: 100%;
        margin-top: 20px;
        // background-color: #FAFAFA;
        margin-bottom: 112px;

        .kply_inner {

            // padding: 20px 20px;
            left: 0;
            right: 0;
            margin: auto;
            width: 860px;
            min-height: 500px;

            background-color: #ffffff;
            border-radius: 40px;

            .user_account {
                font-size: 24px;
                // line-height: 70px;
                margin-bottom: 10px;
                letter-spacing: 5px;
            }


            .start_button_out {
                margin-top: 60px;
                margin-bottom: 40px;
                display: flex;
                flex-direction: row;
                justify-content: center;

                .start_button_self {
                    cursor: pointer;
                    // width: 100px;
                    border-radius: 12px;
                    border: 3px solid #48D68E;
                    color: #ffffff;
                    background-color: #000000;
                    margin-right: 20px;
                    padding: 5px 80px;
                    cursor: pointer;
                    display: flex;
                    align-items: center;
                    font-size: 18px;

                }
            }

        }

        .go_register {
            text-align: right;
            margin-top: 20px;

            span {
                color: #48D68E;
                cursor: pointer;
                font-size: 20px;
            }
        }
    }


}



.home_mid {
    // background-color: blanchedalmond;
    width: 1200px;
    left: 0;
    right: 0;
    margin: auto;
    margin-top: 40px;
    // position: relative;




    .kepu_title {
        text-align: center;

        font-size: 50px;
        color: #111111;
        line-height: 95px;

        // width: 100%;
        // left: 0;
        // right: 0;
        // margin: auto
    }

    .kepu_title_sub {
        margin-top: 30px;
        text-align: center;
        font-size: 28px;
        color: #48D68E;
        line-height: 26px;
    }

    .man1_group {
        margin-top: 60px;
        height: 100%;
        display: flex;

        .man1 {
            position: relative;
            width: 327px;
            // height: 100%;

            // height: 100%
            .man1_img {
                position: absolute;
                bottom: 0;
                /* bottom: 0px; */
                /* height: auto; */
                width: 100%;
                left: 100px
            }

        }

        .des {
            border: #48D68E solid 5px;
            border-radius: 40px;
            padding: 20px;
            letter-spacing: 6px;
            flex: 1;

            .des_inner {
                border: 1px dashed #48D68E;
                border-radius: 40px;
                padding-bottom: 40px;
                padding-top: 30px;
                padding-left: 100px;
                padding-right: 20px;
                letter-spacing: 6px;
                font-weight: normal;
                font-size: 24px;
                color: #333333;
                line-height: 40px;
            }
        }
    }

    .man2_group {
        margin-top: 60px;
        height: 100%;
        display: flex;

        .man2 {
            position: relative;
            width: 327px;
            // height: 100%;

            // height: 100%
            .man2_img {
                position: absolute;
                bottom: 0;
                /* bottom: 0px; */
                /* height: auto; */
                width: 100%;
                left: -100px
            }

        }

        .des2 {
            border: #48D68E solid 5px;
            border-radius: 40px;
            padding: 20px;
            letter-spacing: 6px;
            flex: 1;

            .des2_inner {
                border: 1px dashed #48D68E;
                border-radius: 40px;
                padding-bottom: 40px;
                padding-top: 30px;
                padding-left: 20px;
                padding-right: 100px;
                letter-spacing: 6px;
                font-weight: normal;
                font-size: 24px;
                color: #333333;
                line-height: 40px;
            }
        }
    }

    .get_more {
        text-align: center;

        img {
            width: 300px;
            margin-top: 60px;
            margin-bottom: 60px;
        }
    }
}

// .home_footer_out {
//     width: 100%;
//     background-color: #000000;
// }</style>
