| File was renamed from src/robotaxi/pages/coupon/components/coupon-select-popup/index.tsx |
| | |
| | | import { View, Text, Image, ScrollView, RichText } from '@tarojs/components'; |
| | | import { useEffect, useState } from 'react'; |
| | | import './index.less'; |
| | | import closeIcon from '../../../../assets/close-icon.png'; |
| | | import icon from "../../../../assets/coupon-arrow.png"; |
| | | import couponSelectIcon from '../../../../assets/coupon-select.png'; |
| | | import couponSelectedIcon from '../../../../assets/coupon-selected.png'; |
| | | import couponArrowRight from '../../../../assets/coupon-arrow-right.png'; |
| | | import { getCouponList, getCouponDetail, CouponDetail } from '../../../../api/coupon'; |
| | | import closeIcon from "../../assets/close-icon.png"; |
| | | import icon from "../../assets/coupon-arrow.png"; |
| | | import couponSelectIcon from "../../assets/coupon-select.png"; |
| | | import couponSelectedIcon from "../../assets/coupon-selected.png"; |
| | | import couponArrowRight from "../../assets/coupon-arrow-right.png"; |
| | | import { getCouponList, getCouponDetail, CouponDetail } from '../../api/coupon'; |
| | | |
| | | type Props = { |
| | | show: boolean; |
| | |
| | | const [canScroll, setCanScroll] = useState(false); |
| | | const [thumbHeight, setThumbHeight] = useState(0); |
| | | const [thumbTop, setThumbTop] = useState(0); |
| | | const [containerHeight, setContainerHeight] = useState(0); |
| | | const [showScrollbar, setShowScrollbar] = useState(false); |
| | | const [current, setCurrent] = useState(1); |
| | | const [hasNextPage, setHasNextPage] = useState(false); |
| | | const [loading, setLoading] = useState(false); |
| | | const [couponCount, setCouponCount] = useState(0); |
| | | const [activeCouponId, setActiveCouponId] = useState(''); |
| | | const [detailVisible, setDetailVisible] = useState(false); |
| | |
| | | const res = await getCouponList({ pageNum: page, pageSize: 10, status: 1 }); |
| | | const newList = res.list || []; |
| | | setList(newList); |
| | | setCouponCount(res.total || 0); |
| | | // 如果返回数量少于 pageSize,说明没有更多 |
| | | } catch (e) { |
| | | console.error(e); |
| | | } |
| | | }; |
| | | |
| | | const handleScrollToLower = () => { |
| | | if (hasNextPage && !loading) { |
| | | getList(current + 1); |
| | | } |
| | | }; |
| | | |
| | | const onScroll = (e) => { |
| | | const { scrollHeight, scrollTop } = e.detail; |
| | | if (containerHeight > 0 && scrollHeight > containerHeight) { |
| | | const newThumbTop = (scrollTop / scrollHeight) * containerHeight; |
| | | setThumbTop(newThumbTop); |
| | | } |
| | | }; |
| | | |
| | | const gotoMyCoupon = () => { |
| | | Taro.navigateTo({ url: '/robotaxi/pages/coupon/index' }); |
| | | }; |
| | | |
| | | const getCouponKey = (item: any) => { |
| | | return item?.operationCouponId || item?.couponId || ''; |
| | | }; |
| | | |
| | | const handleSelectCoupon = (item: any) => { |
| | | const couponKey = getCouponKey(item); |
| | | const couponKey = item?.operationCouponId |
| | | setActiveCouponId(couponKey); |
| | | onSelect(item); |
| | | }; |
| | |
| | | const wrapperHeight = res[0].height; |
| | | const contentHeight = res[1].height; |
| | | const isOverflow = contentHeight > wrapperHeight; |
| | | setContainerHeight(wrapperHeight); |
| | | setCanScroll(isOverflow); |
| | | if (isOverflow) { |
| | | setShowScrollbar(true); |
| | |
| | | <ScrollView |
| | | scrollY={canScroll} |
| | | className='coupon-list' |
| | | enhanced |
| | | lowerThreshold={30} |
| | | upperThreshold={30} |
| | | showScrollbar={false} |
| | | onScroll={onScroll} |
| | | onScrollToLower={handleScrollToLower} |
| | | > |
| | | <View className='coupon-list-inner'> |
| | | {list.map((item, index) => ( |
| | |
| | | <Image className='more-img' src={icon}></Image> |
| | | </View> |
| | | </View> |
| | | <View className='select-box'> |
| | | {item.status === 1 && <View className='select-box'> |
| | | <Image |
| | | className='select-img' |
| | | src={activeCouponId === getCouponKey(item) ? couponSelectedIcon : couponSelectIcon} |
| | | src={activeCouponId === item.operationCouponId ? couponSelectedIcon : couponSelectIcon} |
| | | ></Image> |
| | | </View> |
| | | </View>} |
| | | {/* 状态 1-未使用 2-已使用 3-已过期 0待领取 */} |
| | | {item.status === 2 && ( |
| | | <Image |
| | | className='status-img' |
| | | src={require("../../assets/coupon-used.png")} |
| | | /> |
| | | ) } |
| | | { item.status === 3 && ( |
| | | <Image |
| | | className='status-img' |
| | | src={require("../../assets/coupon-lost-efficacy.png")} |
| | | /> |
| | | )} |
| | | </View> |
| | | </View> |
| | | </View> |