Browse Source

增加提现记录的分页,完善提现逻辑

黎海 3 weeks ago
parent
commit
b1c6af0e28

+ 73 - 0
src/api/request_api.js

@@ -0,0 +1,73 @@
1
+import Taro from '@tarojs/taro';
2
+import ttappid from '../../project.tt.json'; // 抖音
3
+import wxappid from '../../project.config.json'; // 微信
4
+import { baseUrl } from './config';
5
+
6
+const getAppId = () => {
7
+  if (process.env.TARO_ENV === 'weapp') {
8
+    return wxappid.appid;
9
+  } else if (process.env.TARO_ENV === 'tt') {
10
+    return ttappid.appid;
11
+  }
12
+  return '';
13
+};
14
+
15
+export default async (options = { method: 'GET', data: {} }) => {
16
+  const request_data = {
17
+    session_key: Taro.getStorageSync('session_key') || '', // 缓存取值
18
+    appid: getAppId(),
19
+    channel_name: 'WeChat'
20
+  };
21
+
22
+  // 如果是登录接口,移除 session_key
23
+  if (options.url.includes('/user/login_applet')) {
24
+    delete request_data.session_key;
25
+  }
26
+
27
+  try {
28
+    const res = await Taro.request({
29
+      url: baseUrl + options.url,
30
+      data: {
31
+        ...request_data,
32
+        ...options.data,
33
+      },
34
+      header: {
35
+        'Content-Type': 'application/json',
36
+        accept: 'application/json',
37
+      },
38
+      method: options.method.toUpperCase(),
39
+    });
40
+    const { code, data, msg } = res.data;
41
+    console.log('==========', options.url);
42
+    console.log('options', options.data);
43
+    console.log('res', res);
44
+    switch (code) {
45
+      case 500:
46
+        Taro.showToast({
47
+          title: '需要登录',
48
+          icon: 'none',
49
+          mask: true,
50
+        });
51
+
52
+        // 获取当前跳转到登录的页面路径
53
+        const currentPages = Taro.getCurrentPages();
54
+        const currentPage = currentPages[currentPages.length - 1];
55
+        if (currentPage) {
56
+          // 储存当前页面路径
57
+          Taro.setStorageSync('currentPage', currentPage.route);
58
+          global.globalData.optionsData = currentPage.options || {};
59
+        }
60
+
61
+        Taro.reLaunch({
62
+          url: '/pages/login/index',
63
+        });
64
+        // throw new Error('需要登录');
65
+        break
66
+      default:
67
+        return res.data;
68
+    }
69
+  } catch (error) {
70
+    console.error('请求错误:', error);
71
+    return Promise.reject(error);
72
+  }
73
+};

+ 22 - 6
src/pages/member/index.jsx

@@ -21,7 +21,20 @@ export default class Index extends Component {
21 21
       partner: { partner_direct_cnt: 0 },
22 22
       order: { order_all: 0, order_promotion: 0, order_pay: 0, unissued_order_cnt: 0, on_arrival_order_cnt: 0, dead_order_cnt: 0 },
23 23
     }, //会员信息
24
+    isAlipay: true,//是否签约
24 25
   };
26
+
27
+  // 获取签约信息
28
+  getWorkerInfo = async () => {
29
+    const res = await get_my_worker_info();
30
+    if (res.data.length == 0) {
31
+      this.setState({
32
+        isAlipay: false
33
+      })
34
+    }
35
+    console.log(res, 'res');
36
+  }
37
+
25 38
   // 获取会员首页数据
