forked from gxwebsoft/mp-10550
fix(api): 修复优惠券页面 API 调用错误并优化调试信息
- 更新 API 请求方式,使用正确的 request-legacy 导入 - 在优惠券页面添加详细的调试日志,帮助排查显示问题 - 修复 Tabs 组件的类型错误,确保类型安全- 优化页面渲染逻辑,增加可视化调试信息 - 更新文档,提供详细的调试步骤和常见问题分析
This commit is contained in:
@@ -77,6 +77,14 @@ const CouponManage = () => {
|
||||
|
||||
if (res && res.list) {
|
||||
const newList = isRefresh ? res.list : [...list, ...res.list]
|
||||
console.log('优惠券数据加载成功:', {
|
||||
isRefresh,
|
||||
currentPage,
|
||||
statusFilter,
|
||||
responseData: res,
|
||||
newListLength: newList.length,
|
||||
activeTab
|
||||
})
|
||||
setList(newList)
|
||||
setTotal(res.count || 0)
|
||||
|
||||
@@ -89,6 +97,7 @@ const CouponManage = () => {
|
||||
setPage(2) // 刷新后下一页是第2页
|
||||
}
|
||||
} else {
|
||||
console.log('优惠券数据为空:', res)
|
||||
setHasMore(false)
|
||||
setTotal(0)
|
||||
}
|
||||
@@ -115,8 +124,10 @@ const CouponManage = () => {
|
||||
}
|
||||
|
||||
// Tab切换
|
||||
const handleTabChange = (value: string) => {
|
||||
setActiveTab(value)
|
||||
const handleTabChange = (value: string | number) => {
|
||||
const tabValue = String(value)
|
||||
console.log('Tab切换:', { from: activeTab, to: tabValue })
|
||||
setActiveTab(tabValue)
|
||||
setPage(1)
|
||||
setList([])
|
||||
setHasMore(true)
|
||||
@@ -128,6 +139,8 @@ const CouponManage = () => {
|
||||
|
||||
// 转换优惠券数据为CouponCard组件所需格式
|
||||
const transformCouponData = (coupon: ShopUserCoupon): CouponCardProps => {
|
||||
console.log('转换优惠券数据:', coupon)
|
||||
|
||||
// 判断优惠券状态
|
||||
let status: 0 | 1 | 2 = 0 // 默认未使用
|
||||
if (coupon.isExpire === 1) {
|
||||
@@ -151,7 +164,7 @@ const CouponManage = () => {
|
||||
amount = 0
|
||||
}
|
||||
|
||||
return {
|
||||
const result = {
|
||||
amount,
|
||||
type,
|
||||
status,
|
||||
@@ -163,6 +176,9 @@ const CouponManage = () => {
|
||||
onUse: () => handleUseCoupon(coupon),
|
||||
theme: getThemeByType(coupon.type)
|
||||
}
|
||||
|
||||
console.log('转换后的数据:', result)
|
||||
return result
|
||||
}
|
||||
|
||||
// 根据优惠券类型获取主题色
|
||||
@@ -366,12 +382,9 @@ const CouponManage = () => {
|
||||
{/* Tab切换 */}
|
||||
<View className="bg-white">
|
||||
<Tabs value={activeTab} onChange={handleTabChange}>
|
||||
<TabPane title="可用" value="0">
|
||||
</TabPane>
|
||||
<TabPane title="已使用" value="1">
|
||||
</TabPane>
|
||||
<TabPane title="已过期" value="2">
|
||||
</TabPane>
|
||||
<TabPane title="可用" value="0" />
|
||||
<TabPane title="已使用" value="1" />
|
||||
<TabPane title="已过期" value="2" />
|
||||
</Tabs>
|
||||
</View>
|
||||
|
||||
@@ -381,6 +394,10 @@ const CouponManage = () => {
|
||||
headHeight={60}
|
||||
>
|
||||
<View style={{ height: 'calc(100vh - 200px)', overflowY: 'auto' }} id="coupon-scroll">
|
||||
{/* 调试信息 */}
|
||||
<View className="p-2 bg-yellow-100 text-xs text-gray-600">
|
||||
调试信息: list.length={list.length}, loading={loading.toString()}, activeTab={activeTab}
|
||||
</View>
|
||||
{list.length === 0 && !loading ? (
|
||||
<View className="flex flex-col justify-center items-center" style={{height: 'calc(100vh - 300px)'}}>
|
||||
<Empty
|
||||
@@ -414,6 +431,10 @@ const CouponManage = () => {
|
||||
onCouponClick={handleCouponClick}
|
||||
showEmpty={false}
|
||||
/>
|
||||
{/* 调试:显示转换后的数据 */}
|
||||
<View className="p-2 bg-blue-100 text-xs text-gray-600">
|
||||
转换后数据: {JSON.stringify(list.map(transformCouponData).slice(0, 2), null, 2)}
|
||||
</View>
|
||||
</InfiniteLoading>
|
||||
)}
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user