withdraw.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 可提现余额 -->
  4. <view class="balance-card">
  5. <text class="balance-label">可提现金额</text>
  6. <text class="balance-value" v-if="availableAmount">{{ formatPriceWithSymbol(availableAmount) }}</text>
  7. <text class="balance-value" v-else>{{ formatPriceWithSymbol(0) }}</text>
  8. <text class="balance-sub">累计佣金 {{ formatPriceWithSymbol(totalCommission) }}</text>
  9. </view>
  10. <!-- 提现规则 -->
  11. <view class="rules-card">
  12. <text class="rules-title">📋 提现规则</text>
  13. <view class="rules-list">
  14. <view class="rule-item">
  15. <text class="rule-label">可提现额度</text>
  16. <text class="rule-value">可提现金额 {{ formatPriceWithSymbol(availableAmount) }},单笔最低提现 1 元</text>
  17. </view>
  18. <view class="rule-item">
  19. <text class="rule-label">提现次数</text>
  20. <text class="rule-value">每日最多提现 1 次</text>
  21. </view>
  22. <view class="rule-item">
  23. <text class="rule-label">提现时间</text>
  24. <text class="rule-value">全天 24 小时均可申请提现</text>
  25. </view>
  26. <view class="rule-item">
  27. <text class="rule-label">到账时间</text>
  28. <text class="rule-value">提交申请后 1-3 个工作日到账,节假日顺延</text>
  29. </view>
  30. <view class="rule-item">
  31. <text class="rule-label">提现账户</text>
  32. <text class="rule-value">提现至支付宝账号,请确保账号信息准确</text>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 快捷金额 -->
  37. <view class="quick-amounts">
  38. <view class="quick-item" :class="amount === '100' ? 'quick-active' : ''" @click="amount = '100'">
  39. <text>¥100</text>
  40. </view>
  41. <view class="quick-item" :class="amount === '200' ? 'quick-active' : ''" @click="amount = '200'">
  42. <text>¥200</text>
  43. </view>
  44. <view class="quick-item" :class="amount === '500' ? 'quick-active' : ''" @click="amount = '500'">
  45. <text>¥500</text>
  46. </view>
  47. <view class="quick-item quick-all" @click="setAllAmount">
  48. <text>全部提现</text>
  49. </view>
  50. </view>
  51. <!-- 提现表单 -->
  52. <view class="form-card">
  53. <view class="form-item">
  54. <text class="form-label">提现金额</text>
  55. <view class="input-row">
  56. <input v-model="amount" type="digit" placeholder="输入提现金额" class="form-input" />
  57. <text class="unit">元</text>
  58. </view>
  59. </view>
  60. <view class="form-item">
  61. <text class="form-label">支付宝账号</text>
  62. <input v-model="accountInfo" type="text" placeholder="请输入支付宝账号" class="form-input" />
  63. </view>
  64. <view class="form-tip">最低提现金额:1元</view>
  65. <button class="submit-btn" @click="submitWithdraw">提交申请</button>
  66. </view>
  67. <!-- 提现历史 -->
  68. <view class="history-section" v-if="history.length > 0">
  69. <text class="section-title">提现记录</text>
  70. <view class="history-item" v-for="item in history" :key="item.id">
  71. <view class="history-left">
  72. <text class="history-amount">{{ formatPriceWithSymbol(item.amount) }}</text>
  73. <text class="history-time">{{ formatTime(item.createdAt) }}</text>
  74. </view>
  75. <text :class="['history-status', statusClass(item.status)]">{{ statusText(item.status) }}</text>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import { getCommissionSummary, applyWithdrawal, getWithdrawalHistory } from '../../utils/api.js'
  82. import { parseDate } from '../../utils/format.js'
  83. import fontScaleMixin from '@/mixins/font-scale.js'
  84. export default {
  85. mixins: [fontScaleMixin],
  86. data() {
  87. return {
  88. availableAmount: '0.00',
  89. totalCommission: '0.00',
  90. amount: '',
  91. accountInfo: '',
  92. history: [],
  93. historyPage: 1
  94. }
  95. },
  96. onLoad() {
  97. this.loadBalance()
  98. this.loadHistory()
  99. },
  100. methods: {
  101. async loadBalance() {
  102. try {
  103. const res = await getCommissionSummary()
  104. if (res.data) {
  105. this.availableAmount = res.data.availableAmount || '0.00'
  106. this.totalCommission = res.data.totalCommission || '0.00'
  107. }
  108. } catch (e) {
  109. console.error('获取佣金总览失败', e)
  110. }
  111. },
  112. async loadHistory() {
  113. try {
  114. const res = await getWithdrawalHistory(this.historyPage)
  115. if (res.data && res.data.records) {
  116. this.history = res.data.records
  117. }
  118. } catch (e) {
  119. console.error('获取提现记录失败', e)
  120. }
  121. },
  122. setAllAmount() {
  123. this.amount = String(parseFloat(this.availableAmount))
  124. },
  125. submitWithdraw() {
  126. var amountNum = parseFloat(this.amount)
  127. if (!this.amount || isNaN(amountNum) || amountNum < 1) {
  128. uni.showToast({ title: '提现金额不能少于1元', icon: 'none' })
  129. return
  130. }
  131. if (amountNum > parseFloat(this.availableAmount)) {
  132. uni.showToast({ title: '提现金额超过可提现余额', icon: 'none' })
  133. return
  134. }
  135. if (!this.accountInfo) {
  136. uni.showToast({ title: '请输入支付宝账号', icon: 'none' })
  137. return
  138. }
  139. uni.showModal({
  140. title: '确认提现',
  141. content: '确认提现 ¥' + amountNum.toFixed(2) + ' 元到 ' + this.accountInfo + ' ?',
  142. success: function(res) {
  143. if (res.confirm) {
  144. this.doWithdraw(amountNum)
  145. }
  146. }.bind(this)
  147. })
  148. },
  149. async doWithdraw(amountNum) {
  150. try {
  151. await applyWithdrawal(amountNum, this.accountInfo)
  152. uni.showToast({ title: '提现申请已提交', icon: 'success' })
  153. this.amount = ''
  154. this.accountInfo = ''
  155. this.loadBalance()
  156. this.loadHistory()
  157. } catch (e) {
  158. uni.showToast({ title: e.message || '提现失败', icon: 'none' })
  159. }
  160. },
  161. statusText(status) {
  162. var map = { pending: '待审核', approved: '已通过', rejected: '已拒绝' }
  163. return map[status] || status
  164. },
  165. statusClass(status) {
  166. if (status === 'approved') return 'text-success'
  167. if (status === 'rejected') return 'text-danger'
  168. return 'text-warning'
  169. },
  170. formatTime(time) {
  171. if (!time) return ''
  172. var d = parseDate(time)
  173. if (!d) return ''
  174. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  175. }
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. .container {
  181. padding: $uni-space-page;
  182. min-height: 100vh;
  183. background: $uni-primary-pale;
  184. }
  185. .balance-card {
  186. background: linear-gradient(135deg, $brand-primary, $brand-primary-dark);
  187. border-radius: 24rpx;
  188. padding: 40rpx;
  189. text-align: center;
  190. color: $app-surface;
  191. margin-bottom: 24rpx;
  192. }
  193. .balance-label {
  194. font-size: calc(26rpx * var(--font-scale, 1));
  195. opacity: 0.9;
  196. }
  197. .balance-value {
  198. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  199. font-weight: bold;
  200. margin-top: 12rpx;
  201. }
  202. .balance-sub {
  203. font-size: calc(22rpx * var(--font-scale, 1));
  204. opacity: 0.7;
  205. margin-top: 8rpx;
  206. display: block;
  207. }
  208. /* ===== 提现规则 ===== */
  209. .rules-card {
  210. background: $app-surface;
  211. border-radius: 24rpx;
  212. padding: $uni-space-lg;
  213. margin-bottom: 24rpx;
  214. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  215. }
  216. .rules-title {
  217. font-size: calc(28rpx * var(--font-scale, 1));
  218. font-weight: bold;
  219. color: $uni-text-color;
  220. display: block;
  221. margin-bottom: 20rpx;
  222. }
  223. .rules-list {
  224. display: flex;
  225. flex-direction: column;
  226. gap: 16rpx;
  227. }
  228. .rule-item {
  229. display: flex;
  230. align-items: flex-start;
  231. }
  232. .rule-label {
  233. width: 140rpx;
  234. font-size: calc(24rpx * var(--font-scale, 1));
  235. color: $app-text-subtle;
  236. flex-shrink: 0;
  237. }
  238. .rule-value {
  239. flex: 1;
  240. font-size: calc(24rpx * var(--font-scale, 1));
  241. color: $uni-text-color;
  242. line-height: 1.5;
  243. }
  244. /* ===== 快捷金额 ===== */
  245. .quick-amounts {
  246. display: flex;
  247. gap: 16rpx;
  248. margin-bottom: 24rpx;
  249. }
  250. .quick-item {
  251. flex: 1;
  252. height: 72rpx;
  253. line-height: 72rpx;
  254. text-align: center;
  255. background: $app-surface;
  256. border: 1rpx solid $brand-primary-light-2;
  257. border-radius: 16rpx;
  258. font-size: calc(26rpx * var(--font-scale, 1));
  259. color: $brand-primary;
  260. font-weight: 500;
  261. }
  262. .quick-item:active {
  263. opacity: 0.8;
  264. }
  265. .quick-active {
  266. background: $brand-primary;
  267. border-color: $brand-primary;
  268. color: $app-surface;
  269. }
  270. .quick-all {
  271. color: $uni-text-color-secondary;
  272. border-color: $uni-border-color;
  273. font-size: calc(22rpx * var(--font-scale, 1));
  274. }
  275. .form-card {
  276. background: $app-surface;
  277. border-radius: 24rpx;
  278. padding: 40rpx;
  279. margin-bottom: $uni-space-lg;
  280. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  281. }
  282. .form-item {
  283. margin-bottom: $uni-space-lg;
  284. }
  285. .form-label {
  286. font-size: calc(28rpx * var(--font-scale, 1));
  287. color: $uni-text-color;
  288. display: block;
  289. margin-bottom: 16rpx;
  290. font-weight: 500;
  291. }
  292. .input-row {
  293. display: flex;
  294. align-items: center;
  295. border: 1rpx solid $uni-border-color;
  296. border-radius: 16rpx;
  297. padding: 20rpx;
  298. }
  299. .form-input {
  300. flex: 1;
  301. font-size: calc(28rpx * var(--font-scale, 1));
  302. }
  303. .unit {
  304. font-size: calc(28rpx * var(--font-scale, 1));
  305. color: $app-text-subtle;
  306. margin: 0 16rpx;
  307. }
  308. .form-tip {
  309. font-size: calc(22rpx * var(--font-scale, 1));
  310. color: $app-text-subtle;
  311. margin-bottom: 24rpx;
  312. }
  313. .submit-btn {
  314. background: linear-gradient(135deg, $brand-primary, $brand-primary-dark);
  315. color: $app-surface;
  316. font-size: calc(30rpx * var(--font-scale, 1));
  317. border-radius: 24rpx;
  318. height: 80rpx;
  319. line-height: 80rpx;
  320. font-weight: 600;
  321. border: none;
  322. }
  323. .submit-btn::after { border: none; }
  324. .submit-btn:active { opacity: 0.9; }
  325. .history-section {
  326. background: $app-surface;
  327. border-radius: 24rpx;
  328. padding: $uni-space-lg;
  329. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  330. }
  331. .section-title {
  332. font-size: calc(28rpx * var(--font-scale, 1));
  333. font-weight: bold;
  334. color: $uni-text-color;
  335. display: block;
  336. margin-bottom: 20rpx;
  337. }
  338. .history-item {
  339. display: flex;
  340. justify-content: space-between;
  341. align-items: center;
  342. padding: 20rpx 0;
  343. border-bottom: 1rpx solid $brand-primary-light-2;
  344. }
  345. .history-item:last-child { border-bottom: none; }
  346. .history-left {
  347. flex: 1;
  348. }
  349. .history-amount {
  350. font-size: calc(28rpx * var(--font-scale, 1));
  351. font-weight: bold;
  352. display: block;
  353. color: $uni-text-color;
  354. }
  355. .history-time {
  356. font-size: calc(22rpx * var(--font-scale, 1));
  357. color: $app-text-subtle;
  358. margin-top: 4rpx;
  359. }
  360. .history-status {
  361. font-size: calc(24rpx * var(--font-scale, 1));
  362. }
  363. .text-success { color: $status-success; }
  364. .text-warning { color: $status-warning-deep; }
  365. .text-danger { color: $status-danger; }
  366. </style>