withdraw.vue 7.7 KB

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