李志伟 3 years ago
parent
commit
3d13be31d3
3 changed files with 64 additions and 51 deletions
  1. 36
    38
      src/pages/wallet/index.jsx
  2. 20
    13
      src/pages/withdrawal/index.jsx
  3. 8
    0
      src/services/withdrawal.js

+ 36
- 38
src/pages/wallet/index.jsx View File

@@ -1,31 +1,31 @@
1 1
 import Taro from "@tarojs/taro"
2 2
 import { View, ScrollView } from "@tarojs/components"
3
-import { useEffect,useState } from "react"
3
+import { useEffect, useState } from "react"
4 4
 import withLayout from '@/layouts'
5 5
 import CustomNav from "@/components/CustomNav"
6 6
 import WalletCard from "@/components/walletCard"
7 7
 import ListTitle from "@/components/ListTitle"
8
-import {getAccount,getLogList} from '@/services/account'
8
+import { getAccount, getLogList } from '@/services/account'
9 9
 import './style.less'
10 10
 
11 11
 
12 12
 export default withLayout((props) => {
13
-  const [balance,setBlance]=useState(0)
14
-  const [logList,setLogList]=useState([])
13
+  const [balance, setBlance] = useState(0)
14
+  const [logList, setLogList] = useState([])
15 15
   const goWithdrawal = () => {
16 16
     Taro.navigateTo({ url: `/pages/withdrawal/index?balance=${balance}` });
17 17
   }
18
-  const getList=()=>{
19
-    getAccount().then(res=>{
20
-      setBlance(res.amounts)
18
+  const getList = () => {
19
+    getAccount().then(res => {
20
+      setBlance(res.amounts / 100)
21 21
     })
22
-    getLogList().then(res=>{
22
+    getLogList().then(res => {
23 23
       setLogList(res.records)
24 24
     })
25 25
   }
26
-  useEffect(()=>{
26
+  useEffect(() => {
27 27
     getList()
28
-  },[])
28
+  }, [])
29 29
   return (
30 30
     <View className='page-index'>
31 31
       <View className='index-navbar'>
@@ -35,34 +35,32 @@ export default withLayout((props) => {
35 35
         <ScrollView scrollY style={{ height: '100%' }}>
36 36
           <WalletCard onClick={goWithdrawal} value={balance} />
37 37
           <ListTitle value='零钱明细' />
38
-          <View className='walletCell'>
39
-            <View className='flexTop'>
40
-              <View className='content'>提现</View>
41
-              <View className='money'>-9000</View>
42
-            </View>
43
-            <View className='withDrawalDetail'>2022-4-10 10:55</View>
44
-          </View>
45
-          <View className='walletCell'>
46
-            <View className='flexTop'>
47
-              <View className='content'>提现</View>
48
-              <View className='money'>-9</View>
49
-            </View>
50
-            <View className='withDrawalDetail'>2022-4-8 10:55</View>
51
-          </View>
52
-          <View className='walletCell'>
53
-            <View className='flexTop'>
54
-              <View className='content'>收入</View>
55
-              <View className='money revenue'>+200</View>
56
-            </View>
57
-            <View className='withDrawalDetail'>2022-2-10 10:55</View>
58
-          </View>
59
-          <View className='walletCell'>
60
-            <View className='flexTop'>
61
-              <View className='content'>提现</View>
62
-              <View className='money'>-90</View>
63
-            </View>
64
-            <View className='withDrawalDetail'>2022-4-1 10:55</View>
65
-          </View>
38
+          {
39
+            logList && logList.map(item => {
40
+              return <View key={item.accountId} className='walletCell'>
41
+                <View className='flexTop'>
42
+                  <View className='content'>
43
+                    {
44
+                      item.chargeType == 'order_pay' ?
45
+                        '订单收入' :
46
+                        item.chargeType == 'order_refund' ?
47
+                          '用户退款' :
48
+                          item.chargeType == 'withdraw' ?
49
+                            '提现' : ''
50
+                    }
51
+                  </View>
52
+                  <View className={['money', item.chargeType == 'order_pay' ? '' : 'revenue']}>
53
+                    {
54
+                      item.chargeType == 'order_pay' ?
55
+                        '+' + item.money / 100 :
56
+                        '-' + item.money / 100
57
+                    }
58
+                  </View>
59
+                </View>
60
+                <View className='withDrawalDetail'>{item.createDate.substr(0, 16)}</View>
61
+              </View>
62
+            })
63
+          }
66 64
         </ScrollView>
67 65
       </View>
68 66
     </View>

+ 20
- 13
src/pages/withdrawal/index.jsx View File

@@ -1,4 +1,4 @@
1
-import Taro, { useDidShow } from "@tarojs/taro"
1
+import Taro from "@tarojs/taro"
2 2
 import { useState, useEffect } from "react"
3 3
 import { View, Image, Input, Picker } from "@tarojs/components"
4 4
 import CustomNav from "@/components/CustomNav"
@@ -7,6 +7,7 @@ import ListTitle from "@/components/ListTitle"
7 7
 import MyButton from "@/components/MyButton"
8 8
 import withLayout from '@/layouts'
9 9
 import { getBankList } from '@/services/bank'
10
+import { addWithdrawal } from '@/services/withdrawal'
10 11
 import goto from '@/assets/user/goto.png'
11 12
 import addImg from '@/assets/bank/addBank.png'
12 13
 import './style.less'
@@ -18,10 +19,9 @@ export default withLayout((props) => {
18 19
   const [money, setMoney] = useState()
19 20
   const [bankList, setBankList] = useState([])
20 21
   const [bankContentList, setBankContentList] = useState([])
21
-
22
+  const [loading, setLoading] = useState(false)
22 23
   const [index, setIndex] = useState(0)
23 24
   const onChange = e => {
24
-    console.log(bankList[e.detail.value])
25 25
     setIndex(e.detail.value)
26 26
   }
27 27
 
@@ -33,11 +33,22 @@ export default withLayout((props) => {
33 33
           icon: 'none',
34 34
         })
35 35
       } else {
36
-        Taro.showToast({
37
-          title: '提交成功,1到3个工作日将到您的付款账户',
38
-          icon: 'none',
36
+        setLoading(true)
37
+        addWithdrawal({ accountCardNo: bankList[index].cardId, money: (money - 0) * 100 }).then(() => {
38
+          Taro.showToast({
39
+            title: '提交成功,平台审核后1到3个工作日到账',
40
+            icon: 'none',
41
+          })
42
+          setTimeout(() => {
43
+            Taro.navigateBack({ delta: 1 })
44
+          }, 1000)
45
+        }).catch(err => {
46
+          Taro.showToast({
47
+            title: err.message,
48
+            icon: 'none',
49
+          })
50
+          setLoading(false)
39 51
         })
40
-        // 刷新页面
41 52
       }
42 53
     }
43 54
     else {
@@ -46,7 +57,6 @@ export default withLayout((props) => {
46 57
         icon: 'none',
47 58
       })
48 59
     }
49
-
50 60
   }
51 61
   const handleChanage = (e) => {
52 62
     setMoney(e.detail.value)
@@ -64,9 +74,6 @@ export default withLayout((props) => {
64 74
       }
65 75
     })
66 76
   }
67
-  useDidShow(() => {
68
-    getList()
69
-  })
70 77
   useEffect(() => {
71 78
     getList()
72 79
   }, [])
@@ -96,10 +103,10 @@ export default withLayout((props) => {
96 103
         <ListTitle value='选择银行卡' />
97 104
         <View className='bankInput'>
98 105
           <View className='header'>¥</View>
99
-          <Input className='body' type='number' placeholder='请输入提取金额' value={money} onInput={handleChanage} />
106
+          <Input className='body' type='digit' placeholder='请输入提取金额' value={money} onInput={handleChanage} />
100 107
         </View>
101 108
         <View className='bottomBtn'>
102
-          <MyButton value='提现' onClick={onClick} />
109
+          <MyButton loading={loading} value='提现' onClick={onClick} />
103 110
         </View>
104 111
       </View>
105 112
     </View>

+ 8
- 0
src/services/withdrawal.js View File

@@ -0,0 +1,8 @@
1
+import request from '@/utils/request'
2
+
3
+/**
4
+ * 提现申请
5
+ * @param {*} data 
6
+ * @returns 
7
+ */
8
+ export const addWithdrawal = (data) => request('/withdrawal', { data, method: 'post' })