refactor(shop): 更新 API调用和页面逻辑

- 修改了多个文件中的 API调用路径
- 优化了部分组件的显示逻辑
- 添加了优惠券相关功能
-调整了环境变量配置
This commit is contained in:
2025-08-14 01:06:44 +08:00
parent 89cadc3886
commit 2c864ce770
12 changed files with 138 additions and 89 deletions

View File

@@ -3,8 +3,8 @@ import Taro, {useDidShow} from '@tarojs/taro'
import {Button, Empty, ConfigProvider, SearchBar, InfiniteLoading, Loading, PullToRefresh, Tabs, TabPane} from '@nutui/nutui-react-taro'
import {Plus, Filter} from '@nutui/icons-react-taro'
import {View} from '@tarojs/components'
import {ShopCoupon} from "@/api/shop/shopCoupon/model";
import {pageShopCoupon} from "@/api/shop/shopCoupon";
import {ShopUserCoupon} from "@/api/shop/shopUserCoupon/model";
import {pageShopUserCoupon} from "@/api/shop/shopUserCoupon";
import CouponList from "@/components/CouponList";
import CouponStats from "@/components/CouponStats";
import CouponGuide from "@/components/CouponGuide";
@@ -14,7 +14,7 @@ import {CouponCardProps} from "@/components/CouponCard";
import dayjs from "dayjs";
const CouponManage = () => {
const [list, setList] = useState<ShopCoupon[]>([])
const [list, setList] = useState<ShopUserCoupon[]>([])
const [loading, setLoading] = useState(false)
const [hasMore, setHasMore] = useState(true)
const [searchValue, setSearchValue] = useState('')
@@ -63,7 +63,7 @@ const CouponManage = () => {
try {
const currentPage = isRefresh ? 1 : page
const statusFilter = getStatusFilter()
const res = await pageShopCoupon({
const res = await pageShopUserCoupon({
page: currentPage,
limit: 10,
keywords: searchValue,
@@ -127,7 +127,7 @@ const CouponManage = () => {
}
// 转换优惠券数据为CouponCard组件所需格式
const transformCouponData = (coupon: ShopCoupon): CouponCardProps => {
const transformCouponData = (coupon: ShopUserCoupon): CouponCardProps => {
// 判断优惠券状态
let status: 0 | 1 | 2 = 0 // 默认未使用
if (coupon.isExpire === 1) {
@@ -176,7 +176,7 @@ const CouponManage = () => {
}
// 使用优惠券
const handleUseCoupon = (coupon: ShopCoupon) => {
const handleUseCoupon = (coupon: ShopUserCoupon) => {
Taro.showModal({
title: '使用优惠券',
content: `确定要使用"${coupon.name}"吗?`,
@@ -201,7 +201,7 @@ const CouponManage = () => {
}
// 显示优惠券详情
const showCouponDetail = (coupon: ShopCoupon) => {
const showCouponDetail = (coupon: ShopUserCoupon) => {
// 跳转到优惠券详情页
Taro.navigateTo({
url: `/user/coupon/detail?id=${coupon.id}`
@@ -213,9 +213,9 @@ const CouponManage = () => {
try {
// 并行获取各状态的优惠券数量
const [availableRes, usedRes, expiredRes] = await Promise.all([
pageShopCoupon({ page: 1, limit: 1, status: 0, isExpire: 0 }),
pageShopCoupon({ page: 1, limit: 1, status: 1 }),
pageShopCoupon({ page: 1, limit: 1, isExpire: 1 })
pageShopUserCoupon({ page: 1, limit: 1, status: 0, isExpire: 0 }),
pageShopUserCoupon({ page: 1, limit: 1, status: 1 }),
pageShopUserCoupon({ page: 1, limit: 1, isExpire: 1 })
])
setStats({
@@ -248,7 +248,7 @@ const CouponManage = () => {
const checkExpiringSoonCoupons = async () => {
try {
// 获取即将过期的优惠券3天内过期
const res = await pageShopCoupon({
const res = await pageShopUserCoupon({
page: 1,
limit: 50,
status: 0, // 未使用
@@ -277,6 +277,7 @@ const CouponManage = () => {
.sort((a, b) => a.daysLeft - b.daysLeft)
if (expiringSoon.length > 0) {
// @ts-ignore
setExpiringSoonCoupons(expiringSoon)
// 延迟显示提醒,避免与页面加载冲突
setTimeout(() => {