26 39
   getVipInfo = async () => {
27 40
     const res = await getVipInfo();
@@ -117,15 +130,18 @@ export default class Index extends Component {
117 130
             <View className="withdrawable-amount-content">
118 131
               <View className="left">
119 132
                 <Text className="amount">
120
-                  ¥{vipInfo.draw_money.store_earnings_now}
133
+                  {`¥ ${vipInfo.draw_money.store_earnings_now}`}
121 134
                 </Text>
135
+                {
136
+                  !this.state.isAlipay &&
137
+                  <View className="warning-icon-box">
138
+                    <Image className="warning-icon" src={warning} />
139
+                    <Text className="warning-text">未完成提现认证</Text>
140
+                  </View>
141
+                }
122 142
 
123
-                <View className="warning-icon-box">
124
-                  <Image className="warning-icon" src={warning} />
125
-                  <Text className="warning-text">未完成提现认证</Text>
126
-                </View>
127 143
               </View>
128
-              <View onClick={() => Taro.navigateTo({ url: `/pages/memberSub/cashOut/index` })} className="right">点击提现</View> 
144
+              <View onClick={() => Taro.navigateTo({ url: `/pages/memberSub/cashOut/index` })} className="right">点击提现</View>
129 145
             </View>
130 146
           </View>
131 147
           {/* 我的伙伴 */}

+ 28 - 14
src/pages/memberSub/Alipay/index.jsx

@@ -31,8 +31,8 @@ export default class Index extends Component {
31 31
   // 获取签约信息
32 32
   getWorkerInfo = async () => {
33 33
     const res = await get_my_worker_info();
34
-    if (res.length > 0) {
35
-      res.forEach(item => {
34
+    if (res.data.length > 0) {
35
+      res.data.forEach(item => {
36 36
         if (item.rsv_account_type === 1) {
37 37
           this.setState({
38 38
             name: item.name,
@@ -113,7 +113,7 @@ export default class Index extends Component {
113 113
                 img_url: data.url
114 114
               }).then(res => {
115 115
                 console.log(res, 'res111');
116
-                let info = JSON.parse(res);
116
+                let info = JSON.parse(res.data);
117 117
                 that.setState({ idCard: info.card_no, name: info.name });
118 118
               })
119 119
             } else if (type === 'back') {
@@ -190,11 +190,22 @@ export default class Index extends Component {
190 190
       national_emblem_page: idCardBack
191 191
     }).then(res => {
192 192
       console.log(res, 'res');
193
-      Taro.showToast({
194
-        title: '签约成功',
195
-        icon: 'none',
196
-        duration: 2000
197
-      });
193
+      if (res.code === 200) {
194
+        this.getWorkerInfo()
195
+        Taro.showToast({
196
+          title: '签约成功',
197
+          icon: 'success',
198
+          mask: true,
199
+          duration: 2000
200
+        });
201
+      } else {
202
+        Taro.showToast({
203
+          title: `签约失败:${res.msg}`,
204
+          icon: 'none',
205
+          mask: true,
206
+          duration: 3000
207
+        });
208
+      }
198 209
     }).finally(() => {
199 210
       Taro.hideLoading();
200 211
     })
@@ -300,14 +311,17 @@ export default class Index extends Component {
300 311
             )
301 312
           }
302 313
         </View>
303
-        <View className="alipay-info-tips">
304
-          <View className="alipay-info-tips-item">
305
-            <Image src={this.state.signImg} className="alipay-info-tips-item-icon" />
306
-            <View className="alipay-info-tips-item-text">
307
-              如需更改,请联系客服
314
+        {
315
+          this.isBind() &&
316
+          <View className="alipay-info-tips">
317
+            <View className="alipay-info-tips-item">
318
+              <Image src={this.state.signImg} className="alipay-info-tips-item-icon" />
319
+              <View className="alipay-info-tips-item-text">
320
+                如需更改,请联系客服
321
+              </View>
308 322
             </View>
309 323
           </View>
310
-        </View>
324
+        }
311 325
         {/* 注意 */}
312 326
         {
313 327
           !this.isBind() && (

+ 36 - 18
src/pages/memberSub/cashOut/index.jsx

@@ -11,7 +11,7 @@ export default class Index extends Component {
11 11
     isOpened: false,
12 12
     isAlipay: false, // 是否已绑定支付宝
13 13
     isBank: false, // 是否已绑定银行卡
14
-    amount: 0, // 提现金额
14
+    amount: '', // 提现金额
15 15
     bank_id: 0, // 银行卡id
16 16
     alipay_id: 0, // 支付宝id
17 17
     type: 0, // 提现类型
@@ -33,19 +33,19 @@ export default class Index extends Component {
33 33
   // 获取签约信息
34 34
   getWorkerInfo = async () => {
35 35
     const res = await get_my_worker_info();
36
-    if (res.length > 0) {
37
-      res.forEach(item => {
36
+    if (res.data.length > 0) {
37
+      res.data.forEach(item => {
38 38
         if (item.rsv_account_type === 1) {
39 39
           this.setState({
40 40
             type: 1,
41 41
             isAlipay: true,
42
-            alipay_id: item.rsv_account_id
42
+            alipay_id: item.id
43 43
           });
44 44
         } else {
45 45
           this.setState({
46 46
             type: 0,
47 47
             isBank: true,
48
-            bank_id: item.rsv_account_id
48
+            bank_id: item.id
49 49
           });
50 50
         }
51 51
       });
@@ -67,28 +67,46 @@ export default class Index extends Component {
67 67
     })
68 68
   }
69 69
   handleChange = (e) => {
70
-    if (e > this.state.translate_money) {
71
-      e == this.state.translate_money
70
+    let amount = e;
71
+   
72
+    let translate_money = parseFloat(this.state.translate_money);
73
+    
74
+    if (amount > translate_money) {
75
+      amount = translate_money;
72 76
     }
73 77
     this.setState({
74
-      amount: e
75
-    })
78
+      amount: amount
79
+    });
76 80
   }
77 81
   handleSubmit = async () => {
82
+    if (this.state.amount <= 0) {
83
+      Taro.showToast({
84
+        title: '请输入大于0的金额',
85
+        icon: 'none'
86
+      })
87
+      return;
88
+    }
89
+    console.log(this.state.alipay_id, 'this.state.alipay_id', this.state.bank_id, 'this.state.bank_id');
90
+
78 91
     const res = await submit_withdraw_record({
79 92
       amount: this.state.amount,
80 93
       bank_id: this.state.type === 1 ? this.state.alipay_id : this.state.bank_id
81 94
     });
82
-    if (res.code === 0) {
95
+    if (res.code === 200) {
83 96
       Taro.showToast({
84 97
         title: '提现申请成功',
85
-        icon: 'none'
98
+        icon: 'success'
86 99
       })
87
-      this.setState({
88
-        isOpened: false
100
+    } else {
101
+      Taro.showToast({
102
+        title: `提现失败:${res.msg}`,
103
+        icon: 'error'
89 104
       })
90
-      this.getUserInfo();
91 105
     }
106
+    this.setState({
107
+      isOpened: false
108
+    })
109
+    this.getUserInfo();
92 110
   }
93 111
 
94 112
   render () {
@@ -117,7 +135,7 @@ export default class Index extends Component {
117 135
             <View className='line'></View>
118 136
             {/* <AtListItem hasBorder={false} title='支付账户' extraText='需维护支付宝账户信息' arrow='right' /> */}
119 137
             {/* <View className='line'></View> */}
120
-            <AtListItem hasBorder={false} onClick={() => Taro.navigateTo({ url: `/pages/memberSub/statementRecords/index` })} title='标题结算单记录' extraText='6月结算单已出' arrow='right' />
138
+            {/* <AtListItem hasBorder={false} onClick={() => Taro.navigateTo({ url: `/pages/memberSub/statementRecords/index` })} title='标题结算单记录' extraText='6月结算单已出' arrow='right' /> */}
121 139
           </AtList>
122 140
         </View>
123 141
         {/* 结算单说明 */}
@@ -163,14 +181,14 @@ export default class Index extends Component {
163 181
               }
164 182
               {
165 183
                 this.state.isBank &&
166
-                <View className={['amount-info-item', this.state.type === 0 ? 'active' : '']} onClick={() => this.setState({ type: 2 })}>
184
+                <View className={['amount-info-item', this.state.type === 0 ? 'active' : '']} onClick={() => this.setState({ type: 0 })}>
167 185
                   <Image src='https://video-img.fyshark.com/1735041334363%E6%94%AF%E4%BB%98%E5%B9%B3%E5%8F%B0-%E9%93%B6%E8%81%94.png' style={{ width: '32px', height: '24px' }} />
168 186
                   <Text className='amount-info-item-text'>银行卡</Text>
169 187
                 </View>
170 188
               }
171 189
             </View>
172
-            <View className='submit-btn'>
173
-              <View className='submit-btn-text' onClick={this.handleSubmit}>提交</View>
190
+            <View className='submit-btn' onClick={this.handleSubmit}>
191
+              <View className='submit-btn-text'>提交</View>
174 192
             </View>
175 193
           </AtModalContent>
176 194
           <AtModalAction>  </AtModalAction>

+ 55 - 29
src/pages/memberSub/cashOutRecord/index.jsx

@@ -1,5 +1,5 @@
1 1
 import { Component } from 'react'
2
-import { View, Text, Image } from '@tarojs/components'
2
+import { View, Text, Image, ScrollView } from '@tarojs/components'
3 3
 import './index.less'
4 4
 import wallet from '../../../images/wallet.png'
5 5
 import { get_withdraw_record } from '../../../service/money_api'
@@ -8,15 +8,17 @@ export default class Index extends Component {
8 8
   state = {
9 9
     withdraw_record_list: [],
10 10
     page: 1,
11
-    page_size: 20, // 每页加载20条
11
+    page_size: 7, // 每页加载20条
12 12
     total: 0,
13
-    loading: false // 加载状态
13
+    loading: false, // 加载状态
14
+    translate_already_money: 0,
14 15
   }
15 16
 
16 17
   componentDidShow () {
17 18
     this.get_withdraw_record()
18 19
   }
19 20
 
21
+
20 22
   get_withdraw_record = async () => {
21 23
     if (this.state.loading) return; // 防止重复加载
22 24
     this.setState({ loading: true });
@@ -26,47 +28,71 @@ export default class Index extends Component {
26 28
     })
27 29
     console.log(res, 'res')
28 30
     this.setState(prevState => ({
29
-      withdraw_record_list: prevState.page === 1 ? res : [...prevState.withdraw_record_list, ...res],
31
+      withdraw_record_list: prevState.page === 1 ? res.data.record_list : [...prevState.withdraw_record_list, ...res.data.record_list],
32
+      translate_already_money: res.data.translate_already_money,
33
+      total: res.data.total_count,
30 34
       loading: false
31 35
     }))
32 36
   }
33 37
 
34 38
   onReachBottom = () => {
39
+    console.log(this.state.page + 1, 'this.state.page + 1',this.state.page);
40
+    
35 41
     if (this.state.withdraw_record_list.length < this.state.total) {
36 42
       this.setState(prevState => ({ page: prevState.page + 1 }), this.get_withdraw_record)
37 43
     }
38 44
   }
39 45
 
46
+  stateToMoney = (status) => {
47
+    console.log(status, 'status');
48
+
49
+    switch (status) {
50
+      case 0:
51
+        return { text: '提现中', color: 'orange' }
52
+      case 1:
53
+        return { text: '审核通过,打款中...', color: 'blue' }
54
+      case 7:
55
+        return { text: '已到账', color: '#07d807' }
56
+      case 4:
57
+        return { text: '已拒绝,请联系客服', color: 'red' }
58
+      default:
59
+        return { text: '未知状态', color: 'gray' }
60
+    }
61
+  }
62
+
40 63
   render () {
41 64
     return (
42
-      <View className='index' onScrollToLower={this.onReachBottom}>
43
-        {/* 提现记录 */}
44
-        <View className='cash-out-record'>
45
-          {/* 累计提现金额 */}
46
-          <View className='total-amount'>
47
-            <View className='left'>
48
-              <Image src={wallet} className='icon' />
49
-              <Text className='title'>累计提现金额</Text>
50
-            </View>
51
-            <View className='amount'>
52
-              <Text className='integer'>¥10000.</Text>
53
-              <Text className='decimal'>00</Text>
54
-            </View>
65
+      <ScrollView
66
+        className='index'
67
+        scrollY
68
+        onScrollToLower={this.onReachBottom}
69
+      >
70
+        {/* 累计提现金额 */}
71
+        <View className='total-amount'>
72
+          <View className='left'>
73
+            <Image src={wallet} className='icon' />
74
+            <Text className='title'>累计提现金额</Text>
75
+          </View>
76
+          <View className='amount'>
77
+            <Text className='integer'>{`¥${this.state.translate_already_money}`}</Text>
55 78
           </View>
56
-          {/* 提现记录 */}
57
-          {this.state.withdraw_record_list.map((item, index) => {
58
-            return (
59
-              <View className='record-item' key={index}>
60
-                <View className='item-time'>{item.time.replace('T', ' ')}</View>
61
-                <View className='item-amount'>
62
-                  <View className='amount'>¥{item.amount}</View>
63
-                  <View className='status'>{item.msg}</View>
79
+        </View>
80
+        {/* 提现记录 */}
81
+        {this.state.withdraw_record_list.map((item, index) => {
82
+          const statusInfo = this.stateToMoney(item.state);
83
+          return (
84
+            <View className='record-item' key={index}>
85
+              <View className='item-time'>{item.time.replace('T', ' ')}</View>
86
+              <View className='item-amount'>
87
+                <View className='amount'>¥{item.amount}</View>
88
+                <View className='status' style={{ color: statusInfo.color }}>
89
+                  {statusInfo.text}
64 90
                 </View>
65 91
               </View>
66
-            )
67
-          })}
68
-        </View>
69
-      </View>
92
+            </View>
93
+          )
94
+        })}
95
+      </ScrollView>
70 96
     )
71 97
   }
72 98
 }

+ 2 - 2
src/pages/memberSub/cashOutRecord/index.less

@@ -4,7 +4,7 @@
4 4
     padding: 30px 16px 0 16px;
5 5
     box-sizing: border-box;
6 6
 
7
-    .cash-out-record {
7
+    // .cash-out-record {
8 8
         .total-amount {
9 9
             height: 170px;
10 10
             background-color: #fff;
@@ -80,5 +80,5 @@
80 80
                 }
81 81
             }
82 82
         }
83
-    }
83
+    // }
84 84
 }

+ 1 - 1
src/service/money_api.js

@@ -1,4 +1,4 @@
1
-import Request from '../api/request';
1
+import Request from '../api/request_api';
2 2
 
3 3
 // 提现认证 
4 4
 export const worker_register = data =>