- 新增地址类型定义,增强前端地址数据结构 - 新增地址编辑页面,支持地址智能识别和定位选点功能 - 地址编辑支持省市区选择及默认地址设置 - 新增地址列表页面,支持地址展示、删除、编辑和选择功能 - 实现售后申请页面,支持选择售后类型和退款原因 - 售后申请支持商品选择、退款金额计算和凭证上传 - 新增售后详情页面,支持售后状态展示及申请取消 - 优化页面加载和用户交互体验,增加错误提示和权限处理
114 lines
3.5 KiB
TypeScript
114 lines
3.5 KiB
TypeScript
import React, { useState, useEffect } from 'react'
|
|
import { View, Text, ScrollView, Image } from '@tarojs/components'
|
|
import Taro from '@tarojs/taro'
|
|
import { listShopGoodsCategory } from '@/api/shop/shopGoodsCategory'
|
|
import { pageShopGoods } from '@/api/shop/shopGoods'
|
|
import type { ShopGoodsCategory, ShopGoods } from '@/api/shop/shopGoodsCategory/model'
|
|
import type { ShopGoodsParam } from '@/api/shop/shopGoods/model'
|
|
import ProductCard from '@/components/common/ProductCard'
|
|
import EmptyState from '@/components/common/EmptyState'
|
|
import LoadMore from '@/components/common/LoadMore'
|
|
|
|
const categories = [
|
|
{ id: 0, title: '全部' },
|
|
{ id: -1, title: '推荐' },
|
|
]
|
|
|
|
const ShopPage: React.FC = () => {
|
|
const [categoryList, setCategoryList] = useState<ShopGoodsCategory[]>(categories)
|
|
const [activeCategory, setActiveCategory] = useState(0)
|
|
const [goodsList, setGoodsList] = useState<ShopGoods[]>([])
|
|
const [loading, setLoading] = useState(false)
|
|
const [page, setPage] = useState(1)
|
|
const [finished, setFinished] = useState(false)
|
|
|
|
useEffect(() => {
|
|
loadCategories()
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
setPage(1)
|
|
setFinished(false)
|
|
setGoodsList([])
|
|
loadGoods(1, activeCategory)
|
|
}, [activeCategory])
|
|
|
|
const loadCategories = async () => {
|
|
try {
|
|
const list = await listShopGoodsCategory()
|
|
if (list && list.length > 0) {
|
|
setCategoryList([...categories, ...list])
|
|
}
|
|
} catch { /* ignore */ }
|
|
}
|
|
|
|
const loadGoods = async (p: number, categoryId?: number) => {
|
|
if (loading) return
|
|
setLoading(true)
|
|
try {
|
|
const params: ShopGoodsParam = { page: p, limit: 10, status: 0 }
|
|
if (categoryId && categoryId > 0) params.categoryId = categoryId
|
|
if (categoryId === -1) params.recommend = 1
|
|
const res = await pageShopGoods(params)
|
|
const newList = res?.list || []
|
|
if (p === 1) {
|
|
setGoodsList(newList)
|
|
} else {
|
|
setGoodsList(prev => [...prev, ...newList])
|
|
}
|
|
setFinished(newList.length < 10)
|
|
setPage(p)
|
|
} catch { /* ignore */ }
|
|
setLoading(false)
|
|
}
|
|
|
|
const handleLoadMore = () => {
|
|
if (!finished && !loading) {
|
|
loadGoods(page + 1, activeCategory)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<View className='flex min-h-screen bg-gray-50'>
|
|
{/* 左侧分类栏 */}
|
|
<ScrollView scrollY className='w-20 bg-gray-100 h-screen'>
|
|
{categoryList.map(cat => (
|
|
<View
|
|
key={cat.categoryId || cat.id}
|
|
className={`py-3 px-2 text-center text-xs ${
|
|
(cat.categoryId || cat.id) === activeCategory
|
|
? 'bg-white text-green-600 font-medium border-l-2 border-green-500'
|
|
: 'text-gray-600'
|
|
}`}
|
|
onClick={() => setActiveCategory(cat.categoryId || cat.id)}
|
|
>
|
|
<Text>{cat.title}</Text>
|
|
</View>
|
|
))}
|
|
</ScrollView>
|
|
|
|
{/* 右侧商品列表 */}
|
|
<ScrollView
|
|
scrollY
|
|
className='flex-1 h-screen'
|
|
onScrollToLower={handleLoadMore}
|
|
lowerThreshold={100}
|
|
>
|
|
<View className='p-2'>
|
|
<View className='grid grid-cols-2 gap-2'>
|
|
{goodsList.map(item => (
|
|
<ProductCard key={item.goodsId} product={item} />
|
|
))}
|
|
</View>
|
|
{goodsList.length === 0 && !loading && (
|
|
<EmptyState text='暂无商品' />
|
|
)}
|
|
<LoadMore loading={loading} finished={finished} />
|
|
</View>
|
|
</ScrollView>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
export default ShopPage
|