diff --git a/pages/order/MyOrder/index.vue b/pages/order/MyOrder/index.vue index 8345232..9993449 100644 --- a/pages/order/MyOrder/index.vue +++ b/pages/order/MyOrder/index.vue @@ -54,7 +54,7 @@ { - this.page = 1 - this.orderList = []; - this.getOrderListReq() + this.changeType() }) }, goStore(order) { @@ -1260,6 +1259,23 @@ export default { reload() { this.changeType(this.type) }, + normalizeOrderList(list = []) { + const orderKeySet = new Set() + return list.reduce((result, item) => { + const orderKey = item && (item.orderId || item.id) + if (orderKey && orderKeySet.has(orderKey)) { + return result + } + if (orderKey) { + orderKeySet.add(orderKey) + } + result.push({ + ...item, + showMore: false + }) + return result + }, []) + }, tabChange(item) { this.type = item.index this.$yroute.query.type = this.type @@ -1300,6 +1316,7 @@ export default { }) }, changeType() { + this.orderListRequestId += 1 this.orderList = [] this.page = 1 this.loaded = false @@ -1308,7 +1325,8 @@ export default { }, getOrderListReq() { if (this.loading || this.loaded) return - // this.loading = true + this.loading = true + const currentRequestId = this.orderListRequestId uni.showLoading({ mask: true, }) @@ -1335,17 +1353,18 @@ export default { keyword, orderType }).then(res => { - this.orderList = this.orderList.concat(res.data) - if (this.orderList.length > 0) { - this.orderList.forEach(item => { - item.showMore = false; - }) + if (currentRequestId !== this.orderListRequestId) { + return } + const nextOrderList = page === 1 ? res.data : this.orderList.concat(res.data) + this.orderList = this.normalizeOrderList(nextOrderList) this.updateOrderDistances() - this.page++; + this.page = page + 1 this.loaded = res.data.length < this.limit - this.loading = false }).finally(() => { + if (currentRequestId !== this.orderListRequestId) { + return + } this.loading = false uni.hideLoading() });