index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. .page-withdraw {
  90. min-height: 100vh;
  91. background: #F8F6F1;
  92. padding: 16px;
  93. }
  94. .balance-card {
  95. background: linear-gradient(135deg, #1E3A5F, #2D4A7A);
  96. border-radius: 14px;
  97. padding: 28px 20px;
  98. text-align: center;
  99. margin-bottom: 16px;
  100. }
  101. .balance-label {
  102. font-size: 13px;
  103. color: rgba(255,255,255,0.6);
  104. display: block;
  105. }
  106. .balance-amount {
  107. font-size: 40px;
  108. font-weight: 700;
  109. color: #C9A84C;
  110. display: block;
  111. margin-top: 6px;
  112. }
  113. .input-section {
  114. background: #fff;
  115. border-radius: 14px;
  116. padding: 20px;
  117. margin-bottom: 16px;
  118. }
  119. .input-label {
  120. font-size: 14px;
  121. font-weight: 600;
  122. color: #1A1A2E;
  123. display: block;
  124. margin-bottom: 12px;
  125. }
  126. .input-row {
  127. display: flex;
  128. align-items: center;
  129. border: 1px solid #E2E8F0;
  130. border-radius: 10px;
  131. padding: 0 14px;
  132. height: 48px;
  133. }
  134. .input-prefix {
  135. font-size: 20px;
  136. font-weight: 700;
  137. color: #1E3A5F;
  138. margin-right: 6px;
  139. }
  140. .amount-input {
  141. flex: 1;
  142. height: 100%;
  143. font-size: 22px;
  144. font-weight: 600;
  145. color: #1A1A2E;
  146. }
  147. .amount-hints {
  148. display: flex;
  149. justify-content: space-between;
  150. margin-top: 8px;
  151. }
  152. .hint {
  153. font-size: 12px;
  154. color: #A0AEC0;
  155. }
  156. .hint-link {
  157. font-size: 12px;
  158. color: #3B82F6;
  159. font-weight: 500;
  160. }
  161. .error-text {
  162. display: block;
  163. font-size: 12px;
  164. color: #EF4444;
  165. margin-top: 8px;
  166. }
  167. .rules-card {
  168. background: #fff;
  169. border-radius: 14px;
  170. padding: 16px 20px;
  171. margin-bottom: 24px;
  172. }
  173. .rules-title {
  174. font-size: 13px;
  175. font-weight: 600;
  176. color: #1A1A2E;
  177. display: block;
  178. margin-bottom: 8px;
  179. }
  180. .rule {
  181. font-size: 12px;
  182. color: #A0AEC0;
  183. display: block;
  184. padding: 3px 0;
  185. line-height: 1.5;
  186. }
  187. .submit-btn {
  188. width: 100%;
  189. height: 48px;
  190. background: linear-gradient(135deg, #f59e0b, #d97706);
  191. border: none;
  192. border-radius: 14px;
  193. color: #fff;
  194. font-size: 17px;
  195. font-weight: 600;
  196. line-height: 48px;
  197. letter-spacing: 1px;
  198. }
  199. .submit-btn[disabled] {
  200. opacity: 0.4;
  201. }
  202. </style>