<template>
    <page-layer>
    <template #header>
          <el-input v-model="queryuploadTerm.patNo" clearable placeholder="住院号"
                    @blur="patNo = $event.target.value.trim()" @keyup.enter="queryPage" style="width: 110px"></el-input>
        <el-input v-model="queryuploadTerm.times" clearable placeholder="住院次数"
                  @blur="times = $event.target.value.trim()"  style="width: 80px"></el-input>
        <el-input v-model="queryuploadTerm.ledgerSn" clearable placeholder="账页号"
                  @blur="times = $event.target.value.trim()"  style="width: 80px"></el-input>
        <span>结算时间</span>
        <el-date-picker
                v-model="queryuploadTerm.setlDateRange"
                type="daterange"
                format="YYYY-MM-DD"
                placeholder="结算开始日期"
                range-separator="至"
                start-placeholder="结算开始日期"
                end-placeholder="结算结束日期"
                :shortcuts="clockinShortcuts"
                style="width: 180px"
                value-format="YYYY-MM-DD"
        />
          <el-button icon="Search"  type="primary" @click="queryPage">查询</el-button>
         <el-button type="primary" @click="ExportToExcel">导出Excel</el-button>
    </template>
    <template #main>
      <el-table ref="drgGroupTableRef" :data="queryuploadTerm.list" :height="tableHeight"   border highlight-current-row >
        <el-table-column prop="patNo" label="住院号" width="80"></el-table-column>
        <el-table-column prop="times" label="住院次数" width="80"></el-table-column>
          <el-table-column prop="ledgerSn" label="账页号" width="80"></el-table-column>
        <el-table-column prop="code" label="分组编码" width="80"></el-table-column>
        <el-table-column prop="name" label="分组名称" width="200"></el-table-column>
        <el-table-column prop="weight" label="权重" width="90"></el-table-column>
        <el-table-column prop="bl" label="病历类型" width="130"></el-table-column>
        <el-table-column prop="profit" label="盈亏额" width="130"></el-table-column>
        <el-table-column prop="feeStand" label="标杆费用" width="130" ></el-table-column>
          <el-table-column prop="totalFee" label="总费用" width="130" ></el-table-column>
          <el-table-column prop="setlTime" label="结算时间" width="130" ></el-table-column>
        <el-table-column prop="groupMessages" label="分组提示" ></el-table-column>
      </el-table>
      <el-pagination
              :current-page="queryuploadTerm.currentPage"
              :page-size="queryuploadTerm.pageSize"
              :page-sizes="[10, 20, 30, 40, 50, 100]"
              :total="queryuploadTerm.total"
              layout="total, sizes, prev, pager, next, jumper"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
      ></el-pagination>
    </template>
    </page-layer>
</template>

<script setup name='DrgGroupResult'>
import {clockinShortcuts} from '@/data/shortcuts'
import {onMounted,ref,onActivated} from "vue";
import {getServerDateApi} from "@/api/public-api";
import {getDateRangeFormatDate} from "@/utils/date";
import {downloadExcel} from "@/utils/excel";
import moment from "moment";
import PageLayer from "@/layout/PageLayer";
import store from '@/store';
import router from "@/router";
import sleep from "@/utils/sleep";
import {
    queryDrgGroupPage
} from '@/api/medical-insurance/si-setl-upload';
const windowSize = store.state.app.windowSize;
const tableHeight = ref(windowSize.h - 70)
const emit = defineEmits(['close'])

const dialog = ref(true)
const uploadInfoData = ref([])
const  queryuploadTerm = ref({
  patNo:"",
  times:null,
  ledgerSn:null,
  currentPage:1,
  pageSize:40,
  setlDateRange:[clockinShortcuts[0].value[0], clockinShortcuts[0].value[1]],
  setlStartTime:"",
  setlEndTime:"",
  list:[],
  total: 0
})

const ExportToExcel = async () => {
    createQuery()
    const data = {
        param: queryuploadTerm.value,
        url: '/setlListUpld/exportDrgGroupInfo',
        fileName: '分组信息.xlsx',
    }
    setTimeout(() => {
        downloadExcel(data)
    }, 500)
}

function createQuery() {
    let setlDates = getDateRangeFormatDate(queryuploadTerm.value.setlDateRange)
    queryuploadTerm.value.setlStartTime =setlDates.startTime
    queryuploadTerm.value.setlEndTime =setlDates.endTime
}

const queryPage=async () =>{
    createQuery()
    queryDrgGroupPage(queryuploadTerm.value).then((res) => {
      queryuploadTerm.value.list = res.records?res.records:[]
      queryuploadTerm.value.total =res.total
    })

}
onActivated(async () => {
    const params = router.currentRoute.value.query
    if (params && params.patNo && params.times && params.ledgerSn ) {
        queryuploadTerm.value.times = params.times
        queryuploadTerm.value.patNo = params.patNo
        queryuploadTerm.value.ledgerSn = params.ledgerSn
        queryuploadTerm.value.setlDateRange = []
        await sleep(300);
    }
    await queryPage()
})

onMounted( () => {

})

const handleSizeChange = (val) => {
  queryuploadTerm.value.pageSize = val
  queryPage()

}
const handleCurrentChange = (val) => {
  queryuploadTerm.value.currentPage = val
  queryPage()
}
</script>

<style scoped>
  .maxhight{
    height: 950px;
    overflow: auto;
  }
</style>
