index.vue 5.0 KB

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