CaIon 2 лет назад
Родитель
Сommit
bd22fee12d
1 измененных файлов с 28 добавлено и 5 удалено
  1. 28 5
      web/src/pages/TopUp/index.js

+ 28 - 5
web/src/pages/TopUp/index.js

@@ -1,5 +1,5 @@
 import React, {useEffect, useState} from 'react';
 import React, {useEffect, useState} from 'react';
-import {Button, Form, Grid, Header, Segment, Statistic} from 'semantic-ui-react';
+import {Button, Confirm, Form, Grid, Header, Segment, Statistic} from 'semantic-ui-react';
 import {API, showError, showInfo, showSuccess} from '../../helpers';
 import {API, showError, showInfo, showSuccess} from '../../helpers';
 import {renderNumber, renderQuota} from '../../helpers/render';
 import {renderNumber, renderQuota} from '../../helpers/render';
 
 
@@ -11,6 +11,8 @@ const TopUp = () => {
     const [topUpLink, setTopUpLink] = useState('');
     const [topUpLink, setTopUpLink] = useState('');
     const [userQuota, setUserQuota] = useState(0);
     const [userQuota, setUserQuota] = useState(0);
     const [isSubmitting, setIsSubmitting] = useState(false);
     const [isSubmitting, setIsSubmitting] = useState(false);
+    const [open, setOpen] = useState(false);
+    const [payWay, setPayWay] = useState('');
 
 
     const topUp = async () => {
     const topUp = async () => {
         if (redemptionCode === '') {
         if (redemptionCode === '') {
@@ -47,15 +49,24 @@ const TopUp = () => {
         window.open(topUpLink, '_blank');
         window.open(topUpLink, '_blank');
     };
     };
 
 
-    const onlineTopUp = async (payment) => {
+    const preTopUp = async (payment) => {
         if (amount === 0) {
         if (amount === 0) {
             await getAmount();
             await getAmount();
         }
         }
+        setPayWay(payment)
+        setOpen(true);
+    }
+
+    const onlineTopUp = async () => {
+        if (amount === 0) {
+            await getAmount();
+        }
+        setOpen(false);
         try {
         try {
             const res = await API.post('/api/user/pay', {
             const res = await API.post('/api/user/pay', {
                 amount: parseInt(topUpCount),
                 amount: parseInt(topUpCount),
                 top_up_code: topUpCode,
                 top_up_code: topUpCode,
-                PaymentMethod: payment
+                PaymentMethod: payWay
             });
             });
             if (res !== undefined) {
             if (res !== undefined) {
                 const {message, data} = res.data;
                 const {message, data} = res.data;
@@ -145,9 +156,21 @@ const TopUp = () => {
         }
         }
     }
     }
 
 
+    const handleCancel = () => {
+        setOpen(false);
+    }
+
     return (
     return (
         <div>
         <div>
             <Segment>
             <Segment>
+                <Confirm
+                    open={open}
+                    content={'充值数量:' + topUpCount + ',充值金额:' + renderAmount() + ',是否确认充值?'}
+                    cancelButton='取消充值'
+                    confirmButton="确定"
+                    onCancel={handleCancel}
+                    onConfirm={onlineTopUp}
+                />
                 <Header as='h3'>充值额度</Header>
                 <Header as='h3'>充值额度</Header>
                 <Grid columns={2} stackable>
                 <Grid columns={2} stackable>
                     <Grid.Column>
                     <Grid.Column>
@@ -204,14 +227,14 @@ const TopUp = () => {
                             {/*/>*/}
                             {/*/>*/}
                             <Button color='blue' onClick={
                             <Button color='blue' onClick={
                                 async () => {
                                 async () => {
-                                    onlineTopUp('zfb')
+                                    preTopUp('zfb')
                                 }
                                 }
                             }>
                             }>
                                 支付宝
                                 支付宝
                             </Button>
                             </Button>
                             <Button color='green' onClick={
                             <Button color='green' onClick={
                                 async () => {
                                 async () => {
-                                    onlineTopUp('wx')
+                                    preTopUp('wx')
                                 }
                                 }
                             }>
                             }>
                                 微信
                                 微信