feat(礼品卡): 优化颜色主题并添加核销功能
- 修改礼品卡颜色主题,使用渐变色提升视觉效果 - 添加礼品卡核销功能,包括生成和验证核销码 -优化礼品卡组件,增加状态显示和使用说明 - 新增礼品卡颜色测试页面,用于验证颜色
This commit is contained in:
@@ -5,7 +5,7 @@ import {ArrowLeft, QrCode, Gift, Voucher} from '@nutui/icons-react-taro'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import {ShopGift} from "@/api/shop/shopGift/model";
|
||||
import {validateGiftCode, redeemGift} from "@/api/shop/shopGift";
|
||||
import {validateGiftCode, redeemGift, pageShopGift, updateShopGift} from "@/api/shop/shopGift";
|
||||
import GiftCard from "@/components/GiftCard";
|
||||
|
||||
const GiftCardRedeem = () => {
|
||||
@@ -38,14 +38,22 @@ const GiftCardRedeem = () => {
|
||||
|
||||
setValidating(true)
|
||||
try {
|
||||
const gift = await validateGiftCode(codeToValidate.trim())
|
||||
if(gift){
|
||||
setValidGift(gift)
|
||||
const gifts = await pageShopGift({code: codeToValidate,status: 0})
|
||||
if(gifts?.count == 0){
|
||||
Taro.showToast({
|
||||
title: '兑换码无效或已使用',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
const item = gifts?.list[0];
|
||||
if(item){
|
||||
setValidGift(item)
|
||||
Taro.showToast({
|
||||
title: '验证成功',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
Taro.showToast({
|
||||
title: '验证成功',
|
||||
icon: 'success'
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('验证兑换码失败:', error)
|
||||
setValidGift(null)
|
||||
@@ -64,8 +72,9 @@ const GiftCardRedeem = () => {
|
||||
|
||||
setLoading(true)
|
||||
try {
|
||||
await redeemGift({
|
||||
code: code.trim()
|
||||
await updateShopGift({
|
||||
...validGift,
|
||||
userId: Taro.getStorageSync('UserId')
|
||||
})
|
||||
|
||||
setRedeemSuccess(true)
|
||||
@@ -125,7 +134,6 @@ const GiftCardRedeem = () => {
|
||||
goodsImage: gift.goodsImage,
|
||||
faceValue: gift.faceValue,
|
||||
type: gift.type,
|
||||
useStatus: gift.useStatus,
|
||||
expireTime: gift.expireTime,
|
||||
useTime: gift.useTime,
|
||||
useLocation: gift.useLocation,
|
||||
|
||||
Reference in New Issue
Block a user