wallet.vue 9.6 KB

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