<template>
    <div class="remote-part">
        <div class="title">{{ title }}</div>
        <div class="content" :class="{'is-total': isRemote}">
            <div class="left-box">
                <div class="info-box">
                    <div class="row-item">
                        <span class="label">病人名称</span>
                        <span class="input-value">{{ patientInfo.name }}</span>
                    </div>
                    <div class="row-item">
                        <span class="label">住院号</span>
                        <span class="input-value">{{ patientInfo.code }}</span>
                    </div>
                </div>
                <div class="row-item" :class="{'alarm': patientInfo.BIS < 40 || patientInfo.BIS > 60}">
                    <span class="label">BIS</span>
                    <span class="value">{{ patientInfo.BIS }}</span>
                </div>
                <div class="row-item" :class="{'alarm': patientInfo.SBP < 90 || patientInfo.SBP > 120}">
                    <span class="label">SBP</span>
                    <span class="value">{{ patientInfo.SBP }}<span class="unit">mmHg</span></span>
                </div>
                <div class="row-item">
                    <span class="label">SPO2</span>
                    <span class="value">{{ patientInfo.SPO2 }}</span>
                </div>
            </div>
            <div class="center-box">
                <img src="@/assets/imgs/main_body_intact.png">
            </div>
            <div class="right-box">
                <div class="info-box">
                    <div class="row-item">
                        <span class="label">手术时间</span>
                        <span class="input-value">{{ patientInfo.time && dateFormater('yyyy-MM-dd HH:mm:ss', patientInfo.time) }}</span>
                    </div>
                    <div class="row-item">
                        <span class="label">手术状态</span>
                        <span class="tag-value" :class="{'normal': !patientInfo.state}">正常</span>
                        <span class="tag-value" :class="{'alarm': patientInfo.state}">异常</span>
                    </div>
                </div>
                <div class="row-item" :class="{'alarm': patientInfo.DBP < 60 || patientInfo.DBP > 90}">
                    <span class="label">DBP</span>
                    <span class="value">{{ patientInfo.DBP }}<span class="unit">mmHg</span></span>
                </div>
                <div class="row-item" :class="{'alarm': patientInfo.HR < 50 || patientInfo.HR > 80}">
                    <span class="label">HR</span>
                    <span class="value">{{ patientInfo.HR }}<span class="unit">次/分</span></span>
                </div>
                <div class="row-item">
                    <span class="label">TEMP</span>
                    <span class="value">{{ patientInfo.TEMP }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang='ts' setup>
import { onMounted, reactive, ref, toRefs, watch } from 'vue'
import { dateFormater } from '@/utils/date-util'
import { useRemoteStore } from '@/stores/remote-info-store';

interface PatientInfoItem {
    name: string // 病人名称
    code: string // 住院号
    time: Date // 手术时间
    state: boolean // 手术状态 false 正常 true 异常
    BIS: number
    SBP: number
    SPO2: number
    DBP: number
    HR: number
    TEMP: number
}

const title = ref('远程控制')
const isRemote = ref(false) // 连接状态
const patientInfo = ref({} as PatientInfoItem)

initData(useRemoteStore().getCurrentRemote())

defineExpose({
    initData
})

function initData(e?: any) {
    const obj = e || {}
    title.value = e.title
    isRemote.value = e.isRemote
    patientInfo.value.state = e.dataAlarm
    patientInfo.value.name = obj.patientName || ''
    patientInfo.value.code = 'XXXXXX'
    patientInfo.value.time = new Date()
    patientInfo.value.BIS = Math.ceil(Math.random() * 100)
    patientInfo.value.SBP = Math.ceil(Math.random() * 100)
    patientInfo.value.SPO2 = Math.ceil(Math.random() * 100)
    patientInfo.value.DBP = Math.ceil(Math.random() * 100)
    patientInfo.value.HR = Math.ceil(Math.random() * 100)
    patientInfo.value.TEMP = Math.ceil(Math.random() * 100)
}

</script>

<style lang='scss' scoped>
.remote-part {
    width: 100%;
    height: 100%;
    border: 1px solid $border-color;

    .title {
        width: 100%;
        height: 40px;
        font-size: 20px;
        text-align: center;
        line-height: 40px;
        font-weight: 600;
        color: white;
        background: $main-color;
    }
    .content {
        width: 100%;
        height: calc(100% - 40px);
        padding: 20px 50px;
        display: flex;
        justify-content: space-between;
        .common-box {
            width: 30%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-evenly;
            align-items: center;
        }
        .left-box {
            @extend .common-box;
            .label {
                background: $main-color;
            }
        }
        .center-box {
            @extend .common-box;
            img {
                max-width: 100%;
                max-height: 100%;
            }
        }
        .right-box {
            @extend .common-box;
            .label {
                background: #f8b300;
            }
        }
        .row-item {
            width: 100%;
            display: flex;
            justify-content: space-between;
            .label {
                flex-shrink: 0;
                width: 100%;
                height: 40px;
                color: white;
                font-size: 18px;
                line-height: 40px;
                text-align: center;
                border-radius: 5px;
            }
        }
        .info-box, .row-item .value {
            display: none;
        }
        &.is-total {
            .info-box, .row-item .value {
                display: block;
            }
            .label {
                width: calc(50% - 10px);
            }
            .value {
                width: 50%;
                height: 40px;
                border-width: 1px;
                border-style: solid;
                text-align: center;
                border-radius: 5px;
                color: $main-color;
                border-color: $main-color;
                font-size: 22px;
                line-height: 40px;
                font-weight: 600;
                .unit {
                    font-size: 16px;
                    font-family: 400;
                }
            }
            .right-box .value {
                color: #f8b300;
                border-color: #f8b300;
            }
            .row-item.alarm {
                .label {
                    background: red;
                }
                .value {
                    color: red;
                    border-color: red;
                }
            }
            .info-box {
                width: 100%;
                .row-item {
                    padding: 10px 0;
                    height: 40px;
                    justify-content: flex-start;
                    align-items: center;
                    .label {
                        width: 70px;
                        height: 20px;
                        background: transparent;
                        color: $main-color;
                        font-size: 16px;
                        line-height: 20px;
                        font-weight: 600;
                        text-align: left;
                    }
                    .input-value {
                        width: 100%;
                        height: 21px;
                        line-height: 20px;
                        font-size: 16px;
                        color: $main-color;
                        border-bottom: 1px solid $border2-color;
                    }
                    .tag-value {
                        margin-left: 30px;
                        padding: 0 20px;
                        height: 30px;
                        line-height: 30px;
                        font-size: 18px;
                        color: white;
                        font-weight: 600;
                        background: $border2-color;
                        border-radius: 8px;
                        &.normal {
                            background: $main-color;
                        }
                        &.alarm {
                            background: red;
                        }
                    }
                }
            }

        }
    }
}
</style>
