<template>
    <page-layer>
        <template #header>
            出院时间：
            <el-date-picker style="width: 180px" v-model="queryParam.date" type="daterange" format="YYYY-MM-DD"
                            value-format="YYYY-MM-DD"/>
            科室：
            <el-select style="width: 200px"
                       v-model="queryParam.deptCode"
                       clearable
                       collapse-tags
                       filterable
                       multiple
                       remote>
                <el-option v-for="item in deptList" :key="item.code" :label="item.name" :value="item.code">
                    <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                    <el-divider direction="vertical"></el-divider>
                    <span>{{ item.name }}</span>
                </el-option>
            </el-select>
            管床医生：
            <SelectStaffCode style="width: 120px" v-model="queryParam" :name="['tubeBedDoctor', 'tubeBedDoctorName']"/>

            <el-button @click="queryClick">查询</el-button>

            <el-button @click="excelClick">导出excel</el-button>
        </template>

        <template #main>
            <xc-table :local-data="data" :final-height="getWindowSize.h / 1.2">
                <el-table-column type="expand">
                    <template #default="{row}">
                        <JsonViewer :value="row.mapMessage"
                                    copyable
                                    :expandDepth="3"/>
                    </template>
                </el-table-column>
                <el-table-column prop="inpatientNo" label="住院号" width="120"/>
                <el-table-column prop="admissTimes" label="次数" width="40"/>
                <el-table-column prop="name" label="姓名" width="220"/>
                <el-table-column prop="gradingScale" label="病历评级"/>
                <el-table-column prop="age" label="年龄"/>
                <el-table-column prop="clinicDiagStr" label="门（急）诊诊断"/>
                <el-table-column prop="admissDiag" label="入院诊断"/>
                <el-table-column prop="admissDate" label="入院时间" width="220"/>
                <el-table-column prop="deptName" label="入院科室" width="220"/>
                <el-table-column prop="zkListName" label="转科"/>
                <el-table-column prop="disDate" label="出院时间"/>
                <el-table-column prop="admissDay" label="住院天数"/>
                <el-table-column prop="totalCharge" label="住院费用"/>
                <el-table-column prop="disDeptName" label="出院科室"/>
                <el-table-column prop="disDiag" label="出院主诊断"/>
                <el-table-column prop="typing" label="病历分型"/>
                <el-table-column prop="deptDirectorName" label="主任医生"/>
                <el-table-column prop="consultPhysicianName" label="主治医生"/>
                <el-table-column prop="tubeBedDoctorName" label="管床医生" width="220"/>
                <el-table-column prop="deathName" label="是否死亡"/>
                <el-table-column prop="fdcrb" label="法定传染病"/>
                <el-table-column prop="ssbm" label="手术编码"/>
                <el-table-column prop="ssmc" label="手术名称"/>
                <el-table-column prop="operatorName" label="术者"/>
                <el-table-column prop="level" label="手术级别"/>
                <el-table-column prop="anaesthesiaName" label="麻醉方式"/>
                <el-table-column prop="qjcs" label="抢救次数"/>
                <el-table-column label="切口分类" prop="cutName"/>
                <el-table-column prop="pathologicDiagStr" label="病理诊断"/>
                <el-table-column prop="allergicMedicine" label="药物过敏"/>
                <el-table-column prop="kssName" label="抗生素使用"/>
                <el-table-column prop="xjpyName" label="细菌培养送检"/>
            </xc-table>
        </template>
    </page-layer>
</template>

<script setup name='FinalQualityControl'>
import PageLayer from "@/layout/PageLayer.vue";
import {ref} from "vue";
import {getDept} from "@/api/public-api";
import SelectStaffCode from "@/components/SelectStaffCode.vue";
import {getDateRangeFormatDate} from "@/utils/date";
import XcTable from "@/components/xiao-chan/xc-table/XcTable.vue";
import {getWindowSize} from "@/utils/window-size";
import {isDev} from "@/utils/public";
import {ExcelName} from "@/utils/ExportExcel";
import {terminalPatients} from "@/api/zhu-yuan-yi-sheng/emr-control-rule";
import {qieKouName} from "@/components/si-sheet-upload/jieSuanDanXiuGai";

const queryParam = ref({
    date: '',
    deptCode: '',
    tubeBedDoctor: '',
    startDate: '',
    endDate: '',
})

const deptList = ref([])
const data = ref([])

const queryClick = () => {

    let {startTime, endTime} = getDateRangeFormatDate(queryParam.value.date)
    queryParam.value.startDate = startTime
    queryParam.value.endDate = endTime

    terminalPatients(queryParam.value).then((res) => {
        data.value = res
        setTheName(data.value)
    })
}


const setTheName = (val) => {
    val.forEach(item => {
        item.cutName = qieKouName(item.cut, item.heal)
        item.kssName = yesOrNo(item.kss)
        item.xjpyName = yesOrNo(item.xjpy)
    })
}


const excelClick = () => {
    let title = {
        inpatientNo: '住院号',
        admissTimes: '次数',
        name: '姓名',
        gradingScale: '病历评级',
        age: '年龄',
        clinicDiagStr: "门（急）诊诊断",
        admissDiag: "入院诊断",
        admissDate: "入院时间",
        deptName: "入院科室",
        zkListName: "转科",
        disDate: "出院时间",
        admissDay: "住院天数",
        totalCharge: "住院费用",
        disDeptName: "出院科室",
        disDiag: "出院主诊断",
        typing: "病历分型",
        deptDirectorName: "主任医生",
        consultPhysicianName: "主治医生",
        tubeBedDoctorName: "管床医生",
        deathName: "是否死亡",
        fdcrb: "法定传染病",
        ssbm: "手术编码",
        ssmc: "手术名称",
        operatorName: "术者",
        level: "手术级别",
        anaesthesiaName: "麻醉方式",
        qjcs: "抢救次数",
        cutName: "切口分类",
        pathologicDiagStr: "病理诊断",
        allergicMedicine: "药物过敏",
        kssName: "抗生素使用",
        xjpyName: "细菌培养送检",
    }
    ExcelName(data.value, title)
}


const yesOrNo = (val) => {
    if (val == 1) {
        return "是";
    }
    if (val == 2) {
        return "否";
    }
    return "";
};

onMounted(() => {
    if (isDev) {
        queryParam.value.date = ['2023-05-10', '2023-05-10']
    }
    getDept().then((res) => {
        deptList.value = res
    });

})
</script>

<style scoped lang="scss">

</style>
