HomeLease/pages/myOrder/myOrder.vue
2025-08-22 15:59:01 +08:00

77 lines
1.4 KiB
Vue

<template>
<view class="container">
<view v-for="item in list" :key="item.id" class="item">
<uni-card :extra="item.createTime" :title="item.typeName" @click="detail(item)"></uni-card>
</view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { getMyOrder } from '@/api/order/myOrder.js'
import { onUnload, onReachBottom } from '@dcloudio/uni-app'
const list = ref([])
const noData = ref(false)
//定义data参数
const queryParams = {
pageNum: 1,
pageSize: 12,
}
// 页面加载时获取数据
onMounted(() => {
getList()
})
onReachBottom(() => {
if (noData.value) return
queryParams.pageNum++
getList()
})
// 获取列表
const getList = async () => {
try {
let res = await getMyOrder(queryParams)
// 确保 res.data 存在且是数组
const newData = res?.rows || []
list.value = [...list.value, ...newData]
if (queryParams.pageSize > newData.length) noData.value = true
uni.setStorageSync('storyList', list.value)
console.log(list.value)
} catch (error) {
console.error('获取订单列表失败:', error)
uni.showToast({
title: '获取订单列表失败',
icon: 'none',
})
}
}
onUnload(() => {
uni.removeStorageSync('storyList')
})
</script>
<style lang="scss" scoped>
.container {
overflow: hidden;
padding: 20rpx;
}
.item {
margin-bottom: 20rpx;
}
.uni-body {
font-size: 28rpx;
line-height: 1.6;
color: #666;
}
</style>