odf_new/odf-uniapp/pages/room/index.vue

180 lines
3.5 KiB
Vue

<template>
<view class="room-page">
<image class="bg-image" src="/static/images/home_bg.png" mode="aspectFill" />
<view class="content">
<!-- 顶部导航栏 -->
<view class="nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="nav-bar-inner">
<image
class="nav-icon"
src="/static/images/ic_back.png"
mode="aspectFit"
@click="goBack"
/>
<text class="nav-title">机房列表</text>
<view class="nav-icon-placeholder" />
</view>
</view>
<!-- 机房列表 -->
<view class="room-list">
<view
class="room-card"
v-for="item in roomList"
:key="item.id"
@click="goRack(item)"
>
<text class="room-name">{{ item.roomName }}</text>
<text class="room-address">{{ item.roomAddress }}</text>
<text class="room-odf">ODF: {{ item.racksCount }}</text>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import { getRoomList } from '@/services/machine'
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 0
const roomList = ref([])
const deptIdRef = ref('')
const pageNum = ref(1)
const pageSize = 20
const totalPage = ref(0)
const loading = ref(false)
async function loadRoomList(isLoadMore = false) {
if (loading.value) return
loading.value = true
try {
const res = await getRoomList(pageNum.value, pageSize, deptIdRef.value)
if (res.code === 200 && res.data) {
totalPage.value = res.data.totalPage || 0
if (isLoadMore) {
roomList.value = [...roomList.value, ...(res.data.result || [])]
} else {
roomList.value = res.data.result || []
}
}
} finally {
loading.value = false
}
}
function goBack() {
uni.navigateBack()
}
function goRack(item) {
uni.navigateTo({
url: '/pages/rack/index?roomId=' + item.id + '&roomName=' + encodeURIComponent(item.roomName)
})
}
onLoad((options) => {
if (options.deptId) {
deptIdRef.value = options.deptId
loadRoomList()
}
})
onPullDownRefresh(() => {
pageNum.value = 1
loadRoomList().finally(() => {
uni.stopPullDownRefresh()
})
})
onReachBottom(() => {
if (pageNum.value >= totalPage.value) return
pageNum.value++
loadRoomList(true)
})
</script>
<style scoped>
.room-page {
position: relative;
min-height: 100vh;
background-color: #F5F5F5;
}
.bg-image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 500rpx;
z-index: 0;
}
.content {
position: relative;
z-index: 1;
}
.nav-bar {
width: 100%;
}
.nav-bar-inner {
display: flex;
align-items: center;
justify-content: space-between;
height: 88rpx;
padding: 0 24rpx;
}
.nav-icon {
width: 44rpx;
height: 44rpx;
}
.nav-icon-placeholder {
width: 44rpx;
height: 44rpx;
}
.nav-title {
font-size: 34rpx;
font-weight: 600;
color: #fff;
}
.room-list {
padding: 16rpx 24rpx;
}
.room-card {
display: flex;
flex-direction: column;
padding: 24rpx;
margin-bottom: 20rpx;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
}
.room-name {
font-size: 30rpx;
font-weight: 500;
color: #333;
margin-bottom: 12rpx;
}
.room-address {
font-size: 26rpx;
color: #666;
margin-bottom: 8rpx;
}
.room-odf {
font-size: 24rpx;
color: #999;
}
</style>