<view class="order-list" v-if="orderList.length > 0">
<order-item
@tap="toDetail(item)"
v-for="item in orderList"
:item="item"
:key="item.id"></order-item>
</view>
<view class="empty-container" v-else-if="!initLoading">
<image class="empty-image" src="../../../static/images/empty-order.png"></image>
<view class="empty-text">暂无待付款订单~</view>
</view>
data() { return { pageIndex: 1, pageSize: 10, initLoading: true, // 初始加载数据 loading: false, // 加载更多 loadingFail: false, // 加载失败 orderList: [], pages: {} } },
onLoad() { this.pageIndex = 1 this.loadData() }),
mounted() { uni.showLoading() this.loadData() }, onReachBottom() { const { pageCount } = this.pages // 加载更多 if(this.pageIndex < pageCount) { this.loading = true this.pageIndex = this.pageIndex + 1 this.loadData() } },
methods: { // 加载订单数据 loadData() { if(this.initLoading) { uni.showLoading() } const {pageIndex, pageSize, userId, active} = this listOrderByPage({ pageIndex, pageSize, filter_fieldone: userId, filter_fieldtwo: active}).then(res => { this.initLoading = false const {data, ...pages} = res.response uni.hideLoading() this.handlePageData(data) this.pages = pages // 记录本次请求的分页参数 this.loading = false this.loadingFail = false }).catch(err => { uni.hideLoading() this.loading = false this.loadingFail = true }) },
// 处理分页数据 handlePageData(data) { const { page = 0, pageSize = 10} = this.pages // 比较上一次获取的页码和当前获取数据的页码判断当前需要更新哪部分数据 if(page >= this.pageIndex) { this.orderList = this.orderList.slice(0, (this.pageIndex - 1)*pageSize).concat(data) } else { this.orderList = this.orderList.concat(data) } },
// 加载失败后重新加载 reload() { this.loading = true this.loadingFail = false this.loadData() }
, // 判断当前订单在第几页 checkPage(id) { let currentIndex = this.orderList.findIndex(v => v.id == id) this.pageIndex = Math.ceil((currentIndex + 1) / this.pageSize) },// 去订单详情页 toDetail(item) { const {id, refunds_status} = item this.checkPage(id) if(refunds_status == 1) { // 退款订单查看退款成功详情 uni.navigateTo({ url: '/pages/message/order/refund?id=' + id }) } else { uni.navigateTo({ url: '/pages/message/order/detail?id=' + id }) } },},