withdraw.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container">
  3. <!-- 可提现余额 -->
  4. <view class="balance-card">
  5. <text class="balance-label">可提现金额</text>
  6. <text class="balance-value">¥{{ availableAmount || '0.00' }}</text>
  7. </view>
  8. <!-- 提现表单 -->
  9. <view class="form-card">
  10. <view class="form-item">
  11. <text class="form-label">提现金额</text>
  12. <view class="input-row">
  13. <input v-model="amount" type="digit" placeholder="输入提现金额" class="form-input" />
  14. <text class="unit">元</text>
  15. <text class="btn-all" @click="amount = availableAmount">全部提现</text>
  16. </view>
  17. </view>
  18. <view class="form-item">
  19. <text class="form-label">支付宝账号</text>
  20. <input v-model="accountInfo" type="text" placeholder="请输入支付宝账号" class="form-input" />
  21. </view>
  22. <view class="form-tip">最低提现金额:1元</view>
  23. <button class="submit-btn" @click="submitWithdraw">提交申请</button>
  24. </view>
  25. <!-- 提现历史 -->
  26. <view class="history-section" v-if="history.length > 0">
  27. <text class="section-title">提现记录</text>
  28. <view class="history-item" v-for="item in history" :key="item.id">
  29. <view class="history-left">
  30. <text class="history-amount">¥{{ item.amount }}</text>
  31. <text class="history-time">{{ formatTime(item.createdAt) }}</text>
  32. </view>
  33. <text :class="['history-status', statusClass(item.status)]">{{ statusText(item.status) }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { getCommissionSummary, applyWithdrawal, getWithdrawalHistory } from '../../utils/api.js'
  40. export default {
  41. data() {
  42. return {
  43. availableAmount: '0.00',
  44. amount: '',
  45. accountInfo: '',
  46. history: [],
  47. historyPage: 1
  48. }
  49. },
  50. onLoad() {
  51. this.loadBalance()
  52. this.loadHistory()
  53. },
  54. methods: {
  55. async loadBalance() {
  56. try {
  57. const res = await getCommissionSummary()
  58. if (res.data) {
  59. this.availableAmount = res.data.availableAmount || '0.00'
  60. }
  61. } catch (e) {
  62. console.error('获取佣金总览失败', e)
  63. }
  64. },
  65. async loadHistory() {
  66. try {
  67. const res = await getWithdrawalHistory(this.historyPage)
  68. if (res.data && res.data.records) {
  69. this.history = res.data.records
  70. }
  71. } catch (e) {
  72. console.error('获取提现记录失败', e)
  73. }
  74. },
  75. submitWithdraw() {
  76. const amountNum = parseFloat(this.amount)
  77. if (!this.amount || isNaN(amountNum) || amountNum < 1) {
  78. uni.showToast({ title: '提现金额不能少于1元', icon: 'none' })
  79. return
  80. }
  81. if (amountNum > parseFloat(this.availableAmount)) {
  82. uni.showToast({ title: '提现金额超过可提现余额', icon: 'none' })
  83. return
  84. }
  85. if (!this.accountInfo) {
  86. uni.showToast({ title: '请输入支付宝账号', icon: 'none' })
  87. return
  88. }
  89. uni.showModal({
  90. title: '确认提现',
  91. content: '确认提现 ¥' + amountNum.toFixed(2) + ' 到 ' + this.accountInfo + ' ?',
  92. success: async (res) => {
  93. if (res.confirm) {
  94. try {
  95. await applyWithdrawal(amountNum, this.accountInfo)
  96. uni.showToast({ title: '提现申请已提交', icon: 'success' })
  97. this.amount = ''
  98. this.accountInfo = ''
  99. this.loadBalance()
  100. this.loadHistory()
  101. } catch (e) {
  102. uni.showToast({ title: e.message || '提现失败', icon: 'none' })
  103. }
  104. }
  105. }
  106. })
  107. },
  108. statusText(status) {
  109. const map = { pending: '待审核', approved: '已通过', rejected: '已拒绝' }
  110. return map[status] || status
  111. },
  112. statusClass(status) {
  113. if (status === 'approved') return 'text-success'
  114. if (status === 'rejected') return 'text-danger'
  115. return 'text-warning'
  116. },
  117. formatTime(time) {
  118. if (!time) return ''
  119. const t = new Date(time)
  120. return t.getFullYear() + '-' + String(t.getMonth()+1).padStart(2,'0') + '-' + String(t.getDate()).padStart(2,'0')
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped>
  126. .container {
  127. padding: 30rpx;
  128. min-height: 100vh;
  129. background: #f5f7fa;
  130. }
  131. .balance-card {
  132. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  133. border-radius: 20rpx;
  134. padding: 40rpx;
  135. text-align: center;
  136. color: #fff;
  137. margin-bottom: 30rpx;
  138. }
  139. .balance-label {
  140. font-size: 26rpx;
  141. opacity: 0.9;
  142. }
  143. .balance-value {
  144. font-size: 56rpx;
  145. font-weight: bold;
  146. margin-top: 12rpx;
  147. }
  148. .form-card {
  149. background: #fff;
  150. border-radius: 20rpx;
  151. padding: 40rpx;
  152. margin-bottom: 30rpx;
  153. }
  154. .form-item {
  155. margin-bottom: 30rpx;
  156. }
  157. .form-label {
  158. font-size: 28rpx;
  159. color: #333;
  160. display: block;
  161. margin-bottom: 16rpx;
  162. }
  163. .input-row {
  164. display: flex;
  165. align-items: center;
  166. border: 1rpx solid #ddd;
  167. border-radius: 10rpx;
  168. padding: 20rpx;
  169. }
  170. .form-input {
  171. flex: 1;
  172. font-size: 28rpx;
  173. }
  174. .unit {
  175. font-size: 28rpx;
  176. color: #999;
  177. margin: 0 16rpx;
  178. }
  179. .btn-all {
  180. font-size: 24rpx;
  181. color: #3A7CC4;
  182. padding: 6rpx 12rpx;
  183. border: 1rpx solid #3A7CC4;
  184. border-radius: 6rpx;
  185. }
  186. .form-tip {
  187. font-size: 24rpx;
  188. color: #999;
  189. margin-bottom: 30rpx;
  190. }
  191. .submit-btn {
  192. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  193. color: #fff;
  194. font-size: 30rpx;
  195. border-radius: 40rpx;
  196. height: 80rpx;
  197. line-height: 80rpx;
  198. }
  199. .submit-btn::after { border: none; }
  200. .history-section {
  201. background: #fff;
  202. border-radius: 20rpx;
  203. padding: 30rpx;
  204. }
  205. .section-title {
  206. font-size: 28rpx;
  207. font-weight: bold;
  208. color: #333;
  209. display: block;
  210. margin-bottom: 20rpx;
  211. }
  212. .history-item {
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. padding: 20rpx 0;
  217. border-bottom: 1rpx solid #f0f0f0;
  218. }
  219. .history-item:last-child { border-bottom: none; }
  220. .history-left {
  221. flex: 1;
  222. }
  223. .history-amount {
  224. font-size: 28rpx;
  225. font-weight: bold;
  226. display: block;
  227. }
  228. .history-time {
  229. font-size: 22rpx;
  230. color: #999;
  231. margin-top: 4rpx;
  232. }
  233. .history-status {
  234. font-size: 24rpx;
  235. }
  236. .text-success { color: #52c41a; }
  237. .text-warning { color: #faad14; }
  238. .text-danger { color: #ff4d4f; }
  239. </style>