<template>
    <div class="hesuan">
        <div class="userInfo">
            <div class="title">个人信息</div>
            <div class="info">
                <div class="name">姓名：{{ this.name }}</div>
                <div class="idCard">身份证号：{{ this.idCard }}</div>
            </div>
        </div>
        <div class="cardContent">
            <div class="card" v-if="this.mockData.hsjcsj">
                <div class="date">
                    <img class="dateImg" src="./img/date.png" alt />
                    <div class="dateText">{{ mockData.hsjcsj }}</div>
                </div>
                <div class="check">
                    <div class="jigou">
                        检测机构：
                        <span>{{ mockData.hsjcjgmc }}</span>
                    </div>
                    <div class="jieguo" v-if="mockData.hsjcjg == '阴性'">
                        检测结果：
                        <span class="yinxing">{{ mockData.hsjcjg }}</span>
                    </div>
                    <div class="jieguo" v-if="mockData.hsjcjg == '阳性'">
                        检测结果：
                        <span class="yangxing">{{ mockData.hsjcjg }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from "axios"
// import { encryptByDES } from "@/utils/utils";
import { decryptByDES } from "@/utils/utils";

export default {
    data() {
        return {
            name: '',
            idCard: '',
            mockData: {},
            userInfo: {},
        }
    },
    created() {
        this.JSBgetUserInfo();
    },
    mounted() {
        window.getUserInfo = this.getUserInfo;
    },
    methods: {
        init() {
            this.name = this.userInfo.realName;
            this.idCard = decryptByDES(this.userInfo.idCardNo,"MnuYbhGv");
            axios({
                url: 'https://appointment.smart-zj.cn/applet/applet/epidemic/queryExamineResult',
                method: 'get',
                headers: {
                    'Content-Type': "application/json",
                },
                params: {
                    idCard: this.userInfo.idCardNo,
                    name: this.userInfo.realName
                }
            }).then((res) => {
                if (res.data.status == 100) {
                    this.mockData = res.data.data
                }
            }).catch({})
        },
        JSBgetUserInfo() {
            if (window.android !== undefined) {
                const res = window.android.getUserInfo(); // 这是一个json字符串
                sessionStorage.setItem("ZJCD-UserInfo", res);
                this.userInfo = JSON.parse(res);
                if (!this.userInfo.idCardNo) {
                    this.$dialog
                        .confirm({
                            message: "请进入“我的”完成实名认证！",
                            showCancelButton: false,
                        })
                        .then(() => {
                            this.back();
                        });
                    return;
                } else {
                    this.init()
                }
            } else if (window.webkit) {
                window.webkit &&
                    window.webkit.messageHandlers.getUserInfo.postMessage("getUserInfo");
            } else {
                this.$dialog
                    .confirm({
                        message: "请进入“我的”完成实名认证！",
                        showCancelButton: false,
                    })
                    .then(() => {
                        this.back();
                    });
                // this.userInfo = {
                //   mobileNo: 17372670270,
                //   userId: 37393,
                //   userName: "孙辉",
                //   realName: "孙涵",
                //   idCardNo: "a/c2v64lTy9MC0QgqjzJxjOp0yG+B96Q",
                // };
                // sessionStorage.setItem("ZJCD-UserInfo", JSON.stringify(this.userInfo));
            }
        },
        getUserInfo(res) {
            sessionStorage.setItem("ZJCD-UserInfo", res);
            this.userInfo = JSON.parse(res);
            if (!this.userInfo.idCardNo) {
                this.$dialog
                    .confirm({
                        message: "请进入“我的”完成实名认证！",
                        showCancelButton: false,
                    })
                    .then(() => {
                        this.back();
                    });
                return;
            } else {
                this.init()
            }
        },
        back() {
            if (window.android !== undefined) {
                window.android.backHome();
            } else {
                window.webkit && window.webkit.messageHandlers.backHome.postMessage("");
            }
        },
    },
}
</script>

<style lang="stylus" scoped>
.hesuan{
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #F3F6F9;
    .userInfo{
		background: url('./img/hesuanBg.png');
		background-size: 100% 100%;
		width: 100%;
		height: 340px;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
		padding: 0 30px;
		box-sizing: border-box;
        .title{
            font-size: 32px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #FFFFFF;
        }
        .info{
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: space-around;
            font-size: 28px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #FFFFFF;
            margin: 20px 0;
            .name{
                margin: 20px 0;
            }
            .idcard{
                margin-bottom: 20px;
            }
        }
	}
    .cardContent{
		width: 96%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
        .card{
            width: 100%;
            background-color: #FFFFFF;
            padding: 0 30px;
            box-sizing: border-box;
            margin-top: 20px;
            font-size: 28px;
            .date{
                display: flex;
                align-items: center;
                padding: 30px 0;
                border-bottom: 1rpx solid #DDDDDD;
                .dateImg{
                    width: 40px;
                    height: 40px;
                }
                .dateText{
                    font-size: 32px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    margin-left: 10px;
                }
            }
            .check{
                display: flex;
                flex-direction: column;
                .jigou{
                    margin: 20px 0;
                }
                .jieguo{
                    margin-bottom: 30px;
                }
                .yinxing{
                    font-size: 30px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #29A400;
                }
                .yangxing{
                    font-size: 30px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #ED0000;
                }
            }
        }
	}
}
</style>