index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <div v-loading="loading" class="oa-page" element-loading-text="正在查询空床明细…">
  3. <ContentWrap>
  4. <div class="page-header">
  5. <div class="header-title">
  6. <Icon icon="ep:house" class="title-icon" />
  7. <span>空床明细报表</span>
  8. </div>
  9. </div>
  10. <!-- 筛选区 -->
  11. <el-form :inline="true" class="filter-form" @submit.prevent>
  12. <el-form-item label="院区">
  13. <el-select
  14. v-model="queryCampusIds"
  15. multiple
  16. collapse-tags
  17. collapse-tags-tooltip
  18. clearable
  19. filterable
  20. placeholder="全部院区"
  21. class="campus-select"
  22. >
  23. <el-option
  24. v-for="item in campusOptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="楼栋">
  32. <el-select
  33. v-model="queryBuildIds"
  34. multiple
  35. collapse-tags
  36. collapse-tags-tooltip
  37. clearable
  38. filterable
  39. placeholder="全部楼栋"
  40. class="build-select"
  41. >
  42. <el-option
  43. v-for="item in buildOptions"
  44. :key="item.buildId"
  45. :label="item.label"
  46. :value="item.buildId"
  47. />
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item label="床位状态">
  51. <el-select v-model="queryStatus" class="status-select">
  52. <el-option label="空床" :value="0" />
  53. <el-option label="在住" :value="1" />
  54. <el-option label="全部" :value="-1" />
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item label="房号/床号">
  58. <el-input
  59. v-model="queryBedName"
  60. placeholder="房间号或床位号关键字"
  61. clearable
  62. class="keyword-input"
  63. @keyup.enter="handleQuery"
  64. />
  65. </el-form-item>
  66. <el-form-item>
  67. <el-button type="primary" :icon="Search" @click="handleQuery">查询</el-button>
  68. <el-button :icon="RefreshLeft" @click="handleReset">重置</el-button>
  69. <el-button type="success" :icon="Download" :loading="exporting" @click="handleExport">
  70. 导出 Excel
  71. </el-button>
  72. </el-form-item>
  73. </el-form>
  74. <!-- 汇总条(恒按空床口径,来自 summary 接口,不受床位状态筛选影响) -->
  75. <div class="summary-grid">
  76. <div class="summary-card blue">
  77. <div class="s-label"><Icon icon="ep:moon" />空床总数</div>
  78. <div class="s-value">{{ summary.emptyBedCount }}<span class="s-unit">张</span></div>
  79. </div>
  80. <div class="summary-card cyan">
  81. <div class="s-label"><Icon icon="ep:office-building" />涉及空床房间</div>
  82. <div class="s-value">{{ summary.emptyRoomCount }}<span class="s-unit">间</span></div>
  83. </div>
  84. <div class="summary-card green">
  85. <div class="s-label"><Icon icon="ep:home-filled" />整间空房</div>
  86. <div class="s-value">{{ summary.fullEmptyRoomCount }}<span class="s-unit">间</span></div>
  87. </div>
  88. <div class="summary-card orange">
  89. <div class="s-label"><Icon icon="ep:files" />当前筛选结果</div>
  90. <div class="s-value">{{ total }}<span class="s-unit">条</span></div>
  91. </div>
  92. </div>
  93. </ContentWrap>
  94. <ContentWrap class="table-wrap">
  95. <div class="panel-title">
  96. 床位明细
  97. <span class="title-tip">按 院区 / 楼栋 / 楼层 / 房间 排序,默认仅展示空床</span>
  98. </div>
  99. <el-table :data="rows" border stripe v-loading="loading">
  100. <el-table-column type="index" label="序号" width="60" align="center" />
  101. <el-table-column prop="tenantName" label="机构" min-width="140" show-overflow-tooltip />
  102. <el-table-column prop="buildName" label="楼栋" min-width="130" show-overflow-tooltip />
  103. <el-table-column prop="floorName" label="楼层" min-width="90" />
  104. <el-table-column prop="roomName" label="房间号" min-width="100" />
  105. <el-table-column prop="bedName" label="床位号" min-width="90" />
  106. <el-table-column label="房间床位" width="90" align="center">
  107. <template #default="{ row }">{{ row.roomUsedCount }}/{{ row.roomBedCount }}</template>
  108. </el-table-column>
  109. <el-table-column label="状态" width="90" align="center">
  110. <template #default="{ row }">
  111. <el-tag :type="row.bedStatus === 0 ? 'warning' : 'success'" effect="light">
  112. {{ row.bedStatus === 0 ? '空床' : '在住' }}
  113. </el-tag>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <div class="pager">
  118. <el-pagination
  119. v-model:current-page="pageNo"
  120. v-model:page-size="pageSize"
  121. :page-sizes="[20, 50, 100, 200]"
  122. :total="total"
  123. layout="total, sizes, prev, pager, next, jumper"
  124. background
  125. @current-change="loadPage"
  126. @size-change="handleSizeChange"
  127. />
  128. </div>
  129. </ContentWrap>
  130. </div>
  131. </template>
  132. <script lang="ts" setup>
  133. import { Download, RefreshLeft, Search } from '@element-plus/icons-vue'
  134. import { getBuildList } from '@/api/system/badManage'
  135. import { exportWithCustomHeaders } from '@/utils/excel-export'
  136. import { getCampusOptions } from '../../overview/campus-data'
  137. import {
  138. fetchEmptyBedPage,
  139. fetchEmptyBedSummary,
  140. type EmptyBedPageRow,
  141. type EmptyBedSummary
  142. } from '../occupancy-api'
  143. defineOptions({ name: 'OaOccupancyEmptyBed' })
  144. const message = useMessage()
  145. const campusOptions = getCampusOptions()
  146. const loading = ref(false)
  147. const exporting = ref(false)
  148. const queryCampusIds = ref<number[]>(campusOptions.map((item) => item.value))
  149. const queryBuildIds = ref<number[]>([])
  150. const queryStatus = ref<number>(0)
  151. const queryBedName = ref('')
  152. const rows = ref<EmptyBedPageRow[]>([])
  153. const total = ref(0)
  154. const summary = ref<EmptyBedSummary>({
  155. emptyBedCount: 0,
  156. emptyRoomCount: 0,
  157. fullEmptyRoomCount: 0
  158. })
  159. const buildOptions = ref<{ buildId: number; label: string }[]>([])
  160. const pageNo = ref(1)
  161. const pageSize = ref(20)
  162. /** 当前筛选条件(院区为空 = 按登录人机构范围) */
  163. const buildFilterParams = () => {
  164. const ids = queryCampusIds.value.length ? queryCampusIds.value : []
  165. return {
  166. tenantIds: ids.length ? ids : undefined,
  167. buildIds: queryBuildIds.value.length ? queryBuildIds.value : undefined,
  168. bedName: queryBedName.value.trim() || undefined
  169. }
  170. }
  171. /** 楼栋下拉:所选院区的全部楼栋(getBuildList 项主键为 id,与明细行 buildId 同源) */
  172. const loadBuildOptions = async () => {
  173. const ids = queryCampusIds.value.length
  174. ? queryCampusIds.value
  175. : campusOptions.map((item) => item.value)
  176. const nameMap = new Map(campusOptions.map((item) => [item.value, item.label]))
  177. const groups = await Promise.all(
  178. ids.map(async (id) => {
  179. try {
  180. const list = await getBuildList({ tenantIds: id })
  181. return (list || []).map((b: any) => ({
  182. buildId: Number(b.id ?? b.buildId),
  183. label: `${nameMap.get(id) || id} / ${b.buildName}`
  184. }))
  185. } catch {
  186. return []
  187. }
  188. })
  189. )
  190. buildOptions.value = groups.flat().filter((item) => !Number.isNaN(item.buildId))
  191. queryBuildIds.value = queryBuildIds.value.filter((id) =>
  192. buildOptions.value.some((item) => item.buildId === id)
  193. )
  194. }
  195. /** 查询明细分页(服务端分页) */
  196. const loadPage = async () => {
  197. loading.value = true
  198. try {
  199. const res = await fetchEmptyBedPage({
  200. pageNo: pageNo.value,
  201. pageSize: pageSize.value,
  202. ...buildFilterParams(),
  203. // 全部状态不传 status
  204. status: queryStatus.value === -1 ? '' : queryStatus.value
  205. })
  206. rows.value = res.list
  207. total.value = res.total
  208. } finally {
  209. loading.value = false
  210. }
  211. }
  212. /** 汇总恒以“空床”口径统计,不随床位状态筛选变化 */
  213. const loadSummary = async () => {
  214. try {
  215. summary.value = await fetchEmptyBedSummary(buildFilterParams())
  216. } catch {
  217. // 汇总失败不阻断明细浏览
  218. }
  219. }
  220. const handleQuery = () => {
  221. pageNo.value = 1
  222. loadPage()
  223. loadSummary()
  224. }
  225. const handleSizeChange = () => {
  226. pageNo.value = 1
  227. loadPage()
  228. }
  229. const handleReset = () => {
  230. queryCampusIds.value = campusOptions.map((item) => item.value)
  231. queryBuildIds.value = []
  232. queryStatus.value = 0
  233. queryBedName.value = ''
  234. loadBuildOptions()
  235. handleQuery()
  236. }
  237. /** 导出:按当前筛选(含状态)拉全量后前端生成 Excel */
  238. const handleExport = async () => {
  239. exporting.value = true
  240. try {
  241. const all: EmptyBedPageRow[] = []
  242. const pageSizeForExport = 200
  243. let page = 1
  244. // 服务端单页上限 200,循环拉取全部筛选结果
  245. for (;;) {
  246. const res = await fetchEmptyBedPage({
  247. pageNo: page,
  248. pageSize: pageSizeForExport,
  249. ...buildFilterParams(),
  250. status: queryStatus.value === -1 ? '' : queryStatus.value
  251. })
  252. all.push(...res.list)
  253. if (all.length >= res.total || res.list.length === 0) break
  254. page += 1
  255. if (page > 100) break
  256. }
  257. if (!all.length) {
  258. message.warning('当前筛选条件下暂无数据可导出')
  259. return
  260. }
  261. exportWithCustomHeaders(
  262. all.map((row) => ({
  263. tenantName: row.tenantName,
  264. buildName: row.buildName,
  265. floorName: row.floorName,
  266. roomName: row.roomName,
  267. bedName: row.bedName,
  268. roomBedText: `${row.roomUsedCount}/${row.roomBedCount}`,
  269. statusText: row.bedStatus === 0 ? '空床' : '在住'
  270. })),
  271. [
  272. { key: 'tenantName', title: '机构', width: 18 },
  273. { key: 'buildName', title: '楼栋', width: 16 },
  274. { key: 'floorName', title: '楼层', width: 10 },
  275. { key: 'roomName', title: '房间号', width: 12 },
  276. { key: 'bedName', title: '床位号', width: 10 },
  277. { key: 'roomBedText', title: '房间床位(在住/总数)', width: 16 },
  278. { key: 'statusText', title: '状态', width: 8 }
  279. ],
  280. `空床明细_${new Date().toISOString().slice(0, 10)}.xlsx`,
  281. '空床明细'
  282. )
  283. message.success('导出成功')
  284. } finally {
  285. exporting.value = false
  286. }
  287. }
  288. watch(queryCampusIds, () => loadBuildOptions())
  289. onMounted(async () => {
  290. await loadBuildOptions()
  291. handleQuery()
  292. })
  293. </script>
  294. <style lang="scss" scoped>
  295. .oa-page {
  296. .page-header {
  297. margin-bottom: 14px;
  298. .header-title {
  299. display: flex;
  300. align-items: center;
  301. font-size: 18px;
  302. font-weight: 600;
  303. color: #303133;
  304. .title-icon {
  305. margin-right: 8px;
  306. font-size: 22px;
  307. color: #409eff;
  308. }
  309. }
  310. }
  311. .filter-form {
  312. margin-top: 4px;
  313. .campus-select {
  314. width: 280px;
  315. max-width: 52vw;
  316. }
  317. .build-select {
  318. width: 240px;
  319. max-width: 48vw;
  320. }
  321. .status-select {
  322. width: 100px;
  323. }
  324. .keyword-input {
  325. width: 200px;
  326. }
  327. }
  328. .api-tip {
  329. margin: 4px 0 14px;
  330. }
  331. .summary-grid {
  332. display: grid;
  333. grid-template-columns: repeat(4, 1fr);
  334. gap: 12px;
  335. @media (max-width: 992px) {
  336. grid-template-columns: repeat(2, 1fr);
  337. }
  338. .summary-card {
  339. padding: 14px 18px;
  340. border-radius: 8px;
  341. color: #fff;
  342. .s-label {
  343. display: flex;
  344. align-items: center;
  345. font-size: 13px;
  346. opacity: 0.95;
  347. .el-icon {
  348. margin-right: 6px;
  349. font-size: 16px;
  350. }
  351. }
  352. .s-value {
  353. margin-top: 8px;
  354. font-size: 28px;
  355. font-weight: 700;
  356. line-height: 1.1;
  357. .s-unit {
  358. margin-left: 4px;
  359. font-size: 13px;
  360. font-weight: 400;
  361. opacity: 0.85;
  362. }
  363. }
  364. &.blue {
  365. background: linear-gradient(135deg, #5b9bff 0%, #2f7cf6 100%);
  366. }
  367. &.cyan {
  368. background: linear-gradient(135deg, #4fd0e0 0%, #1fa9bf 100%);
  369. }
  370. &.green {
  371. background: linear-gradient(135deg, #62d391 0%, #36a866 100%);
  372. }
  373. &.orange {
  374. background: linear-gradient(135deg, #ffb066 0%, #f5851d 100%);
  375. }
  376. }
  377. }
  378. .table-wrap {
  379. margin-top: 12px;
  380. }
  381. .pager {
  382. display: flex;
  383. justify-content: flex-end;
  384. margin-top: 14px;
  385. }
  386. .panel-title {
  387. position: relative;
  388. padding-left: 10px;
  389. margin-bottom: 12px;
  390. font-size: 15px;
  391. font-weight: 600;
  392. color: #303133;
  393. &::before {
  394. content: '';
  395. position: absolute;
  396. left: 0;
  397. top: 2px;
  398. width: 4px;
  399. height: 16px;
  400. background: #409eff;
  401. border-radius: 2px;
  402. }
  403. .title-tip {
  404. margin-left: 10px;
  405. font-size: 12px;
  406. font-weight: 400;
  407. color: #a8abb2;
  408. }
  409. }
  410. }
  411. </style>