feat(coupon): 优化优惠券列表的加载更多功能
新增ScrollView包裹优惠券列表,支持滚动列表底部触发加载,同时提取加载逻辑为独立函数复用代码
| | |
| | | import Taro, { useReachBottom } from "@tarojs/taro"; |
| | | import { useState, useEffect } from "react"; |
| | | import { View, Text, Image, RichText } from "@tarojs/components"; |
| | | import { View, Text, Image, RichText, ScrollView } from "@tarojs/components"; |
| | | import "./index.less"; |
| | | import { |
| | | getCouponList, |
| | |
| | | getList(1, activeStatus, true); |
| | | }, [activeStatus]); |
| | | |
| | | useReachBottom(() => { |
| | | const loadMore = () => { |
| | | if (hasMore) { |
| | | const nextPage = pageNum + 1; |
| | | setPageNum(nextPage); |
| | | getList(nextPage, activeStatus); |
| | | } |
| | | }; |
| | | |
| | | useReachBottom(() => { |
| | | loadMore(); |
| | | }); |
| | | |
| | | const changeStatus = (value: string | number) => { |
| | |
| | | })} |
| | | </View> |
| | | {couponList.length > 0 && ( |
| | | <View className="coupon-card"> |
| | | <ScrollView |
| | | className="coupon-card" |
| | | scrollY |
| | | onScrollToLower={loadMore} |
| | | > |
| | | {couponList.map((item, index) => { |
| | | return ( |
| | | <View |
| | |
| | | </View> |
| | | ); |
| | | })} |
| | | </View> |
| | | </ScrollView> |
| | | )} |
| | | {!couponList.length && ( |
| | | <View className="no-data-box"> |