修复已知bug
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view class="contentStyle">
|
||||
<view class="status-bar"></view>
|
||||
<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
|
||||
<uni-nav-bar title="巡检记录" backgroundColor="transparent" :border="false" left-icon="left" @click-left="goBack" />
|
||||
<view class="content-wrap">
|
||||
<!-- 时间选择器 -->
|
||||
@@ -19,17 +19,22 @@
|
||||
</view>
|
||||
<!-- 巡检列表 -->
|
||||
<scroll-view scroll-y class="scroll-view">
|
||||
<view class="list-container" @click="goToInspectionDetail">
|
||||
<view class="card-item" v-for="(item, index) in listData" :key="index">
|
||||
<view class="list-container" v-if="listData.length > 0">
|
||||
<view class="card-item" v-for="(item, index) in listData" :key="index" @click="goToInspectionDetail(item)">
|
||||
<view class="card-head">
|
||||
<text class="address">{{ item.address }}</text>
|
||||
<text class="address">{{ item.locationName }}</text>
|
||||
<text class="status">{{ item.status }}</text>
|
||||
</view>
|
||||
<view class="tag-label">{{ item.type }}</view>
|
||||
<view class="text-row">巡检时间:{{ item.time }}</view>
|
||||
<view class="text-row">巡检人:{{ item.inspector }}</view>
|
||||
<view class="tag-label">{{ item.inspectionType }}</view>
|
||||
<view class="text-row">巡检时间:{{ item.executeDate }}</view>
|
||||
<view class="text-row">巡检人:{{ item.inspectorName }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 暂无数据 -->
|
||||
<view class="empty-wrap" v-if="!loading && listData.length === 0">
|
||||
<uni-icons type="info" size="30" color="#ccc"></uni-icons>
|
||||
<text class="empty-text">暂无数据</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
</view>
|
||||
@@ -37,51 +42,117 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
ref
|
||||
} from 'vue';
|
||||
import {ref} from 'vue'
|
||||
import {onLoad,onReachBottom,onPullDownRefresh} from '@dcloudio/uni-app'
|
||||
import {getInspectionList} from '../api/apiSub.js'
|
||||
import moment from 'moment' // 新增
|
||||
|
||||
// ---------- 基础状态 ----------
|
||||
const datetime = ref('')
|
||||
const showDate = ref('选择日期')
|
||||
const listData = ref([
|
||||
{
|
||||
address: '幸福苑小区1号楼1单元电梯间',
|
||||
status: '已巡检',
|
||||
type: '设备巡检',
|
||||
time: '07:00:00 –09:00:00',
|
||||
inspector: '李祥龙'
|
||||
},
|
||||
{
|
||||
address: '幸福苑小区1号楼1单元电梯间',
|
||||
status: '已巡检',
|
||||
type: '设备巡检',
|
||||
time: '07:00:00 –09:00:00',
|
||||
inspector: '李祥龙'
|
||||
}
|
||||
])
|
||||
|
||||
const listData = ref([])
|
||||
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight || 0)
|
||||
|
||||
const handleChangeTime = (e) => {
|
||||
if (e) {
|
||||
// e 格式为 YYYY-MM-DD,只取 MM-DD
|
||||
showDate.value = e.slice(5)
|
||||
} else {
|
||||
showDate.value = '选择日期'
|
||||
// ---------- 分页状态 ----------
|
||||
const pageNum = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const total = ref(0)
|
||||
const loading = ref(false)
|
||||
const noMore = ref(false)
|
||||
|
||||
// ---------- 初始化 ----------
|
||||
onLoad(() => {
|
||||
// 使用 moment 格式化今天
|
||||
const today = moment().format('YYYY-MM-DD')
|
||||
datetime.value = today
|
||||
showDate.value = moment().format('MM-DD') // 显示 MM-DD
|
||||
fetchList(true)
|
||||
})
|
||||
|
||||
// ---------- 获取列表 ----------
|
||||
const fetchList = async (reset = false) => {
|
||||
if (loading.value) return
|
||||
if (!reset && noMore.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
date: datetime.value, // 已经是 YYYY-MM-DD
|
||||
pageNum: reset ? 1 : pageNum.value,
|
||||
pageSize: pageSize.value
|
||||
}
|
||||
const res = await getInspectionList(params)
|
||||
if (res.code === 200) {
|
||||
const rows = res.rows
|
||||
total.value = res.total || 0
|
||||
if (reset) {
|
||||
listData.value = rows
|
||||
pageNum.value = 1
|
||||
noMore.value = rows.length < pageSize.value
|
||||
} else {
|
||||
listData.value = [...listData.value, ...rows]
|
||||
noMore.value = rows.length < pageSize.value || listData.value.length >= total.value
|
||||
}
|
||||
if (!reset && rows.length > 0) {
|
||||
pageNum.value += 1
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: res.msg || '获取列表失败', icon: 'none' })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取巡检列表失败', err)
|
||||
uni.showToast({ title: '网络异常,请重试', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
}
|
||||
// 返回
|
||||
|
||||
// ---------- 日期变更(使用 moment) ----------
|
||||
const handleChangeTime = (e) => {
|
||||
if (e) {
|
||||
// e 格式为 YYYY-MM-DD,用 moment 解析并格式化为 MM-DD
|
||||
showDate.value = moment(e).format('MM-DD')
|
||||
datetime.value = e
|
||||
} else {
|
||||
// 用户清空日期,可根据业务设置默认值或置空
|
||||
showDate.value = '选择日期'
|
||||
datetime.value = ''
|
||||
// 如果希望清空时不请求,可 return,否则也重置列表
|
||||
}
|
||||
// 重置分页并刷新
|
||||
pageNum.value = 1
|
||||
noMore.value = false
|
||||
fetchList(true)
|
||||
}
|
||||
|
||||
// ---------- 上拉加载更多 ----------
|
||||
onReachBottom(() => {
|
||||
if (!noMore.value && !loading.value) {
|
||||
fetchList(false)
|
||||
}
|
||||
})
|
||||
|
||||
// ---------- 下拉刷新 ----------
|
||||
onPullDownRefresh(() => {
|
||||
pageNum.value = 1
|
||||
noMore.value = false
|
||||
fetchList(true)
|
||||
})
|
||||
|
||||
// ---------- 返回 ----------
|
||||
const goBack = () => {
|
||||
uni.switchTab({
|
||||
url: '/pages/serviceIndex/serviceIndex'
|
||||
})
|
||||
}
|
||||
// 跳转详情
|
||||
const goToInspectionDetail = () =>{
|
||||
|
||||
// ---------- 跳转详情 ----------
|
||||
const goToInspectionDetail = (item) => {
|
||||
uni.navigateTo({
|
||||
url: `/pageSubPack/inspection-revenue/inspection-details`
|
||||
url: `/pageSubPack/inspection-revenue/inspection-details?id=${item.id}`
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -99,8 +170,8 @@
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
height: 46px;
|
||||
width: 100%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.timebox {
|
||||
@@ -214,4 +285,22 @@
|
||||
color: #333;
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
// 暂无数据
|
||||
.empty-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: 200rpx;
|
||||
}
|
||||
.empty-img {
|
||||
width: 240rpx;
|
||||
height: 240rpx;
|
||||
}
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user