hookehuyr

预约记录页面数据分页处理

1 <!-- 1 <!--
2 * @Date: 2024-01-16 11:37:10 2 * @Date: 2024-01-16 11:37:10
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-01-19 21:55:03 4 + * @LastEditTime: 2024-01-22 17:45:57
5 * @FilePath: /xysBooking/src/views/bookingList.vue 5 * @FilePath: /xysBooking/src/views/bookingList.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 <div class="booking-list-page"> 9 <div class="booking-list-page">
10 + <van-list
11 + v-model:loading="loading"
12 + :finished="finished"
13 + :finished-text="finishedTextStatus ? '没有更多了' : ''"
14 + @load="onLoad"
15 + >
10 <div @click="() => { go('/bookingDetail', { pay_id: item.pay_id }) }" v-for="(item, index) in bookingList" :key="index" class="booking-list-item"> 16 <div @click="() => { go('/bookingDetail', { pay_id: item.pay_id }) }" v-for="(item, index) in bookingList" :key="index" class="booking-list-item">
11 <div class="booking-list-item-header"> 17 <div class="booking-list-item-header">
12 <div>{{ item.booking_time }}</div> 18 <div>{{ item.booking_time }}</div>
...@@ -21,6 +27,7 @@ ...@@ -21,6 +27,7 @@
21 <div class="booking-time">下单时间:<span>{{ item.order_time }}</span></div> 27 <div class="booking-time">下单时间:<span>{{ item.order_time }}</span></div>
22 </div> 28 </div>
23 </div> 29 </div>
30 + </van-list>
24 <div v-if="!bookingList.length" class="no-qrcode"> 31 <div v-if="!bookingList.length" class="no-qrcode">
25 <img src="https://cdn.ipadbiz.cn/xys/booking/%E6%9A%82%E6%97%A0@2x.png" style="width: 10rem;"> 32 <img src="https://cdn.ipadbiz.cn/xys/booking/%E6%9A%82%E6%97%A0@2x.png" style="width: 10rem;">
26 <div class="no-qrcode-title">您还没有预约过参观</div> 33 <div class="no-qrcode-title">您还没有预约过参观</div>
...@@ -43,8 +50,6 @@ useTitle($route.meta.title); ...@@ -43,8 +50,6 @@ useTitle($route.meta.title);
43 50
44 const go = useGo(); 51 const go = useGo();
45 52
46 -const bookingList = ref([]);
47 -
48 /** 53 /**
49 * 1=待支付(下单就立即支付,所以理论上不存在待支付的数据), 54 * 1=待支付(下单就立即支付,所以理论上不存在待支付的数据),
50 * 2=支付中(支付前先把状态打成2;支付回调后应立即变更状态,支付中的状态不会持续很久), 55 * 2=支付中(支付前先把状态打成2;支付回调后应立即变更状态,支付中的状态不会持续很久),
...@@ -95,8 +100,15 @@ const formatStatus = (status) => { ...@@ -95,8 +100,15 @@ const formatStatus = (status) => {
95 } 100 }
96 } 101 }
97 102
103 +const page = ref(1);
104 +const limit = ref(5);
105 +const bookingList = ref([]);
106 +const loading = ref(false);
107 +const finished = ref(false);
108 +const finishedTextStatus = ref(false);
109 +
98 onMounted(async () => { 110 onMounted(async () => {
99 - const { code, data } = await billListAPI(); 111 + const { code, data } = await billListAPI({ page: page.value, row_num: limit.value });
100 if (code) { 112 if (code) {
101 // 113 //
102 data.forEach(item => { 114 data.forEach(item => {
...@@ -108,7 +120,31 @@ onMounted(async () => { ...@@ -108,7 +120,31 @@ onMounted(async () => {
108 }); 120 });
109 bookingList.value = data; 121 bookingList.value = data;
110 } 122 }
111 -}) 123 +});
124 +
125 +const onLoad = async () => {
126 + page.value++;
127 + const { code, data } = await billListAPI({ page: page.value, row_num: limit.value });
128 + if (code) {
129 + data.forEach(item => {
130 + let begin_time = item.begin_time?.slice(0, -3);
131 + let end_time = item.end_time?.slice(0, -3);
132 + let str = begin_time + ' ' + end_time;
133 + item.booking_time = `${str.split(' ')[0]} ${str.split(' ')[1]}-${str.split(' ')[3]}`;
134 + item.order_time = item.created_time.slice(0, -3);
135 + });
136 + bookingList.value = bookingList.value.concat(data);
137 + loading.value = false;
138 + // 数据全部加载完成
139 + if (!data.length) {
140 + // 加载状态结束
141 + finished.value = true;
142 + if (!bookingList.value.length) {
143 + finishedTextStatus.value = false;
144 + }
145 + }
146 + }
147 +}
112 </script> 148 </script>
113 149
114 <style lang="less" scoped> 150 <style lang="less" scoped>
......