wallet.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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" :height="height">
  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. height: 'calc(100vh - 540rpx)'
  75. }
  76. },
  77. onLoad() {
  78. this.getWithdrawInfo()
  79. this.$refs.pageRef.loadData(true, { queryTypes: '' })
  80. },
  81. methods: {
  82. async getWithdrawInfo() {
  83. try {
  84. const res = await uni.$u.http.get('/token/user/accountInfo')
  85. if (res.code === 200) {
  86. const { userId, restMoney, freezeMoney, canUseMoney } = res.data
  87. this.restMoney = restMoney
  88. this.freezeMoney = freezeMoney
  89. this.canUseMoney = canUseMoney
  90. }
  91. } catch (e) {
  92. console.error('获取提现信息失败:', e)
  93. }
  94. },
  95. // 分类选择
  96. onCategoryConfirm(selectedCategories) {
  97. console.log('选中的分类:', selectedCategories)
  98. this.otherParams.queryTypes = selectedCategories.join(',')
  99. this.$refs.pageRef.loadData(true, this.otherParams)
  100. },
  101. goToDetail(item) {
  102. if (item.desc == '待确认收款') {
  103. uni.$u.http.post('/token/user/withdrawConfirm', {
  104. orderNo: item.orderNo
  105. }).then(res => {
  106. if (res.code === 200) {
  107. this.handleConfirmReceipt(res.data)
  108. }
  109. }).catch(err => {
  110. uni.showToast({
  111. title: err.message || '确认失败',
  112. icon: 'none'
  113. });
  114. });
  115. }
  116. },
  117. handleWithdraw() {
  118. uni.navigateTo({
  119. url: '/pages-mine/pages/withdraw'
  120. })
  121. },
  122. handleWithdrawDetail() {
  123. uni.navigateTo({
  124. url: '/pages-mine/pages/withdraw-detail'
  125. })
  126. },
  127. toggleFilter() {
  128. // 实现筛选功能
  129. this.showCategoryPopup = !this.showCategoryPopup
  130. },
  131. // 更新列表
  132. handleUpdateList(data) {
  133. this.detailList = data
  134. },
  135. //执行微信确认收款操作
  136. handleConfirmReceipt(data) {
  137. if (wx.canIUse('requestMerchantTransfer')) {
  138. wx.requestMerchantTransfer({
  139. mchId: data.mchId,
  140. appId: data.appId,
  141. package: data.packageStr,
  142. success: (res) => {
  143. // res.err_msg将在页面展示成功后返回应用时返回ok,并不代表付款成功
  144. uni.showToast({
  145. title: '确认收款成功',
  146. icon: 'none'
  147. })
  148. // 刷新列表和余额信息
  149. this.getWithdrawInfo();
  150. this.$refs.pageRef.loadData(true, this.otherParams);
  151. },
  152. fail: (res) => {
  153. console.log('fail:', res);
  154. },
  155. });
  156. } else {
  157. wx.showModal({
  158. content: '你的微信版本过低,请更新至最新版本。',
  159. showCancel: false,
  160. });
  161. }
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .wallet-page {
  168. height: 100vh;
  169. background: #F5F5F5;
  170. padding: 10rpx 30rpx;
  171. box-sizing: border-box;
  172. overflow: hidden;
  173. .balance-card {
  174. background: #38C148;
  175. border-radius: 20rpx;
  176. padding: 30rpx 40rpx;
  177. color: #FFFFFF;
  178. z-index: 9;
  179. position: sticky;
  180. top: 10rpx;
  181. .card-header {
  182. display: flex;
  183. justify-content: space-between;
  184. align-items: center;
  185. font-size: 28rpx;
  186. .detail-link {
  187. display: flex;
  188. align-items: center;
  189. opacity: 0.9;
  190. }
  191. }
  192. .amount {
  193. margin: 40rpx 0 20rpx;
  194. .symbol {
  195. font-size: 40rpx;
  196. margin-right: 8rpx;
  197. }
  198. .number {
  199. font-size: 80rpx;
  200. font-weight: 500;
  201. }
  202. }
  203. .balance-info {
  204. font-size: 26rpx;
  205. opacity: 0.9;
  206. }
  207. .withdraw-btn {
  208. margin-top: 40rpx;
  209. height: 60rpx;
  210. line-height: 60rpx;
  211. text-align: center;
  212. background: rgba(255, 255, 255, 0.2);
  213. border-radius: 14rpx;
  214. font-size: 28rpx;
  215. width: 200rpx;
  216. }
  217. }
  218. .detail-section {
  219. background: #FFFFFF;
  220. border-radius: 20rpx;
  221. margin-top: 20rpx;
  222. padding: 0 30rpx;
  223. height: calc(100vh - 400rpx);
  224. overflow-y: auto;
  225. .section-header {
  226. display: flex;
  227. justify-content: space-between;
  228. align-items: center;
  229. height: 100rpx;
  230. font-size: 30rpx;
  231. color: #333;
  232. border-bottom: 1px solid #EEEEEE;
  233. .filter {
  234. display: flex;
  235. align-items: center;
  236. color: #666;
  237. font-size: 28rpx;
  238. margin-right: 8rpx;
  239. }
  240. }
  241. .detail-list {
  242. .detail-item {
  243. display: flex;
  244. justify-content: space-between;
  245. align-items: center;
  246. padding: 30rpx 0;
  247. border-bottom: 1px solid #EEEEEE;
  248. &:last-child {
  249. border-bottom: none;
  250. }
  251. .item-left {
  252. .title {
  253. font-size: 28rpx;
  254. color: #333;
  255. margin-bottom: 10rpx;
  256. display: block;
  257. }
  258. .time {
  259. font-size: 24rpx;
  260. color: #999;
  261. }
  262. }
  263. .item-right {
  264. text-align: right;
  265. .amount {
  266. display: block;
  267. font-size: 32rpx;
  268. margin-bottom: 10rpx;
  269. font-weight: 500;
  270. &.income {
  271. color: #FF5B5B;
  272. }
  273. &.expense {
  274. color: #38C148;
  275. }
  276. }
  277. .status {
  278. font-size: 24rpx;
  279. color: #999;
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
  286. </style>