index.jsx 3.0 KB

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