From ac3ace5a569da2d68af40ad46bc7a03233d920f7 Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Mon, 14 Oct 2024 15:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=91=E6=8D=A2=E6=88=90=E5=8A=9F=E5=BC=B9?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UserExchangeModal/index.tsx | 80 ++++++------------- .../UserExchangeSuccessModal/index.less | 72 +++++++++++++++++ .../UserExchangeSuccessModal/index.tsx | 64 +++++++++++++++ src/pages/Home/index.tsx | 42 ++++------ src/pages/UserHome/index.tsx | 2 +- 5 files changed, 176 insertions(+), 84 deletions(-) create mode 100644 src/components/UserExchangeSuccessModal/index.less create mode 100644 src/components/UserExchangeSuccessModal/index.tsx diff --git a/src/components/UserExchangeModal/index.tsx b/src/components/UserExchangeModal/index.tsx index faadf1f..66990d5 100644 --- a/src/components/UserExchangeModal/index.tsx +++ b/src/components/UserExchangeModal/index.tsx @@ -3,6 +3,7 @@ import Taro from '@tarojs/taro' import { Input, View, Text } from '@tarojs/components' import './index.less' import GetPhoneNumber from '../getPhoneModal' +import UserExchangeSuccessModal from '../UserExchangeSuccessModal' interface Props{ isOpen: boolean, @@ -16,11 +17,20 @@ export default function UserExchangeModal({ isOpen, setIsOpen }: Props) { const [userScene, setuserScene] = useState(null) //管理登录弹窗 - const [isGetUsePhone, setisGetUsePhone] = useState(false) //false + const [isGetUsePhone, setisGetUsePhone] = useState(false) //管理登录弹窗 const [isLoginOpen, setisLoginOpen] = useState(false) + // 兑换成功弹窗 + const [isUserExchangeSuccessModalOpen, setisUserExchangeSuccessModalOpen] = useState(false) + + // 兑换成功的商品名称字符串 + const [prdtNames, setPrdtNames] = useState('') + + // 兑换成功的商品名称数组 + const [prdtList, setPrdtList] = useState([]) + //唤起扫码 const handleScanCode = () => { console.log('唤起扫码') @@ -43,34 +53,12 @@ export default function UserExchangeModal({ isOpen, setIsOpen }: Props) { }, 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};` - }) - - Taro.showModal({ - title: '兑换成功', - content: modalContent, - showCancel: true, - success: (modal_res) => { - setIsOpen(false) - if (modal_res.confirm) { - console.log('用户点击确定') - if(s_res.data.data.Subscribed[0].PrdtType === '03'){ - Taro.navigateTo({ - url: '/pages/ListenDetail/index?prdtId=' + s_res.data.data.Subscribed[0].PrdtId - }) - }else if(s_res.data.data.Subscribed[0].PrdtType === '05'){ - Taro.navigateTo({ - url: '/pages/CollectionDetail/index?id=' + s_res.data.data.Subscribed[0].PrdtId - }) - } - } else if (modal_res.cancel) { - console.log('用户点击取消') - } - } - }) + if (s_res.data.state === '200') { + const list = s_res.data.data.Subscribed + setPrdtNames(list.map((e: any) => e.PrdtTitle).join(';')) + setPrdtList(list) + setIsOpen(false) + setisUserExchangeSuccessModalOpen(true) }else if(s_res.data.state === '207'){ Taro.showToast({ title: '兑换码已使用', @@ -103,34 +91,10 @@ export default function UserExchangeModal({ isOpen, setIsOpen }: Props) { success: (res: any) => { console.log('兑换成功=>', res.data) if(res.data.state === '200'){ - let modalContent = '兑换成功:' - res.data.data.Subscribed.forEach(element => { - modalContent += `${element.PrdtTitle};` - }) - console.log(modalContent) - - Taro.showModal({ - title: '兑换成功', - content: modalContent, - showCancel: true, - success: (modal_res) => { - setIsOpen(false) - if (modal_res.confirm) { - console.log('用户点击确定') - if(res.data.data.Subscribed[0].PrdtType === '03'){ - Taro.navigateTo({ - url: '/pages/ListenDetail/index?prdtId=' + res.data.data.Subscribed[0].PrdtId - }) - }else if(res.data.data.Subscribed[0].PrdtType === '05'){ - Taro.navigateTo({ - url: '/pages/CollectionDetail/index?id=' + res.data.data.Subscribed[0].PrdtId - }) - } - } else if (modal_res.cancel) { - console.log('用户点击取消') - } - } - }) + const list = res.data.data.Subscribed + setPrdtNames(list.map((e: any) => e.PrdtTitle).join(';')) + setPrdtList(list) + setIsOpen(false) }else if(res.data.state === '207'){ Taro.showToast({ title: '兑换码已使用', @@ -187,6 +151,8 @@ export default function UserExchangeModal({ isOpen, setIsOpen }: Props) { + + void, + prdtNames: string, + prdtList: any[] +} + +export default function UserExchangeModal({ isOpen, setIsOpen, prdtNames, prdtList }: Props) { + const handleExchange = () => { + if(prdtList[0].PrdtType === '03'){ + Taro.navigateTo({ + url: '/pages/ListenDetail/index?prdtId=' + prdtList[0].PrdtId + }) + }else if(prdtList[0].PrdtType === '05'){ + Taro.navigateTo({ + url: '/pages/CollectionDetail/index?id=' + prdtList[0].PrdtId + }) + } + } + + if(!isOpen){ + return null + } + + return ( + <> + setIsOpen(false)} + > + + + + setIsOpen(false)} + > + + + { + prdtList.length ? + + 兑换成功: + {prdtNames} + : + null + } + + + 立即阅读 + + + + ) +} diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 6a5aa76..13cc029 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react' import './index.less' import GetPhoneNumber from '../../components/getPhoneModal' import GoToStoreModal from '../../components/goToStoreModal' +import UserExchangeSuccessModal from '../../components/UserExchangeSuccessModal' interface FreeItemProps { Child: any[], @@ -60,32 +61,10 @@ export default function Home() { 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};` - }) - - Taro.showModal({ - title: '兑换成功', - content: modalContent, - showCancel: true, - success: (modal_res) => { - if (modal_res.confirm) { - console.log('用户点击确定') - if(s_res.data.data.Subscribed[0].PrdtType === '03'){ - Taro.navigateTo({ - url: '/pages/ListenDetail/index?prdtId=' + s_res.data.data.Subscribed[0].PrdtId - }) - }else if(s_res.data.data.Subscribed[0].PrdtType === '05'){ - Taro.navigateTo({ - url: '/pages/CollectionDetail/index?id=' + s_res.data.data.Subscribed[0].PrdtId - }) - } - } else if (modal_res.cancel) { - console.log('用户点击取消') - } - } - }) + const list = s_res.data.data.Subscribed + setPrdtNames(list.map((e: any) => e.PrdtTitle).join(';')) + setPrdtList(list) + setisUserExchangeSuccessModalOpen(true) }else if(s_res.data.state === '207'){ Taro.showToast({ title: '兑换码已使用', @@ -123,6 +102,15 @@ export default function Home() { //管理跳转页面路径 const [prdtMallLink, setprdtMallLink] = useState('') + // 兑换成功弹窗 + const [isUserExchangeSuccessModalOpen, setisUserExchangeSuccessModalOpen] = useState(false) + + // 兑换成功的商品名称字符串 + const [prdtNames, setPrdtNames] = useState('') + + // 兑换成功的商品名称数组 + const [prdtList, setPrdtList] = useState([]) + //点击免费试读跳转 const handleNavigateToFreeRead = (id: number) => { console.log('点击免费试读跳转', id) @@ -410,6 +398,8 @@ export default function Home() { + +