| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-03-01 19:27:35 |
| 4 | * @LastEditTime: 2025-03-03 18:06:49 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: 任务提现 |
| 7 | */ |
| 8 | import { Button, Modal, Card, Typography, Space, message, Tag } from 'antd'; |
| 9 | import { |
| 10 | Task, |
| 11 | TaskProduct, |
| 12 | TaskPromotion, |
| 13 | TaskTypeName, |
| 14 | TaskVideo, |
| 15 | } from '@@/types/task'; |
| 16 | import { forwardRef, useImperativeHandle, useState } from 'react'; |
| 17 | import { taskApi } from '@/api/task'; |
| 18 | import { UserTask } from '@/api/types/task'; |
| 19 | |
| 20 | export interface WithdrawRef { |
| 21 | init: ( |
| 22 | taskInfo: UserTask<Task<TaskProduct | TaskPromotion | TaskVideo>>, |
| 23 | ) => Promise<void>; |
| 24 | } |
| 25 | |
| 26 | const Com = forwardRef<WithdrawRef>((props: any, ref) => { |
| 27 | const [isModalOpen, setIsModalOpen] = useState(false); |
| 28 | const [taskInfo, setTaskInfo] = useState<UserTask< |
| 29 | Task<TaskProduct | TaskPromotion | TaskVideo> |
| 30 | > | null>(); |
| 31 | const [loading, setLoading] = useState(false); |
| 32 | |
| 33 | const { Title, Text, Paragraph } = Typography; |
| 34 | |
| 35 | async function init( |
| 36 | inTaskInfo: UserTask<Task<TaskProduct | TaskPromotion | TaskVideo>>, |
| 37 | ) { |
| 38 | setTaskInfo(inTaskInfo); |
| 39 | setIsModalOpen(true); |
| 40 | } |
| 41 | |
| 42 | useImperativeHandle(ref, () => ({ |
| 43 | init: init, |
| 44 | })); |
| 45 | |
| 46 | /** |
| 47 | * 提交提现申请 |
| 48 | */ |
| 49 | async function submitWithdraw() { |
| 50 | if (!taskInfo) return; |
| 51 | |
| 52 | setLoading(true); |
| 53 | try { |
| 54 | const res = await taskApi.withdraw(taskInfo.id); |
| 55 | message.success('提现申请已提交'); |
| 56 | setIsModalOpen(false); |
| 57 | } catch (error) { |
| 58 | message.error('提交失败,请稍后重试'); |
| 59 | } finally { |
| 60 | setLoading(false); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const handleCancel = () => { |
| 65 | setIsModalOpen(false); |
| 66 | }; |
| 67 | |
| 68 | // 获取任务支持的账户类型标签 |
| 69 | const renderAccountTypeTags = () => { |
| 70 | const accountTypes = taskInfo?.taskId.accountTypes || []; |
| 71 | if (accountTypes.length === 0) return null; |
| 72 | |
| 73 | return ( |
| 74 | <Space size={[0, 8]} wrap> |
| 75 | <Text style={{ marginRight: 8 }}>支持账户类型:</Text> |
| 76 | {accountTypes.map((type) => ( |
| 77 | <Tag color="blue" key={type}> |
| 78 | {type.toUpperCase()} |
| 79 | </Tag> |
| 80 | ))} |
| 81 | </Space> |
| 82 | ); |
| 83 | }; |
| 84 | |
| 85 | return ( |
| 86 | <> |
| 87 | <Modal |
| 88 | title={<Title level={4}>任务提现申请</Title>} |
| 89 | open={isModalOpen} |
| 90 | onCancel={handleCancel} |
| 91 | width={500} |
| 92 | footer={[ |
| 93 | <Button key="back" onClick={handleCancel}> |
| 94 | 取消 |
| 95 | </Button>, |
| 96 | <Button |
| 97 | key="submit" |
| 98 | type="primary" |
| 99 | onClick={submitWithdraw} |
| 100 | loading={loading} |
| 101 | > |
| 102 | 提交申请 |
| 103 | </Button>, |
| 104 | ]} |
| 105 | > |
| 106 | <Space direction="vertical" size="large" style={{ width: '100%' }}> |
| 107 | {/* 提现金额信息卡片 */} |
| 108 | <Card |
| 109 | style={{ |
| 110 | backgroundColor: '#f5f5f5', |
| 111 | borderRadius: '8px', |
| 112 | }} |
| 113 | > |
| 114 | <Space direction="vertical" size="small"> |
| 115 | <Text>任务标题:{taskInfo?.taskId.title || '暂无'}</Text> |
| 116 | <Space> |
| 117 | <Text>提现金额:</Text> |
| 118 | <Text |
| 119 | style={{ |
| 120 | fontSize: '24px', |
| 121 | fontWeight: 'bold', |
| 122 | color: '#1890ff', |
| 123 | }} |
| 124 | > |
| 125 | ¥{taskInfo?.taskId.reward || 0} |
| 126 | </Text> |
| 127 | </Space> |
| 128 | <Text type="secondary"> |
| 129 | 任务类型: |
| 130 | {taskInfo?.taskId.type |
| 131 | ? TaskTypeName.get(taskInfo.taskId.type) |
| 132 | : '暂无'} |
| 133 | </Text> |
| 134 | {taskInfo?.verificationNote && ( |
| 135 | <Paragraph type="secondary" style={{ marginTop: 8 }}> |
| 136 | 审核备注:{taskInfo.verificationNote} |
| 137 | </Paragraph> |
| 138 | )} |
| 139 | </Space> |
| 140 | </Card> |
| 141 | |
| 142 | {/* 提现说明 */} |
| 143 | <Card> |
| 144 | <Space direction="vertical"> |
| 145 | <Text strong>提现说明</Text> |
| 146 | <Text type="secondary"> |
| 147 | 1. 提交申请后,系统将审核您的资金情况 |
| 148 | </Text> |
| 149 | <Text type="secondary"> |
| 150 | 2. 审核通过后,奖励将自动发放到您的账户钱包 |
| 151 | </Text> |
| 152 | <Text type="secondary">3. 账户钱包余额可提现到支付宝</Text> |
| 153 | </Space> |
| 154 | </Card> |
| 155 | </Space> |
| 156 | </Modal> |
| 157 | </> |
| 158 | ); |
| 159 | }); |
| 160 | |
| 161 | export default Com; |
| 162 |