From e80247f4cc77715c093b98cbf1d065759e213c5d Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Mon, 18 Nov 2024 13:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=85=91=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserExchangeSuccessModal/index.tsx | 4 +- src/components/getPhoneModal/index.tsx | 50 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/components/UserExchangeSuccessModal/index.tsx b/src/components/UserExchangeSuccessModal/index.tsx index 8e8613e..73e8d3a 100644 --- a/src/components/UserExchangeSuccessModal/index.tsx +++ b/src/components/UserExchangeSuccessModal/index.tsx @@ -53,9 +53,9 @@ export default function UserExchangeModal({ isOpen, setIsOpen, exchangeState, pr exchangeState === '207' ? '该兑换码/二维码已被兑换,请核对后再来兑换' : exchangeState === '205' ? - '兑换码/二维码有误,请核对后再来兑换' : + '该兑换码/二维码有误,请核对后再来兑换' : exchangeState === '206' ? - '兑换码已过有效期' : + '该兑换码/二维码已过期,请核对后再来兑换' : exchangeState === '217' ? '该兑换码/二维码你已兑换过,兑换的商品为:' : '兑换商品:' diff --git a/src/components/getPhoneModal/index.tsx b/src/components/getPhoneModal/index.tsx index e3eacfe..fa61d53 100644 --- a/src/components/getPhoneModal/index.tsx +++ b/src/components/getPhoneModal/index.tsx @@ -2,6 +2,7 @@ import { Button, View, Text } from '@tarojs/components' import { useState } from 'react' import Taro, { useLoad } from '@tarojs/taro' import './index.less' +import UserExchangeSuccessModal from '../../components/UserExchangeSuccessModal' export default function GetPhoneNumber({ onClose, scene = null, modalVisible, onModalClose}) { @@ -10,6 +11,18 @@ export default function GetPhoneNumber({ onClose, scene = null, modalVisible, on const [inviteCode, setInviteCode] = useState() + // 兑换成功弹窗 + const [isUserExchangeSuccessModalOpen, setisUserExchangeSuccessModalOpen] = useState(false) + + // 兑换接口返回的state + const [exchangeState, setExchangeState] = useState('') + + // 兑换成功的商品名称字符串 + const [prdtNames, setPrdtNames] = useState('') + + // 兑换成功的商品名称数组 + const [prdtList, setPrdtList] = useState([]) + useLoad((query)=> { console.log(query.inviteCode) setInviteCode(query.inviteCode || '') @@ -63,34 +76,15 @@ export default function GetPhoneNumber({ onClose, scene = null, modalVisible, on change_code: scene }, success: (s_res: any) => { - console.log('兑换成功=>', s_res.data) - if(s_res.data.state === '200'){ - let modalContent = '' - s_res.data.data.Subscribed.forEach(element => { - modalContent += `兑换成功: ${element.PrdtTitle}\n` - }) - - Taro.showModal({ - title: '兑换成功', - content: modalContent, - showCancel: true, - success: (modal_res) => { - if (modal_res.confirm) { - console.log('用户点击确定') - Taro.navigateTo({ - url: '/pages/CollectionDetail/index?id=' + s_res.data.data.Subscribed[0].PrdtId - }) - } else if (modal_res.cancel) { - console.log('用户点击取消') - } - } - }) - }else if(s_res.data.state === '207'){ - Taro.showToast({ - title: '兑换码已使用', - icon: 'error' - }) + const { state, data } = s_res.data + setExchangeState(state) + // 有返回商品名称,则显示;否则只显示提示语 + if(data && data.Subscribed){ + const list = data.Subscribed + setPrdtNames(list.map((n: any) => n.PrdtTitle).join(';')) + setPrdtList(list) } + setisUserExchangeSuccessModalOpen(true) }, fail: (err: any) => { console.log('兑换失败=>', err) @@ -192,6 +186,8 @@ export default function GetPhoneNumber({ onClose, scene = null, modalVisible, on + + )