index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="balance">
  3. <!-- <view class="date_picker">
  4. <picker mode="date" :value="selectedDate" fields="month" @change="_bindDateChange">
  5. <view>{{ formattedDate }}</view>
  6. </picker>
  7. </view> -->
  8. <view class="balance_content">
  9. <view class="balance_content_main">
  10. <view style="display: flex">
  11. <view class="price_content" style="margin-right: 45rpx">
  12. <text class="title">当前余额(元)</text> <text>{{ Number(userInfo.amount || 0).toFixed(2) }}</text></view
  13. >
  14. <view class="price_content">
  15. <text class="title">已成功提现(元)</text> <text>{{ Number(userInfo.transfer_amount || 0).toFixed(2) }}</text></view
  16. >
  17. </view>
  18. <view class="withdraw_btn" @click="_goWithdraw">兑现</view>
  19. </view>
  20. </view>
  21. <view class="balance_list">
  22. <!-- <view class="balance_date">2025年1月</view> -->
  23. <view class="balance_item" @click="_goDetail(item.id)" v-for="(item, index) in balanceList" :key="item.id">
  24. <view class="balance_item_fix">
  25. <view class="balance_item_left">
  26. <view style="margin-bottom: 10rpx"
  27. >{{ item.type_state }}
  28. <text v-if="item.state" style="font-size: 20rpx"> ({{ item.state }}) </text>
  29. </view>
  30. <view>{{ item.insert_time }}</view>
  31. </view>
  32. <view class="balance_item_right">
  33. <view class="price">{{ item.prefix == 1 ? '+' : '-' }}{{ item.amount }}</view>
  34. <view>余额:{{ item.balance }}</view>
  35. </view>
  36. </view>
  37. <view class="alter_info" v-if="item.buy_type == 2 && item.status == 1">若提现不成功,将在24小时内返回您的余额,可重新提现</view>
  38. </view>
  39. </view>
  40. <Empty v-if="balanceList.length == 0 && !isReqing" text="----- 还没有记录啦 -----" />
  41. <view class="to_bottom" v-if="isLast && balanceList.length"> -----到底啦-----</view>
  42. </view>
  43. </template>
  44. <script setup>
  45. import { ref, computed, onMounted } from 'vue';
  46. import { onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
  47. import Empty from '@/components/Empty/Empty.vue';
  48. import http from '@/utils/request';
  49. const selectedDate = ref('请选择日期');
  50. const balanceList = ref([]);
  51. const page = ref(1);
  52. const pageSize = ref(15);
  53. const isLast = ref(false);
  54. const isReqing = ref(false);
  55. const userInfo = ref({
  56. amount: 0,
  57. transfer_amount: 0,
  58. });
  59. const _bindDateChange = (e) => {
  60. selectedDate.value = e.detail.value;
  61. };
  62. onMounted(() => {
  63. _getBalacnelist();
  64. _getUserInfo();
  65. });
  66. const _goDetail = (record_id) => {
  67. uni.navigateTo({
  68. url: `/pages/balance/detail?record_id=${record_id}`,
  69. });
  70. };
  71. const _getBalacnelist = async () => {
  72. if (isReqing.value) return;
  73. isReqing.value = true;
  74. try {
  75. const callback = await http.request('api/custom_amount/get_record_list', {
  76. page: page.value,
  77. limit: pageSize.value,
  78. });
  79. if (callback.code == 'success') {
  80. if (callback.data.last_page <= page.value) isLast.value = true;
  81. const balanceListData = callback.data.data || [];
  82. balanceList.value = [...balanceList.value, ...balanceListData];
  83. }
  84. } finally {
  85. isReqing.value = false;
  86. }
  87. };
  88. const _getUserInfo = async () => {
  89. try {
  90. const callback = await http.request('api/custom/get_info');
  91. if (callback.code == 'success') {
  92. // 赋值
  93. userInfo.value = callback.data;
  94. // 存储登录标识
  95. uni.setStorageSync('userInfo', callback.data);
  96. }
  97. } catch (error) {
  98. console.log(error);
  99. }
  100. };
  101. onReachBottom(async () => {
  102. console.log('上拉加载');
  103. if (isLast.value || isReqing.value) return;
  104. page.value += 1;
  105. await _getBalacnelist();
  106. });
  107. onPullDownRefresh(async () => {
  108. page.value = 1;
  109. balanceList.value = [];
  110. isLast.value = false;
  111. await _getBalacnelist();
  112. uni.stopPullDownRefresh();
  113. });
  114. const formattedDate = computed(() => {
  115. if (selectedDate.value === '请选择日期') {
  116. return selectedDate.value;
  117. }
  118. const [year, month] = selectedDate.value.split('-');
  119. return `${year}年${parseInt(month)}月`;
  120. });
  121. const _goWithdraw = () => {
  122. // #ifdef MP-WEIXIN
  123. uni.navigateTo({
  124. url: '/pages/user/withdraw',
  125. });
  126. // #endif
  127. // #ifdef H5
  128. uni.showModal({
  129. title: '温馨提示',
  130. content: '请前往小程序兑现',
  131. showCancel: false,
  132. });
  133. // #endif
  134. };
  135. </script>
  136. <style scoped lang="less">
  137. .balance {
  138. padding: 36rpx;
  139. box-sizing: border-box;
  140. width: 100vw;
  141. .balance_content {
  142. margin-bottom: 20rpx;
  143. padding: 35rpx;
  144. background-color: #fff;
  145. box-sizing: border-box;
  146. border-radius: 20rpx;
  147. position: sticky;
  148. top: 0;
  149. left: 0;
  150. right: 0;
  151. width: 100%;
  152. box-sizing: border-box;
  153. .balance_content_main {
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. .price_content {
  158. display: flex;
  159. flex-direction: column;
  160. > .title {
  161. font-size: 24rpx;
  162. margin-bottom: 15rpx;
  163. }
  164. }
  165. .withdraw_btn {
  166. color: #ffffff;
  167. background-color: #f89c33;
  168. border-radius: 60rpx;
  169. padding: 10rpx 20rpx;
  170. width: 90rpx;
  171. text-align: center;
  172. line-height: 40rpx;
  173. }
  174. }
  175. }
  176. .date_picker {
  177. padding: 0 16rpx;
  178. border: 1px solid #e5e5e5;
  179. width: 250rpx;
  180. height: 60rpx;
  181. line-height: 60rpx;
  182. margin-bottom: 40rpx;
  183. }
  184. .balance_list {
  185. .balance_date {
  186. font-weight: bold;
  187. padding-bottom: 20rpx;
  188. border-bottom: 2rpx solid #ddd;
  189. }
  190. .balance_item {
  191. border-bottom: 1px solid #ddd;
  192. padding-bottom: 20rpx;
  193. .balance_item_fix {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. .balance_item_left,
  198. .balance_item_right {
  199. display: flex;
  200. flex-direction: column;
  201. font-size: 26rpx;
  202. padding-top: 20rpx;
  203. }
  204. .balance_item_right {
  205. align-items: flex-end;
  206. > .price {
  207. font-weight: bold;
  208. margin-bottom: 10rpx;
  209. &.red {
  210. color: #ff0000;
  211. }
  212. &.green {
  213. color: #00ff00;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. .alter_info {
  220. display: block;
  221. color: #f89c33;
  222. font-size: 20rpx;
  223. overflow: hidden;
  224. margin: 0rpx auto;
  225. line-height: 40rpx;
  226. padding: 5rpx 0rpx;
  227. }
  228. }
  229. }
  230. </style>