<template>
    <nav-bar :navbar-data="navbarData"></nav-bar>
    <view class="report-detail-container"
        :style="{ marginTop: height +'px', minHeight: 'calc(100vh - '+ height +'px)' }">
        <view v-if="pageLoading">
            <view class="skeleton-box">
                <van-skeleton title row="4" />
                <van-skeleton title avatar avatar-size="50px" row="4" />
                <van-skeleton title row="4" />
                <van-skeleton title avatar avatar-size="50px" row="4" />
            </view>
        </view>
        <view v-else>
            <view class="card">
                <view class="title">{{ inspectionData.itemDesc }}</view>
                <view class="card-content patient-info" v-if="inspectionData">
                    <view class="text">患者：{{ inspectionData.patName }}</view>
                    <view class="text">科室：{{ inspectionData.locDesc }}</view>
                    <view class="text">报告时间：{{ inspectionData.reportDate }} {{ inspectionData.reportTime }}</view>
                </view>
            </view>
            <view class="card">
                <view class="title">项目明细</view>
                <view class="card-content result-content">
                    <view class="cell-item item-hader">
                        <text class="header-t">项目名称</text>
                        <text class="unit">结果/单位</text>
                    </view>
                    <view v-for="(item, index) in lisReportCaseData" :key="index">
                        <view class="cell-item" v-if="item.result !== '阴性' && item.result !== '阳性'">
                            <view class="item-l">
                                <text class="t">{{ item.descripts }}</text>
                                <text class="desc">参考值：{{ item.refRange }} {{ item.unit }}</text>
                            </view>
                            <view class="item-r">
                                <text>{{ item.result }} {{ item.unit }}</text>
                            </view>
                        </view>
                        <view class="cell-item" v-else>
                            <view class="item-l">
                                <text class="t">{{ item.descripts }}</text>
                                <text class="desc">参考值：{{ item.refRange }}</text>
                            </view>
                            <view class="item-r">
                                <text :class="item.result == '阳性' ? 'c-red' : ''">{{ item.result }}</text>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="btnbox">
                <navigator class="btn" url="/pages/index/pages/reportRetrieval/inspection/trend/trend">历次报告趋势</navigator>
            </view>
        </view>
    </view>
</template>

<script>
import $http from "@/utils/https";
import Util from '@/utils/utils';
import httpConfig from '@/utils/httpConfig'
import navBar from '@/components/navBar/index'
import VanSkeleton from '@/components/skeleton/index'
const app = getApp()
export default {
    components: {
        'nav-bar': navBar,
        'van-skeleton': VanSkeleton,
    },
    data() {
        return {
            pageLoading: true,
            height: app.globalData.height,
            windowHost: httpConfig && httpConfig.ipDeault,
            navbarData: {
                isGoHome: true,
                isGoBack: true,
                title: "报告查询详情"
            },
            userData: [],
            lisReportID: null, // 报告记录ID
            inspectionData: null, // 检测项目数据
            lisReportCaseData: [], // 检测项目详细检验项数据集
            trendStatus: false, // 历次报告趋势
        }
    },
    onLoad(options) {
        const self = this
        const reportRecordCurrentData = app.globalData.reportRecordCurrentData
        console.log(reportRecordCurrentData)
        if (reportRecordCurrentData) {
            self.lisReportID = reportRecordCurrentData.id
            self.inspectionData = reportRecordCurrentData
        }
        self.getDetail().then(data => {
            setTimeout(function () {
                self.pageLoading = false
            }, 500)
        }).catch(err => {
            self.pageLoading = false
        })
    },
    methods: {
        getDetail() {
            const self = this
            const { lisReportID } = self
            return new Promise((resolve, reject) => {
                let data = {
                    params: [{
                        "lisReportID": lisReportID
                    }]
                }
                uni.showLoading({
                    title: '数据加载中...',
                })
                $http.post("urlS", self, {
                    namespace: "Y",
                    code: "03100217",
                    data: data,
                    success: function (res) {
                        console.log(res)
                        uni.hideLoading()
                        if (+res.errorCode === 0) {
                            const repeatFlagArr = res.data.map(item => item.repeatFlag)
                            let trendStatus = false
                            if (repeatFlagArr.indexOf('Y') > -1) trendStatus = true
                            self.setData({
                                trendStatus,
                                lisReportCaseData: res.data
                            })
                            resolve(res.data)
                        } else {
                            resolve([])
                        }
                    },
                    fail(err) {
                        uni.hideLoading()
                        reject(err)
                    }
                })
            })
        },
    }
}
</script>

<style>
 @import "../style/inspection.css";
</style>