wallet.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="wallet-page">
  3. <!-- 余额卡片 -->
  4. <view class="balance-card">
  5. <view class="card-header">
  6. <text>我的余额</text>
  7. <view class="detail-link" @click="handleWithdrawDetail">
  8. 提现明细
  9. <u-icon name="arrow-right" color="#FFFFFF" size="26" top="4rpx"></u-icon>
  10. </view>
  11. </view>
  12. <view class="amount flex-c">
  13. <text class="number">¥ {{ restMoney }}</text>
  14. </view>
  15. <view class="balance-info flex-c">
  16. (可用余额¥{{ canUseMoney }} 提现中¥{{ freezeMoney }})
  17. </view>
  18. <view class="flex-c">
  19. <view class="withdraw-btn" @click="handleWithdraw">
  20. 提现
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 余额明细列表 -->
  25. <view class="detail-section">
  26. <view class="section-header">
  27. <text>余额明细</text>
  28. <view class="filter" @click="toggleFilter">
  29. 分类
  30. <u-icon name="arrow-down" color="#333" size="26"></u-icon>
  31. </view>
  32. </view>
  33. <page-scroll @updateList="handleUpdateList" ref="pageRef" slotEmpty url="/token/user/accountChangeList"
  34. :immediate="false" bgColor="#ffffff">
  35. <view class="detail-list">
  36. <view class="detail-item" v-for="(item, index) in detailList" :key="index"
  37. @click="goToDetail(item)">
  38. <view class="item-left">
  39. <text class="title">{{ item.title }}</text>
  40. <text class="time">{{ item.createTime }}</text>
  41. </view>
  42. <view class="item-right">
  43. <text :class="['amount', item.changeMoney > 0 ? 'income' : 'expense']">
  44. {{ item.changeMoney }}
  45. </text>
  46. <text class="status" v-if="item.desc">{{ item.desc }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. </page-scroll>
  51. </view>
  52. <!-- 分类选择弹窗 -->
  53. <category-popup :show.sync="showCategoryPopup" @confirm="onCategoryConfirm"></category-popup>
  54. </view>
  55. </template>
  56. <script>
  57. import CategoryPopup from '../components/category-popup.vue'
  58. import pageScroll from '@/components/pageScroll/index.vue'
  59. export default {
  60. components: {
  61. CategoryPopup,
  62. pageScroll
  63. },
  64. data() {
  65. return {
  66. showCategoryPopup: false,
  67. restMoney: '0.00',
  68. freezeMoney: '0.00',
  69. canUseMoney: '0.00',
  70. detailList: [],
  71. otherParams: {
  72. queryTypes: ''
  73. }
  74. }
  75. },
  76. onLoad() {
  77. this.getWithdrawInfo()
  78. this.$refs.pageRef.loadData(true, { queryTypes: '' })
  79. },
  80. methods: {
  81. async getWithdrawInfo() {
  82. try {
  83. const res = await uni.$u.http.get('/token/user/accountInfo')
  84. if (res.code === 200) {
  85. const { userId, restMoney, freezeMoney, canUseMoney } = res.data
  86. this.restMoney = restMoney
  87. this.freezeMoney = freezeMoney
  88. this.canUseMoney = canUseMoney
  89. }
  90. } catch (e) {
  91. console.error('获取提现信息失败:', e)
  92. }
  93. },
  94. // 分类选择
  95. onCategoryConfirm(selectedCategories) {
  96. console.log('选中的分类:', selectedCategories)
  97. this.otherParams.queryTypes = selectedCategories.join(',')
  98. this.$refs.pageRef.loadData(true, this.otherParams)
  99. },
  100. goToDetail(item) {
  101. if (item.desc == '待确认收款') {
  102. uni.$u.http.post('/token/user/withdrawConfirm', {
  103. orderNo: item.orderNo
  104. }).then(res => {
  105. if (res.code === 200) {
  106. this.handleConfirmReceipt(res.data)
  107. }
  108. }).catch(err => {
  109. uni.showToast({
  110. title: err.message || '确认失败',
  111. icon: 'none'
  112. });
  113. });
  114. }
  115. },
  116. handleWithdraw() {
  117. uni.navigateTo({
  118. url: '/pages-mine/pages/withdraw'
  119. })
  120. },
  121. handleWithdrawDetail() {
  122. uni.navigateTo({
  123. url: '/pages-mine/pages/withdraw-detail'
  124. })
  125. },
  126. toggleFilter() {
  127. // 实现筛选功能
  128. this.showCategoryPopup = !this.showCategoryPopup
  129. },
  130. // 更新列表
  131. handleUpdateList(data) {
  132. this.detailList = data
  133. },
  134. //执行微信确认收款操作
  135. handleConfirmReceipt(data) {
  136. if (wx.canIUse('requestMerchantTransfer')) {
  137. wx.requestMerchantTransfer({
  138. mchId: data.mchId,
  139. appId: data.appId,
  140. package: data.packageStr,
  141. success: (res) => {
  142. // res.err_msg将在页面展示成功后返回应用时返回ok,并不代表付款成功
  143. uni.showToast({
  144. title: '确认收款成功',
  145. icon: 'none'
  146. })
  147. // 刷新列表和余额信息
  148. this.getWithdrawInfo();
  149. this.$refs.pageRef.loadData(true, this.otherParams);
  150. },
  151. fail: (res) => {
  152. console.log('fail:', res);
  153. },
  154. });
  155. } else {
  156. wx.showModal({
  157. content: '你的微信版本过低,请更新至最新版本。',
  158. showCancel: false,
  159. });
  160. }
  161. },
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .wallet-page {
  167. min-height: 100vh;
  168. background: #F5F5F5;
  169. padding: 10rpx 30rpx;
  170. box-sizing: border-box;
  171. .balance-card {
  172. background: #38C148;
  173. border-radius: 20rpx;
  174. padding: 30rpx 40rpx;
  175. color: #FFFFFF;
  176. .card-header {
  177. display: flex;
  178. justify-content: space-between;
  179. align-items: center;
  180. font-size: 28rpx;
  181. .detail-link {
  182. display: flex;
  183. align-items: center;
  184. opacity: 0.9;
  185. }
  186. }
  187. .amount {
  188. margin: 40rpx 0 20rpx;
  189. .symbol {
  190. font-size: 40rpx;
  191. margin-right: 8rpx;
  192. }
  193. .number {
  194. font-size: 80rpx;
  195. font-weight: 500;
  196. }
  197. }
  198. .balance-info {
  199. font-size: 26rpx;
  200. opacity: 0.9;
  201. }
  202. .withdraw-btn {
  203. margin-top: 40rpx;
  204. height: 60rpx;
  205. line-height: 60rpx;
  206. text-align: center;
  207. background: rgba(255, 255, 255, 0.2);
  208. border-radius: 14rpx;
  209. font-size: 28rpx;
  210. width: 200rpx;
  211. }
  212. }
  213. .detail-section {
  214. background: #FFFFFF;
  215. border-radius: 20rpx;
  216. margin-top: 20rpx;
  217. padding: 0 30rpx;
  218. .section-header {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. height: 100rpx;
  223. font-size: 30rpx;
  224. color: #333;
  225. border-bottom: 1px solid #EEEEEE;
  226. .filter {
  227. display: flex;
  228. align-items: center;
  229. color: #666;
  230. font-size: 28rpx;
  231. margin-right: 8rpx;
  232. }
  233. }
  234. .detail-list {
  235. .detail-item {
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. padding: 30rpx 0;
  240. border-bottom: 1px solid #EEEEEE;
  241. &:last-child {
  242. border-bottom: none;
  243. }
  244. .item-left {
  245. .title {
  246. font-size: 28rpx;
  247. color: #333;
  248. margin-bottom: 10rpx;
  249. display: block;
  250. }
  251. .time {
  252. font-size: 24rpx;
  253. color: #999;
  254. }
  255. }
  256. .item-right {
  257. text-align: right;
  258. .amount {
  259. display: block;
  260. font-size: 32rpx;
  261. margin-bottom: 10rpx;
  262. font-weight: 500;
  263. &.income {
  264. color: #FF5B5B;
  265. }
  266. &.expense {
  267. color: #38C148;
  268. }
  269. }
  270. .status {
  271. font-size: 24rpx;
  272. color: #999;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. }
  279. </style>