<template>
    <page-layer>
        <template #header>
            <el-date-picker v-model="dateRange" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" :shortcuts="shortcuts"> </el-date-picker>
            <el-input v-model="ill" clearable style="width: 220px" placeholder="请输入关键字">
                <template #prepend>诊断</template>
            </el-input>
            <el-button type="primary" icon="Search" @click="query" style="margin-left: 5px">查询</el-button>
            <el-button type="primary" icon="Download" @click="exportData" style="margin-left: 5px">导出</el-button>
        </template>
        <template #main>
            <xc-table :data="returnData" localPaging :height="105">
                <el-table-column type="index" label="序号" align="center"></el-table-column>
                <template v-for="col in returnData.tableDisplays">
                    <el-table-column v-if="col.sortable" :prop="col.prop" :label="col.label" :width="col.width"
                        :align="col.align" sortable show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column v-else :prop="col.prop" :label="col.label" :width="col.width" :align="col.align"
                        show-overflow-tooltip>
                    </el-table-column>
                </template>
            </xc-table>
        </template>
    </page-layer>
</template>
<script setup name="MzSpecialDisease">
import PageLayer from '@/layout/PageLayer.vue'
import { reactive, ref } from '@vue/reactivity'
import { shortcuts, clockinShortcuts } from '@/data/shortcuts'
import { formatDate, getDateRangeFormatDate } from '@/utils/date'
import { selectReportPortalMenu, exportReportPortalData } from '@/api/reports/high-report'
import XcTable from '@/components/xiao-chan/xc-table/XcTable.vue'

const start = formatDate(clockinShortcuts[1].value[0]);
const end = formatDate(clockinShortcuts[1].value[1]);
const ill = ref('');
const queryTerm = reactive({
    startTime: "",
    endTime: "",
    diagn: "",
    reportId: "mz_tsb",
    menuId: "118",
    type: "1",
});
onMounted(() => {
    queryTerm.startTime = start;
    queryTerm.endTime = end + " 23:59:59";
    dateRange.value = [start, end];
    queryTerm.diagn = ill.value;
    query();
});
const dateRange = ref([]);
const returnData = ref({
    currentPage: 1,
    pageSize: 30,
    total: 0,
    data: []
});

const query = async () => {
    if (dateRange.value) {
        let dateS = getDateRangeFormatDate(dateRange.value);
        queryTerm.startTime = dateS.startTime;
        queryTerm.endTime = dateS.endTime;
        queryTerm.diagn = ill.value;
    }
    else {
        queryTerm.startTime = start;
        queryTerm.endTime = end;
        queryTerm.diagn = ill.value;
        ElMessage({
            type: "info",
            message: "默认查询本月的数据",
            duration: 2500,
            showClose: true,
        });
    }
    selectReportPortalMenu(queryTerm)
        .then((res) => {
            returnData.value.tableDisplays = res.tableDisplays
            returnData.value.data = res.dataList
            returnData.value.total = returnData.value.data.length
        });
};
const exportData = () => {
    if (returnData.value.data.length <= 0) {
        ElMessage({
            message: '没有可以导出的数据！',
            type: 'warning',
            duration: 2500,
            showClose: true,
        })
    }
    queryTerm.diagn = ill.value;
    // 导出excel表格标题
    queryTerm.exportName = '门诊特殊病统计';
    exportReportPortalData(queryTerm)
}
</script>