withdraw.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="container">
  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. export default {
  83. data() {
  84. return {
  85. availableAmount: '0.00',
  86. totalCommission: '0.00',
  87. amount: '',
  88. accountInfo: '',
  89. history: [],
  90. historyPage: 1
  91. }
  92. },
  93. onLoad() {
  94. this.loadBalance()
  95. this.loadHistory()
  96. },
  97. methods: {
  98. async loadBalance() {
  99. try {
  100. const res = await getCommissionSummary()
  101. if (res.data) {
  102. this.availableAmount = res.data.availableAmount || '0.00'
  103. this.totalCommission = res.data.totalCommission || '0.00'
  104. }
  105. } catch (e) {
  106. console.error('获取佣金总览失败', e)
  107. }
  108. },
  109. async loadHistory() {
  110. try {
  111. const res = await getWithdrawalHistory(this.historyPage)
  112. if (res.data && res.data.records) {
  113. this.history = res.data.records
  114. }
  115. } catch (e) {
  116. console.error('获取提现记录失败', e)
  117. }
  118. },
  119. setAllAmount() {
  120. this.amount = String(parseFloat(this.availableAmount))
  121. },
  122. submitWithdraw() {
  123. var amountNum = parseFloat(this.amount)
  124. if (!this.amount || isNaN(amountNum) || amountNum < 1) {
  125. uni.showToast({ title: '提现金额不能少于1元', icon: 'none' })
  126. return
  127. }
  128. if (amountNum > parseFloat(this.availableAmount)) {
  129. uni.showToast({ title: '提现金额超过可提现余额', icon: 'none' })
  130. return
  131. }
  132. if (!this.accountInfo) {
  133. uni.showToast({ title: '请输入支付宝账号', icon: 'none' })
  134. return
  135. }
  136. uni.showModal({
  137. title: '确认提现',
  138. content: '确认提现 ¥' + amountNum.toFixed(2) + ' 元到 ' + this.accountInfo + ' ?',
  139. success: function(res) {
  140. if (res.confirm) {
  141. this.doWithdraw(amountNum)
  142. }
  143. }.bind(this)
  144. })
  145. },
  146. async doWithdraw(amountNum) {
  147. try {
  148. await applyWithdrawal(amountNum, this.accountInfo)
  149. uni.showToast({ title: '提现申请已提交', icon: 'success' })
  150. this.amount = ''
  151. this.accountInfo = ''
  152. this.loadBalance()
  153. this.loadHistory()
  154. } catch (e) {
  155. uni.showToast({ title: e.message || '提现失败', icon: 'none' })
  156. }
  157. },
  158. statusText(status) {
  159. var map = { pending: '待审核', approved: '已通过', rejected: '已拒绝' }
  160. return map[status] || status
  161. },
  162. statusClass(status) {
  163. if (status === 'approved') return 'text-success'
  164. if (status === 'rejected') return 'text-danger'
  165. return 'text-warning'
  166. },
  167. formatTime(time) {
  168. if (!time) return ''
  169. var t = new Date(time)
  170. return t.getFullYear() + '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + String(t.getDate()).padStart(2, '0')
  171. }
  172. }
  173. }
  174. </script>
  175. <style scoped>
  176. .container {
  177. padding: 30rpx;
  178. min-height: 100vh;
  179. background: #FFF7ED;
  180. }
  181. .balance-card {
  182. background: linear-gradient(135deg, #F97316, #EA580C);
  183. border-radius: 20rpx;
  184. padding: 40rpx;
  185. text-align: center;
  186. color: #fff;
  187. margin-bottom: 24rpx;
  188. }
  189. .balance-label {
  190. font-size: 26rpx;
  191. opacity: 0.9;
  192. }
  193. .balance-value {
  194. font-size: 60rpx;
  195. font-weight: bold;
  196. margin-top: 12rpx;
  197. }
  198. .balance-sub {
  199. font-size: 22rpx;
  200. opacity: 0.7;
  201. margin-top: 8rpx;
  202. display: block;
  203. }
  204. /* ===== 提现规则 ===== */
  205. .rules-card {
  206. background: #fff;
  207. border-radius: 20rpx;
  208. padding: 30rpx;
  209. margin-bottom: 24rpx;
  210. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  211. }
  212. .rules-title {
  213. font-size: 28rpx;
  214. font-weight: bold;
  215. color: #1E293B;
  216. display: block;
  217. margin-bottom: 20rpx;
  218. }
  219. .rules-list {
  220. display: flex;
  221. flex-direction: column;
  222. gap: 16rpx;
  223. }
  224. .rule-item {
  225. display: flex;
  226. align-items: flex-start;
  227. }
  228. .rule-label {
  229. width: 140rpx;
  230. font-size: 24rpx;
  231. color: #94A3B8;
  232. flex-shrink: 0;
  233. }
  234. .rule-value {
  235. flex: 1;
  236. font-size: 24rpx;
  237. color: #1E293B;
  238. line-height: 1.5;
  239. }
  240. /* ===== 快捷金额 ===== */
  241. .quick-amounts {
  242. display: flex;
  243. gap: 16rpx;
  244. margin-bottom: 24rpx;
  245. }
  246. .quick-item {
  247. flex: 1;
  248. height: 72rpx;
  249. line-height: 72rpx;
  250. text-align: center;
  251. background: #fff;
  252. border: 1rpx solid #FED7AA;
  253. border-radius: 12rpx;
  254. font-size: 26rpx;
  255. color: #F97316;
  256. font-weight: 500;
  257. }
  258. .quick-item:active {
  259. opacity: 0.8;
  260. }
  261. .quick-active {
  262. background: #F97316;
  263. border-color: #F97316;
  264. color: #fff;
  265. }
  266. .quick-all {
  267. color: #64748B;
  268. border-color: #CBD5E1;
  269. font-size: 22rpx;
  270. }
  271. .form-card {
  272. background: #fff;
  273. border-radius: 20rpx;
  274. padding: 40rpx;
  275. margin-bottom: 30rpx;
  276. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  277. }
  278. .form-item {
  279. margin-bottom: 30rpx;
  280. }
  281. .form-label {
  282. font-size: 28rpx;
  283. color: #1E293B;
  284. display: block;
  285. margin-bottom: 16rpx;
  286. font-weight: 500;
  287. }
  288. .input-row {
  289. display: flex;
  290. align-items: center;
  291. border: 1rpx solid #CBD5E1;
  292. border-radius: 12rpx;
  293. padding: 20rpx;
  294. }
  295. .form-input {
  296. flex: 1;
  297. font-size: 28rpx;
  298. }
  299. .unit {
  300. font-size: 28rpx;
  301. color: #94A3B8;
  302. margin: 0 16rpx;
  303. }
  304. .form-tip {
  305. font-size: 22rpx;
  306. color: #94A3B8;
  307. margin-bottom: 24rpx;
  308. }
  309. .submit-btn {
  310. background: linear-gradient(135deg, #F97316, #EA580C);
  311. color: #fff;
  312. font-size: 30rpx;
  313. border-radius: 40rpx;
  314. height: 80rpx;
  315. line-height: 80rpx;
  316. font-weight: 600;
  317. border: none;
  318. }
  319. .submit-btn::after { border: none; }
  320. .submit-btn:active { opacity: 0.9; }
  321. .history-section {
  322. background: #fff;
  323. border-radius: 20rpx;
  324. padding: 30rpx;
  325. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  326. }
  327. .section-title {
  328. font-size: 28rpx;
  329. font-weight: bold;
  330. color: #1E293B;
  331. display: block;
  332. margin-bottom: 20rpx;
  333. }
  334. .history-item {
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. padding: 20rpx 0;
  339. border-bottom: 1rpx solid #FED7AA;
  340. }
  341. .history-item:last-child { border-bottom: none; }
  342. .history-left {
  343. flex: 1;
  344. }
  345. .history-amount {
  346. font-size: 28rpx;
  347. font-weight: bold;
  348. display: block;
  349. color: #1E293B;
  350. }
  351. .history-time {
  352. font-size: 22rpx;
  353. color: #94A3B8;
  354. margin-top: 4rpx;
  355. }
  356. .history-status {
  357. font-size: 24rpx;
  358. }
  359. .text-success { color: #10B981; }
  360. .text-warning { color: #D97706; }
  361. .text-danger { color: #EF4444; }
  362. </style>