wallet.vue 9.5 KB

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