withdraw.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="withdraw-container">
  3. <!-- 顶部卡片 -->
  4. <view class="card balance-card">
  5. <view class="card-header">
  6. <text class="title">账户余额</text>
  7. </view>
  8. <view class="balance-display">
  9. <text class="amount">¥{{walletBalance}}</text>
  10. </view>
  11. </view>
  12. <!-- 提现表单 -->
  13. <view class="card withdraw-form">
  14. <view class="card-header">
  15. <text class="title">提现金额</text>
  16. </view>
  17. <view class="form-group">
  18. <text class="prefix">¥</text>
  19. <input class="input" type="digit" v-model="withdrawAmount" placeholder="请输入提现金额" placeholder-class="placeholder"
  20. @input="validateAmount" />
  21. </view>
  22. <view class="hint">
  23. <text>可提现余额 ¥{{walletBalance}}</text>
  24. <text class="all" @click="withdrawAll">全部提现</text>
  25. </view>
  26. <!-- 银行信息 -->
  27. <view class="bank-info" v-if="bankInfo">
  28. <view class="bank-item">
  29. <text class="label">银行名称</text>
  30. <text class="value">{{bankInfo.bankName}}</text>
  31. </view>
  32. <view class="bank-item">
  33. <text class="label">开户人</text>
  34. <text class="value">{{bankInfo.accountHolder}}</text>
  35. </view>
  36. <view class="bank-item">
  37. <text class="label">银行卡号</text>
  38. <text class="value">{{bankInfo.bankAccount}}</text>
  39. </view>
  40. </view>
  41. <button class="submit-btn" :class="{disabled: !canSubmit}" :disabled="!canSubmit" @click="submitWithdraw">
  42. 申请提现
  43. </button>
  44. <view class="tips">
  45. <text>提现申请将在1-3个工作日内处理</text>
  46. </view>
  47. </view>
  48. <!-- 提现记录 -->
  49. <view class="card record-list">
  50. <view class="card-header">
  51. <text class="title">提现记录</text>
  52. </view>
  53. <view class="list">
  54. <view class="record-item" v-for="item in records" :key="item.id" @click="viewDetail(item)">
  55. <view class="left">
  56. <view class="status" :class="statusClassMap[item.status]">
  57. {{getStatusText(item.status)}}
  58. </view>
  59. <view class="time">{{item.createTime}}</view>
  60. </view>
  61. <view class="right">
  62. <text class="amount">-¥{{item.amount}}</text>
  63. <image class="arrow" src=""></image>
  64. </view>
  65. </view>
  66. <view class="load-more" @click="loadMore" v-if="hasMore">
  67. <text>{{loading ? '加载中...' : '加载更多'}}</text>
  68. </view>
  69. <view class="empty" v-if="!loading && records.length === 0">
  70. <image class="empty-icon" src=""></image>
  71. <text class="empty-text">暂无提现记录</text>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. mapState
  80. } from 'vuex';
  81. export default {
  82. data() {
  83. return {
  84. walletBalance: 0,
  85. withdrawAmount: '',
  86. bankInfo: null,
  87. records: [],
  88. page: 1,
  89. pageSize: 10,
  90. total: 0,
  91. loading: false,
  92. hasMore: true
  93. };
  94. },
  95. computed: {
  96. ...mapState(['token', 'userInfo']),
  97. canSubmit() {
  98. return this.withdrawAmount > 0 &&
  99. this.withdrawAmount <= this.walletBalance &&
  100. this.bankInfo;
  101. },
  102. statusClassMap() {
  103. return {
  104. 0: 'pending',
  105. 1: 'approved',
  106. 2: 'rejected',
  107. 3: 'paid'
  108. };
  109. }
  110. },
  111. onLoad() {
  112. this.loadData();
  113. },
  114. methods: {
  115. loadData() {
  116. this.getWalletInfo();
  117. this.getBankInfo();
  118. this.getWithdrawRecords();
  119. },
  120. getWalletInfo() {
  121. uni.showLoading({
  122. title: '加载中...'
  123. });
  124. this.request("get", "rider/wallet/info", this.token).then(res => {
  125. if (res.code === 200) {
  126. this.walletBalance = res.data.walletBalance || 0;
  127. }
  128. }).finally(() => {
  129. uni.hideLoading();
  130. });
  131. },
  132. getBankInfo() {
  133. this.request("get", "rider/app/profile", this.token).then(res => {
  134. if (res.code === 200) {
  135. this.bankInfo = res.data;
  136. }
  137. });
  138. },
  139. getWithdrawRecords(refresh = false) {
  140. if (this.loading) return;
  141. this.loading = true;
  142. if (refresh) {
  143. this.page = 1;
  144. }
  145. this.request("get", "rider/withdrawal/list", this.token, {
  146. page: this.page,
  147. size: this.pageSize
  148. }).then(res => {
  149. if (res.code === 200) {
  150. const newData = res.data.rows || [];
  151. this.records = refresh ? newData : [...this.records, ...newData];
  152. this.total = res.data.total || 0;
  153. this.hasMore = this.records.length < this.total;
  154. }
  155. }).finally(() => {
  156. this.loading = false;
  157. });
  158. },
  159. validateAmount() {
  160. // 限制只能输入数字和小数点
  161. this.withdrawAmount = this.withdrawAmount.replace(/[^\d.]/g, '');
  162. // 限制小数点后最多两位
  163. if (this.withdrawAmount.includes('.')) {
  164. const parts = this.withdrawAmount.split('.');
  165. if (parts[1].length > 2) {
  166. this.withdrawAmount = parts[0] + '.' + parts[1].substring(0, 2);
  167. }
  168. }
  169. // 限制最大金额
  170. if (parseFloat(this.withdrawAmount) > this.walletBalance) {
  171. this.withdrawAmount = this.walletBalance.toString();
  172. }
  173. },
  174. withdrawAll() {
  175. this.withdrawAmount = this.walletBalance.toString();
  176. },
  177. submitWithdraw() {
  178. if (!this.canSubmit) return;
  179. const amount = parseFloat(this.withdrawAmount);
  180. if (amount <= 0 || amount > this.walletBalance) {
  181. uni.showToast({
  182. title: '请输入正确的提现金额',
  183. icon: 'none'
  184. });
  185. return;
  186. }
  187. uni.showLoading({
  188. title: '提交中...'
  189. });
  190. this.request("post", "rider/withdrawal/apply", this.token, {
  191. amount: amount
  192. }).then(res => {
  193. if (res.code === 200) {
  194. uni.showToast({
  195. title: '提现申请已提交',
  196. icon: 'success'
  197. });
  198. this.withdrawAmount = '';
  199. this.loadData(); // 刷新数据
  200. } else {
  201. uni.showToast({
  202. title: res.msg || '提现失败',
  203. icon: 'none'
  204. });
  205. }
  206. }).catch(err => {
  207. uni.showToast({
  208. title: '网络错误,请重试',
  209. icon: 'none'
  210. });
  211. }).finally(() => {
  212. uni.hideLoading();
  213. });
  214. },
  215. loadMore() {
  216. if (this.hasMore && !this.loading) {
  217. this.page++;
  218. this.getWithdrawRecords();
  219. }
  220. },
  221. viewDetail(item) {
  222. uni.navigateTo({
  223. url: `/pages/wallet/withdraw-detail?id=${item.id}`
  224. });
  225. },
  226. getStatusText(status) {
  227. const statusMap = {
  228. 0: '审核中',
  229. 1: '审核通过',
  230. 2: '审核拒绝',
  231. 3: '已打款'
  232. };
  233. return statusMap[status] || '未知状态';
  234. }
  235. }
  236. };
  237. </script>
  238. <style lang="scss" scoped>
  239. .withdraw-container {
  240. padding: 20rpx;
  241. min-height: 100vh;
  242. background-color: #f7f7f7;
  243. padding-bottom: 40rpx;
  244. }
  245. .card {
  246. background-color: #fff;
  247. border-radius: 16rpx;
  248. margin-bottom: 20rpx;
  249. overflow: hidden;
  250. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  251. .card-header {
  252. padding: 24rpx 30rpx;
  253. border-bottom: 1rpx solid #f0f0f0;
  254. .title {
  255. font-size: 32rpx;
  256. font-weight: bold;
  257. color: #333;
  258. }
  259. }
  260. }
  261. .balance-card {
  262. .balance-display {
  263. padding: 40rpx 30rpx;
  264. text-align: center;
  265. .amount {
  266. font-size: 48rpx;
  267. font-weight: bold;
  268. color: #ff6b35;
  269. }
  270. }
  271. }
  272. .withdraw-form {
  273. padding-bottom: 30rpx;
  274. .form-group {
  275. display: flex;
  276. align-items: center;
  277. padding: 30rpx;
  278. border-bottom: 1rpx solid #f0f0f0;
  279. .prefix {
  280. font-size: 48rpx;
  281. font-weight: bold;
  282. color: #333;
  283. margin-right: 20rpx;
  284. }
  285. .input {
  286. flex: 1;
  287. font-size: 48rpx;
  288. height: 60rpx;
  289. line-height: 60rpx;
  290. }
  291. .placeholder {
  292. color: #ccc;
  293. font-size: 36rpx;
  294. }
  295. }
  296. .hint {
  297. display: flex;
  298. justify-content: space-between;
  299. padding: 20rpx 30rpx;
  300. font-size: 26rpx;
  301. color: #999;
  302. .all {
  303. color: #437CE8;
  304. }
  305. }
  306. .bank-info {
  307. padding: 0 30rpx;
  308. .bank-item {
  309. display: flex;
  310. justify-content: space-between;
  311. padding: 20rpx 0;
  312. border-bottom: 1rpx solid #f0f0f0;
  313. &:last-child {
  314. border-bottom: none;
  315. }
  316. .label {
  317. font-size: 28rpx;
  318. color: #666;
  319. }
  320. .value {
  321. font-size: 28rpx;
  322. color: #333;
  323. }
  324. }
  325. }
  326. .submit-btn {
  327. margin: 40rpx 30rpx 20rpx;
  328. height: 80rpx;
  329. line-height: 80rpx;
  330. border-radius: 40rpx;
  331. background-color: #437CE8;
  332. color: #fff;
  333. font-size: 32rpx;
  334. &.disabled {
  335. opacity: 0.6;
  336. }
  337. }
  338. .tips {
  339. text-align: center;
  340. font-size: 24rpx;
  341. color: #999;
  342. padding: 0 30rpx;
  343. }
  344. }
  345. .record-list {
  346. .list {
  347. .record-item {
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: center;
  351. padding: 25rpx 30rpx;
  352. border-bottom: 1rpx solid #f0f0f0;
  353. &:last-child {
  354. border-bottom: none;
  355. }
  356. .left {
  357. .status {
  358. font-size: 30rpx;
  359. margin-bottom: 8rpx;
  360. &.pending {
  361. color: #FF9800;
  362. }
  363. &.approved {
  364. color: #4CAF50;
  365. }
  366. &.rejected {
  367. color: #F44336;
  368. }
  369. &.paid {
  370. color: #2196F3;
  371. }
  372. }
  373. .time {
  374. font-size: 24rpx;
  375. color: #999;
  376. }
  377. }
  378. .right {
  379. display: flex;
  380. align-items: center;
  381. .amount {
  382. font-size: 32rpx;
  383. font-weight: bold;
  384. color: #333;
  385. }
  386. .arrow {
  387. width: 24rpx;
  388. height: 24rpx;
  389. margin-left: 20rpx;
  390. }
  391. }
  392. }
  393. .load-more {
  394. text-align: center;
  395. padding: 25rpx 0;
  396. color: #437CE8;
  397. font-size: 28rpx;
  398. }
  399. .empty {
  400. display: flex;
  401. flex-direction: column;
  402. align-items: center;
  403. padding: 60rpx 0;
  404. .empty-icon {
  405. width: 200rpx;
  406. height: 200rpx;
  407. margin-bottom: 30rpx;
  408. opacity: 0.5;
  409. }
  410. .empty-text {
  411. font-size: 28rpx;
  412. color: #999;
  413. }
  414. }
  415. }
  416. }
  417. </style>