withdrawal.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view class="page">
  3. <NavBar title="申请提现" :showBack="true" />
  4. <view class="content">
  5. <!-- 当前余额 -->
  6. <view class="balance-card" v-if="myStats">
  7. <text class="balance-label">可提现余额</text>
  8. <view class="balance-amount">
  9. <text class="amount-symbol">¥</text>
  10. <text class="amount-value">{{ myStats.commissionBalance.toFixed(2) }}</text>
  11. </view>
  12. <view class="balance-detail">
  13. <text class="detail-item">冻结金额:¥{{ myStats.frozenAmount.toFixed(2) }}</text>
  14. </view>
  15. </view>
  16. <!-- 提现金额输入 -->
  17. <view class="input-section">
  18. <text class="input-label">提现金额</text>
  19. <view class="input-wrapper">
  20. <text class="input-prefix">¥</text>
  21. <input
  22. class="amount-input"
  23. type="digit"
  24. v-model="withdrawalAmount"
  25. placeholder="请输入提现金额"
  26. :maxlength="10"
  27. />
  28. </view>
  29. <view class="input-actions">
  30. <text class="action-link" @click="fillAll">全部提现</text>
  31. </view>
  32. </view>
  33. <!-- 提现说明 -->
  34. <view class="tips-section">
  35. <text class="tips-title">提现说明</text>
  36. <view class="tip-item">
  37. <text class="tip-dot"></text>
  38. <text class="tip-text">提现金额最低 10 元</text>
  39. </view>
  40. <view class="tip-item">
  41. <text class="tip-dot"></text>
  42. <text class="tip-text">提现申请提交后,将在1-3个工作日内审核</text>
  43. </view>
  44. <view class="tip-item">
  45. <text class="tip-dot"></text>
  46. <text class="tip-text">审核通过后,款项将打入您的绑定账户</text>
  47. </view>
  48. </view>
  49. <!-- 提交按钮 -->
  50. <button class="btn-submit" @click="handleSubmit" :disabled="isSubmitting">
  51. {{ isSubmitting ? '提交中...' : '确认提现' }}
  52. </button>
  53. </view>
  54. </view>
  55. </template>
  56. <script setup lang="ts">
  57. import { ref, onMounted } from 'vue';
  58. import { logger } from '@/utils/logger';
  59. import NavBar from '@/components/NavBar.vue';
  60. import { getMyStats, applyWithdrawal } from '@/api/distribution';
  61. import type { DistributionStats } from '@/api/distribution';
  62. const myStats = ref<DistributionStats | null>(null);
  63. const withdrawalAmount = ref('');
  64. const isSubmitting = ref(false);
  65. onMounted(() => {
  66. loadStats();
  67. });
  68. const loadStats = async () => {
  69. try {
  70. myStats.value = await getMyStats();
  71. } catch (error) {
  72. logger.warn('加载分销统计失败', error);
  73. }
  74. };
  75. const fillAll = () => {
  76. if (myStats.value) {
  77. withdrawalAmount.value = myStats.value.commissionBalance.toFixed(2);
  78. }
  79. };
  80. const handleSubmit = async () => {
  81. const amount = parseFloat(withdrawalAmount.value);
  82. if (!withdrawalAmount.value || isNaN(amount)) {
  83. uni.showToast({ title: '请输入提现金额', icon: 'none' });
  84. return;
  85. }
  86. if (amount < 10) {
  87. uni.showToast({ title: '提现金额最低10元', icon: 'none' });
  88. return;
  89. }
  90. if (myStats.value && amount > myStats.value.commissionBalance) {
  91. uni.showToast({ title: '提现金额不能超过可提现余额', icon: 'none' });
  92. return;
  93. }
  94. isSubmitting.value = true;
  95. try {
  96. const result = await applyWithdrawal(amount);
  97. if (result.success) {
  98. uni.showToast({ title: '提现申请已提交', icon: 'success' });
  99. setTimeout(() => {
  100. uni.navigateBack();
  101. }, 1500);
  102. } else {
  103. uni.showToast({ title: result.message || '提现申请失败', icon: 'none' });
  104. }
  105. } catch (error) {
  106. logger.warn('提现申请失败', error);
  107. uni.showToast({ title: '提现申请失败,请重试', icon: 'none' });
  108. } finally {
  109. isSubmitting.value = false;
  110. }
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .page {
  115. min-height: 100vh;
  116. background: $bg-color-page;
  117. }
  118. .content {
  119. padding: 24rpx;
  120. padding-top: 0;
  121. }
  122. .balance-card {
  123. background: linear-gradient(135deg, $primary-color 0%, $primary-color-dark 100%);
  124. border-radius: 20rpx;
  125. padding: 36rpx;
  126. margin-bottom: 24rpx;
  127. color: $bg-color-card;
  128. }
  129. .balance-label {
  130. font-size: 26rpx;
  131. color: rgba(255, 255, 255, 0.8);
  132. display: block;
  133. margin-bottom: 12rpx;
  134. }
  135. .balance-amount {
  136. display: flex;
  137. align-items: baseline;
  138. margin-bottom: 16rpx;
  139. }
  140. .amount-symbol {
  141. font-size: 32rpx;
  142. font-weight: 600;
  143. color: $bg-color-card;
  144. margin-right: 4rpx;
  145. }
  146. .amount-value {
  147. font-size: 64rpx;
  148. font-weight: 700;
  149. color: $bg-color-card;
  150. }
  151. .balance-detail {
  152. padding-top: 16rpx;
  153. border-top: 1rpx solid rgba(255, 255, 255, 0.2);
  154. }
  155. .detail-item {
  156. font-size: 24rpx;
  157. color: rgba(255, 255, 255, 0.7);
  158. }
  159. .input-section {
  160. background: $bg-color-card;
  161. border-radius: 20rpx;
  162. padding: 28rpx;
  163. margin-bottom: 24rpx;
  164. border: 1rpx solid $border-color;
  165. }
  166. .input-label {
  167. font-size: 28rpx;
  168. font-weight: 600;
  169. color: $text-color-primary;
  170. display: block;
  171. margin-bottom: 20rpx;
  172. }
  173. .input-wrapper {
  174. display: flex;
  175. align-items: center;
  176. padding: 20rpx 24rpx;
  177. background: $bg-color-page;
  178. border-radius: 12rpx;
  179. border: 2rpx solid $border-color;
  180. }
  181. .input-prefix {
  182. font-size: 40rpx;
  183. font-weight: 700;
  184. color: $text-color-primary;
  185. margin-right: 12rpx;
  186. }
  187. .amount-input {
  188. flex: 1;
  189. font-size: 40rpx;
  190. font-weight: 600;
  191. color: $text-color-primary;
  192. height: 56rpx;
  193. }
  194. .input-actions {
  195. display: flex;
  196. justify-content: flex-end;
  197. margin-top: 16rpx;
  198. }
  199. .action-link {
  200. font-size: 26rpx;
  201. color: $info-color;
  202. font-weight: 500;
  203. }
  204. .tips-section {
  205. background: $bg-color-card;
  206. border-radius: 20rpx;
  207. padding: 28rpx;
  208. margin-bottom: 40rpx;
  209. border: 1rpx solid $border-color;
  210. }
  211. .tips-title {
  212. font-size: 28rpx;
  213. font-weight: 600;
  214. color: $text-color-primary;
  215. display: block;
  216. margin-bottom: 16rpx;
  217. }
  218. .tip-item {
  219. display: flex;
  220. align-items: flex-start;
  221. margin-bottom: 12rpx;
  222. &:last-child {
  223. margin-bottom: 0;
  224. }
  225. }
  226. .tip-dot {
  227. width: 10rpx;
  228. height: 10rpx;
  229. background: $text-color-muted;
  230. border-radius: 50%;
  231. margin-right: 12rpx;
  232. margin-top: 12rpx;
  233. flex-shrink: 0;
  234. }
  235. .tip-text {
  236. font-size: 24rpx;
  237. color: $text-color-tertiary;
  238. line-height: 36rpx;
  239. }
  240. .btn-submit {
  241. width: 100%;
  242. height: 96rpx;
  243. line-height: 96rpx;
  244. padding: 0;
  245. background: linear-gradient(135deg, $primary-color 0%, $primary-color-dark 100%);
  246. border-radius: 48rpx;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. font-size: 32rpx;
  251. font-weight: 600;
  252. color: $bg-color-card;
  253. border: none;
  254. &[disabled] {
  255. background: $text-color-placeholder;
  256. color: $text-color-muted;
  257. }
  258. &:active:not([disabled]) {
  259. opacity: 0.9;
  260. }
  261. }
  262. </style>