withdraw.vue 9.6 KB

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