修复bug

This commit is contained in:
zhouyanli
2026-08-13 14:12:11 +08:00
parent 94146ce27a
commit 32765cc004
12 changed files with 145 additions and 48 deletions

View File

@@ -12,7 +12,7 @@
<!-- 报修类型Tab -->
<scroll-view class="scroll-container" scroll-y="true"
:lower-threshold="100">
:lower-threshold="100" @scrolltolower="loadMore">
<view class="repair-type-tabs">
<view
class="type-tab"
@@ -102,12 +102,18 @@
<text class="empty-text">暂无数据</text>
</view>
</view>
<!-- 加载更多提示 -->
<view v-if="repairList.length > 0" class="load-more-tip">
<text v-if="loading">加载中...</text>
<text v-else-if="!hasMoreData">没有更多数据了</text>
</view>
</scroll-view>
</view>
</template>
<script setup>
import { ref, watch } from 'vue';
import { ref, watch, computed } from 'vue';
import { onLoad, onShow, onUnload } from '@dcloudio/uni-app';
import { getQueryRepair } from '../api/api.js';
@@ -120,6 +126,8 @@ const repairList = ref([]);
const loading = ref(false);
const pageNum = ref(1);
const pageSize = ref(10);
const total = ref(0);
const hasMoreData = computed(() => repairList.value.length < total.value);
const maintenanceItemId = ref('');
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight || 0)
@@ -138,14 +146,23 @@ const getStatusInfo = (val) => {
};
// 获取报修列表
const fetchRepairList = async () => {
// reset = true 时重置到第一页;否则按当前 pageNum 追加加载
const fetchRepairList = async (reset = false) => {
const villageId = uni.getStorageSync('currentVillageId');
if (!villageId || villageId === '0') {
uni.showToast({ title: '请先选择小区', icon: 'none' });
return;
}
// 防止重复请求
if (loading.value) return;
loading.value = true;
if (reset) {
pageNum.value = 1;
repairList.value = [];
total.value = 0;
}
try {
const params = {
villageId,
@@ -158,7 +175,8 @@ const fetchRepairList = async () => {
// console.log('接口返回:', res);
if (res.code === 200) {
const list = res.rows || [];
repairList.value = list.map(item => {
total.value = Number(res.total) || 0;
const mapped = list.map(item => {
const statusInfo = getStatusInfo(item.problemStatus);
const images = item.problemImageUrl ? item.problemImageUrl.split(',').filter(Boolean) : [];
if (statusInfo) {
@@ -166,6 +184,7 @@ const fetchRepairList = async () => {
}
return { ...item, imageList: images };
});
repairList.value = pageNum.value === 1 ? mapped : [...repairList.value, ...mapped];
} else {
uni.showToast({ title: res.msg || '获取失败', icon: 'none' });
}
@@ -176,10 +195,16 @@ const fetchRepairList = async () => {
}
};
// 监听状态变化自动刷新(切换 tab 时重置页码
watch(activeStatus, () => {
pageNum.value = 1;
// 加载更多(滚动到底部触发
const loadMore = () => {
if (loading.value || !hasMoreData.value) return;
pageNum.value++;
fetchRepairList();
};
// 监听状态变化自动刷新(切换 tab 时重置到第一页)
watch(activeStatus, () => {
fetchRepairList(true);
});
function publicClick(){
@@ -219,11 +244,11 @@ const goDetail = (item) => {
onLoad(() => {
// maintenanceItemId.value = option.maintenanceProjectId || '' // 接收维修项目id
fetchRepairList()
fetchRepairList(true)
});
onShow(() => {
// 从其他页面返回时刷新列表
fetchRepairList()
fetchRepairList(true)
});
onUnload(() =>{
@@ -382,6 +407,10 @@ onUnload(() =>{
color: #333;
padding-right: 20rpx;
width: 77%;
word-break: break-all;
word-wrap: break-word;
white-space: normal;
line-height: 1.4;
}
.item-status {
font-size: 14px;
@@ -472,6 +501,16 @@ onUnload(() =>{
margin-bottom: 10rpx;
}
/* 加载更多提示 */
.load-more-tip {
display: flex;
justify-content: center;
align-items: center;
padding: 30rpx 0;
color: #999;
font-size: 26rpx;
}
/* 底部时间和详情 */
.item-footer {
display: flex;

View File

@@ -169,8 +169,21 @@ const form = ref({
// ========== 基础数据 ==========
const timePopupRef = ref(null)
const selectedTime = ref('')
const tempTime = ref(moment().hour(9).minute(30).second(0))
// 默认预约时间:今天(向上取整到下一个整点/半点)
const getDefaultTime = () => {
const t = moment().second(0).millisecond(0)
if (t.minute() > 30) {
t.add(1, 'hour').minute(0)
} else if (t.minute() > 0) {
t.minute(30)
}
return t
}
const selectedTime = ref(getDefaultTime())
const tempTime = ref(getDefaultTime())
form.value.datetime = selectedTime.value.format('YYYY-MM-DD HH:mm')
// ========== 时间选择列数据 ==========
const dateList = ref([
@@ -191,12 +204,15 @@ const minuteList = ref([
])
// ========== 选中状态 ==========
const selectedDate = ref('')
const selectedHour = ref('')
const selectedMinute = ref('')
const selectedDate = ref(selectedTime.value.format('YYYY-MM-DD'))
const selectedHour = ref(selectedTime.value.format('HH'))
const selectedMinute = ref(selectedTime.value.format('mm'))
// ========== 滚动配置 ==========
const itemHeight = 80
// 每项高度 / 可视高度rpx 转 px避免直接用数字导致滚动错位
const itemHeight = uni.upx2px(80)
const visibleHeight = uni.upx2px(400)
const centerOffset = (visibleHeight - itemHeight) / 2
const dateScrollTop = ref(0)
const hourScrollTop = ref(0)
const minuteScrollTop = ref(0)
@@ -242,10 +258,11 @@ const syncScrollPosition = () => {
const dateIdx = dateList.value.findIndex(i => i.value === selectedDate.value)
const hourIdx = hourList.value.findIndex(i => i.time === selectedHour.value)
const minIdx = minuteList.value.findIndex(i => i.minute === selectedMinute.value)
dateScrollTop.value = dateIdx * itemHeight
hourScrollTop.value = hourIdx * itemHeight
minuteScrollTop.value = minIdx * itemHeight
// 让选中项滚动到可视区域居中位置,并限制不小于 0
dateScrollTop.value = dateIdx >= 0 ? Math.max(0, dateIdx * itemHeight - centerOffset) : 0
hourScrollTop.value = hourIdx >= 0 ? Math.max(0, hourIdx * itemHeight - centerOffset) : 0
minuteScrollTop.value = minIdx >= 0 ? Math.max(0, minIdx * itemHeight - centerOffset) : 0
}
// 点击选择日期

View File

@@ -54,7 +54,7 @@
</view>
<view class="photo-container" v-else>
<view class="photo-item">
<uni-icons type="plusempty" size="24" color="#ccc"></uni-icons>
<!-- <uni-icons type="plusempty" size="24" color="#ccc"></uni-icons> -->
</view>
</view>
</view>

View File

@@ -57,12 +57,11 @@ const fetchHouseList = async () => {
if (res.code === 200) {
const list = res.rows || []
houseList.value = list
if (houseList.value.length > 0) {
if (preSelectedHouseId.value) {
const found = houseList.value.find(item => String(item.id) === String(preSelectedHouseId.value))
selectedHouse.value = found || houseList.value[0]
} else {
selectedHouse.value = houseList.value[0]
// 仅当从表单页带入了房屋ID时自动选中对应房屋否则不默认选择
if (preSelectedHouseId.value) {
const found = houseList.value.find(item => String(item.id) === String(preSelectedHouseId.value))
if (found) {
selectedHouse.value = found
}
}
}
@@ -85,7 +84,7 @@ const selectHouse = (item) => {
// 确认选择并返回
const confirmSelect = () => {
if (!selectedHouse.value) {
if (!selectedHouse.value.id) {
uni.showToast({ title: '请选择房屋', icon: 'none' })
return
}
@@ -113,6 +112,8 @@ const confirmSelect = () => {
}
.house-list {
flex: 1;
min-height: 0;
overflow-y: auto;
}
.house-item {
display: flex;