CovidExamResult.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <el-container>
  3. <el-header height="36px" style="margin-top: 8px">
  4. <el-date-picker
  5. v-model="dateRange"
  6. type="datetimerange"
  7. range-separator="至"
  8. start-placeholder="开始日期"
  9. end-placeholder="结束日期"
  10. :shortcuts="shortcuts"
  11. ></el-date-picker>
  12. <span></span>
  13. <el-select v-model="type" style="width: 130px">
  14. <el-option v-for="item in types" :key="item.code" :value="item.code" :label="item.name"></el-option>
  15. </el-select>
  16. <span></span>
  17. <el-button type="primary" icon="el-icon-search" @click="fetchResult">查询</el-button>
  18. <el-button type="primary" icon="el-icon-upload" @click="exportExcel">导出Excel</el-button>
  19. </el-header>
  20. <el-main>
  21. <el-table :data="list" stripe :height="tableHeight">
  22. <el-table-column type="index"></el-table-column>
  23. <el-table-column prop="ptntName" label="姓名"></el-table-column>
  24. <el-table-column prop="idCard" label="身份证"></el-table-column>
  25. <el-table-column prop="itmStrValue" label="检测结果"></el-table-column>
  26. <el-table-column prop="ordrCreateDate" label="送检时间"></el-table-column>
  27. </el-table>
  28. <el-pagination
  29. @size-change="handleSizeChange"
  30. @current-change="handleCurrentChange"
  31. :current-page="currentPage"
  32. :page-sizes="[15, 30, 45, 70, 100]"
  33. :page-size="pageSize"
  34. layout="total, sizes, prev, pager, next, jumper"
  35. :total="totalSize"
  36. style="margin-top: 5px"
  37. ></el-pagination>
  38. </el-main>
  39. </el-container>
  40. </template>
  41. <script>
  42. import {ref} from 'vue'
  43. import {formatDate, formatDatetime} from '@/utils/date'
  44. import {shortcuts} from '@/data/shortcuts'
  45. import {fetchCovidExamData} from '@/api/inspections'
  46. import store from '@/store'
  47. import {writeExcelFile, createWorkSheet} from '@/utils/excel'
  48. import {ElMessage} from 'element-plus'
  49. export default {
  50. setup() {
  51. const windowSize = store.state.app.windowSize
  52. const tableHeight = windowSize.h - 85
  53. const dateRange = ref(null)
  54. const types = initTypes()
  55. const type = ref(1)
  56. const totalSize = ref(0)
  57. const list = ref([])
  58. const pageSize = ref(30)
  59. const currentPage = ref(1)
  60. const handleSizeChange = (val) => {
  61. pageSize.value = val
  62. fetchResult()
  63. }
  64. const handleCurrentChange = (val) => {
  65. currentPage.value = val
  66. fetchResult()
  67. }
  68. const fetchResult = () => {
  69. if (!dateRange.value) {
  70. ElMessage({
  71. message: '请选择时间范围',
  72. type: 'warning',
  73. duration: 2000,
  74. showClose: true,
  75. })
  76. return
  77. }
  78. const param = {
  79. start: formatDatetime(dateRange.value[0]),
  80. end: formatDatetime(dateRange.value[1]),
  81. currentPage: currentPage.value,
  82. pageSize: pageSize.value,
  83. type: type.value,
  84. }
  85. fetchCovidExamData(param).then((res) => {
  86. totalSize.value = res.totalSize
  87. list.value = res.list
  88. })
  89. }
  90. const exportExcel = () => {
  91. if (!dateRange.value) {
  92. ElMessage({
  93. message: '请选择时间范围',
  94. type: 'warning',
  95. duration: 2000,
  96. showClose: true,
  97. })
  98. return
  99. }
  100. store.commit('app/setLoading', true)
  101. const param = {
  102. start: formatDate(dateRange.value[0]),
  103. end: formatDate(dateRange.value[1]),
  104. currentPage: 1,
  105. pageSize: -1,
  106. type: type.value,
  107. }
  108. fetchCovidExamData(param).then((res) => {
  109. const titName = type.value === 1 ? '新冠核酸检测' : '新冠抗体检测'
  110. const fileName = titName + '(' + formatDate(dateRange.value[0]) + ' - ' + formatDate(dateRange.value[1]) + ').xlsx'
  111. setTimeout(() => {
  112. const title = {
  113. ptntName: '姓名',
  114. idCard: '身份证',
  115. itmStrValue: '检测结果',
  116. ordrCreateDate: '送检时间',
  117. }
  118. const fields = ['ptntName', 'idCard', 'itmStrValue', 'ordrCreateDate']
  119. const workSheet = createWorkSheet(res.list, fields, title)
  120. writeExcelFile(workSheet, fileName)
  121. }, 50)
  122. })
  123. }
  124. return {
  125. tableHeight,
  126. shortcuts,
  127. dateRange,
  128. types,
  129. type,
  130. fetchResult,
  131. totalSize,
  132. list,
  133. pageSize,
  134. currentPage,
  135. handleSizeChange,
  136. handleCurrentChange,
  137. exportExcel,
  138. }
  139. },
  140. }
  141. function initTypes() {
  142. return [
  143. {code: 1, name: '核酸检测'},
  144. {code: 2, name: '抗体检测'},
  145. ]
  146. }
  147. </script>