index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="page-withdraw">
  3. <!-- Balance card -->
  4. <view class="balance-card">
  5. <text class="balance-label">可提现余额</text>
  6. <text class="balance-amount">¥{{ formatMoney(balance) }}</text>
  7. </view>
  8. <!-- Amount input -->
  9. <view class="input-section">
  10. <text class="input-label">提现金额</text>
  11. <view class="input-row">
  12. <text class="input-prefix">¥</text>
  13. <input
  14. class="amount-input"
  15. type="digit"
  16. v-model="amount"
  17. placeholder="输入提现金额"
  18. @input="validateAmount"
  19. />
  20. </view>
  21. <view class="amount-hints">
  22. <text class="hint">最低提现 ¥100</text>
  23. <text class="hint-link" @click="setAll">全部提现</text>
  24. </view>
  25. <text v-if="error" class="error-text">{{ error }}</text>
  26. </view>
  27. <!-- Rules -->
  28. <view class="rules-card">
  29. <text class="rules-title">提现规则</text>
  30. <text class="rule">• 最低提现金额 ¥100</text>
  31. <text class="rule">• 提现申请提交后由平台审核处理</text>
  32. <text class="rule">• 审核通过后佣金将自动扣除</text>
  33. </view>
  34. <!-- Submit -->
  35. <button class="submit-btn" @click="handleApply" :disabled="submitting || !amountValid">
  36. {{ submitting ? '提交中...' : '提交提现申请' }}
  37. </button>
  38. </view>
  39. </template>
  40. <script setup>
  41. import { ref, computed, onMounted } from 'vue'
  42. import { withdrawApi } from '@/utils/api'
  43. const balance = ref(0)
  44. const amount = ref('')
  45. const error = ref('')
  46. const submitting = ref(false)
  47. const amountNum = computed(() => parseInt(amount.value) || 0)
  48. const amountValid = computed(() => amountNum.value >= 100 && amountNum.value <= balance.value)
  49. onMounted(async () => {
  50. try {
  51. const res = await withdrawApi.balance()
  52. balance.value = res.balance || 0
  53. } catch (e) {
  54. // silent
  55. }
  56. })
  57. function validateAmount() {
  58. const num = parseInt(amount.value) || 0
  59. if (amount.value && num < 100) {
  60. error.value = '最低提现金额为 ¥100'
  61. } else if (num > balance.value) {
  62. error.value = `超出可提现余额 ¥${formatMoney(balance.value)}`
  63. } else {
  64. error.value = ''
  65. }
  66. }
  67. function setAll() {
  68. amount.value = String(Math.floor(balance.value / 100) * 100)
  69. validateAmount()
  70. }
  71. async function handleApply() {
  72. if (!amountValid.value) return
  73. submitting.value = true
  74. try {
  75. await withdrawApi.apply(amountNum.value)
  76. uni.showToast({ title: '提现申请已提交', icon: 'success' })
  77. setTimeout(() => uni.navigateBack(), 1500)
  78. } catch (e) {
  79. uni.showToast({ title: e.message || '提交失败', icon: 'none' })
  80. }
  81. submitting.value = false
  82. }
  83. function formatMoney(cents) {
  84. if (cents == null) return '0.00'
  85. return (cents / 100).toFixed(2)
  86. }
  87. </script>
  88. <style scoped lang="scss">
  89. @import "@/styles/theme.scss";
  90. .page-withdraw {
  91. min-height: 100vh;
  92. background: var(--color-bg);
  93. padding: 16px;
  94. }
  95. .balance-card {
  96. background: linear-gradient(135deg, var(--color-brand), #2D4A7A);
  97. border-radius: 14px;
  98. padding: 28px 20px;
  99. text-align: center;
  100. margin-bottom: 16px;
  101. }
  102. .balance-label {
  103. font-size: 13px;
  104. color: rgba(255,255,255,0.6);
  105. display: block;
  106. }
  107. .balance-amount {
  108. font-size: 40px;
  109. font-weight: 700;
  110. color: var(--color-gold);
  111. display: block;
  112. margin-top: 6px;
  113. }
  114. .input-section {
  115. background: #fff;
  116. border-radius: 14px;
  117. padding: 20px;
  118. margin-bottom: 16px;
  119. }
  120. .input-label {
  121. font-size: 14px;
  122. font-weight: 600;
  123. color: var(--color-text-primary);
  124. display: block;
  125. margin-bottom: 12px;
  126. }
  127. .input-row {
  128. display: flex;
  129. align-items: center;
  130. border: 1px solid var(--color-border);
  131. border-radius: 10px;
  132. padding: 0 14px;
  133. height: 48px;
  134. }
  135. .input-prefix {
  136. font-size: 20px;
  137. font-weight: 700;
  138. color: var(--color-brand);
  139. margin-right: 6px;
  140. }
  141. .amount-input {
  142. flex: 1;
  143. height: 100%;
  144. font-size: 22px;
  145. font-weight: 600;
  146. color: var(--color-text-primary);
  147. }
  148. .amount-hints {
  149. display: flex;
  150. justify-content: space-between;
  151. margin-top: 8px;
  152. }
  153. .hint {
  154. font-size: 12px;
  155. color: var(--color-text-secondary);
  156. }
  157. .hint-link {
  158. font-size: 12px;
  159. color: #3B82F6;
  160. font-weight: 500;
  161. }
  162. .error-text {
  163. display: block;
  164. font-size: 12px;
  165. color: #EF4444;
  166. margin-top: 8px;
  167. }
  168. .rules-card {
  169. background: #fff;
  170. border-radius: 14px;
  171. padding: 16px 20px;
  172. margin-bottom: 24px;
  173. }
  174. .rules-title {
  175. font-size: 13px;
  176. font-weight: 600;
  177. color: var(--color-text-primary);
  178. display: block;
  179. margin-bottom: 8px;
  180. }
  181. .rule {
  182. font-size: 12px;
  183. color: var(--color-text-secondary);
  184. display: block;
  185. padding: 3px 0;
  186. line-height: 1.5;
  187. }
  188. .submit-btn {
  189. width: 100%;
  190. height: 48px;
  191. background: linear-gradient(135deg, #f59e0b, #d97706);
  192. border: none;
  193. border-radius: 14px;
  194. color: #fff;
  195. font-size: 17px;
  196. font-weight: 600;
  197. line-height: 48px;
  198. letter-spacing: 1px;
  199. }
  200. .submit-btn[disabled] {
  201. opacity: 0.4;
  202. }
  203. </style>