import React, { useEffect, useState } from 'react' import { View, Text, Image, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' import { pageShopGroupBuy } from '@/api/shop/shopGroupBuy' import type { ShopGroupBuy } from '@/api/shop/shopGroupBuy/model' import EmptyState from '@/components/common/EmptyState' definePageConfig({ navigationBarTitleText: '拼团活动', }) const GroupBuyListPage: React.FC = () => { const [groupBuyList, setGroupBuyList] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { fetchGroupBuyList() }, []) const fetchGroupBuyList = async () => { try { setLoading(true) const res = await pageShopGroupBuy({ page: 1, pageSize: 20, status: 1 }) if (res.code === 0 && res.data) { setGroupBuyList(res.data.items || []) } } catch (err) { console.error('获取拼团列表失败', err) Taro.showToast({ title: '加载失败', icon: 'none' }) } finally { setLoading(false) } } const handleGroupBuyClick = (item: ShopGroupBuy) => { Taro.navigateTo({ url: `/pages/shop/group-buy-detail?groupBuyId=${item.id}` }) } const getStatusText = (item: ShopGroupBuy) => { const remaining = item.groupSize - item.currentSize if (remaining <= 0) return '已满员' return `还差${remaining}人成团` } const getStatusColor = (item: ShopGroupBuy) => { const remaining = item.groupSize - item.currentSize if (remaining <= 0) return '#999' return '#ff4d4f' } return ( {loading ? ( 加载中... ) : groupBuyList.length === 0 ? ( ) : ( {groupBuyList.map(item => ( handleGroupBuyClick(item)} > {item.goodsName || item.product?.name || '商品名称'} {item.groupSize}人团 {getStatusText(item)} {'\u00A5'}{item.groupPrice} {'\u00A5'}{item.product?.price || 0} 去拼团 ))} )} ) } export default GroupBuyListPage