| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <template>
- <view class="container">
- <!-- 可提现余额 -->
- <view class="balance-card">
- <text class="balance-label">可提现金额</text>
- <text class="balance-value">¥{{ availableAmount || '0.00' }}</text>
- </view>
- <!-- 提现表单 -->
- <view class="form-card">
- <view class="form-item">
- <text class="form-label">提现金额</text>
- <view class="input-row">
- <input v-model="amount" type="digit" placeholder="输入提现金额" class="form-input" />
- <text class="unit">元</text>
- <text class="btn-all" @click="amount = availableAmount">全部提现</text>
- </view>
- </view>
- <view class="form-item">
- <text class="form-label">支付宝账号</text>
- <input v-model="accountInfo" type="text" placeholder="请输入支付宝账号" class="form-input" />
- </view>
- <view class="form-tip">最低提现金额:1元</view>
- <button class="submit-btn" @click="submitWithdraw">提交申请</button>
- </view>
- <!-- 提现历史 -->
- <view class="history-section" v-if="history.length > 0">
- <text class="section-title">提现记录</text>
- <view class="history-item" v-for="item in history" :key="item.id">
- <view class="history-left">
- <text class="history-amount">¥{{ item.amount }}</text>
- <text class="history-time">{{ formatTime(item.createdAt) }}</text>
- </view>
- <text :class="['history-status', statusClass(item.status)]">{{ statusText(item.status) }}</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getCommissionSummary, applyWithdrawal, getWithdrawalHistory } from '../../utils/api.js'
- export default {
- data() {
- return {
- availableAmount: '0.00',
- amount: '',
- accountInfo: '',
- history: [],
- historyPage: 1
- }
- },
- onLoad() {
- this.loadBalance()
- this.loadHistory()
- },
- methods: {
- async loadBalance() {
- try {
- const res = await getCommissionSummary()
- if (res.data) {
- this.availableAmount = res.data.availableAmount || '0.00'
- }
- } catch (e) {
- console.error('获取佣金总览失败', e)
- }
- },
- async loadHistory() {
- try {
- const res = await getWithdrawalHistory(this.historyPage)
- if (res.data && res.data.records) {
- this.history = res.data.records
- }
- } catch (e) {
- console.error('获取提现记录失败', e)
- }
- },
- submitWithdraw() {
- const amountNum = parseFloat(this.amount)
- if (!this.amount || isNaN(amountNum) || amountNum < 1) {
- uni.showToast({ title: '提现金额不能少于1元', icon: 'none' })
- return
- }
- if (amountNum > parseFloat(this.availableAmount)) {
- uni.showToast({ title: '提现金额超过可提现余额', icon: 'none' })
- return
- }
- if (!this.accountInfo) {
- uni.showToast({ title: '请输入支付宝账号', icon: 'none' })
- return
- }
- uni.showModal({
- title: '确认提现',
- content: '确认提现 ¥' + amountNum.toFixed(2) + ' 到 ' + this.accountInfo + ' ?',
- success: async (res) => {
- if (res.confirm) {
- try {
- await applyWithdrawal(amountNum, this.accountInfo)
- uni.showToast({ title: '提现申请已提交', icon: 'success' })
- this.amount = ''
- this.accountInfo = ''
- this.loadBalance()
- this.loadHistory()
- } catch (e) {
- uni.showToast({ title: e.message || '提现失败', icon: 'none' })
- }
- }
- }
- })
- },
- statusText(status) {
- const map = { pending: '待审核', approved: '已通过', rejected: '已拒绝' }
- return map[status] || status
- },
- statusClass(status) {
- if (status === 'approved') return 'text-success'
- if (status === 'rejected') return 'text-danger'
- return 'text-warning'
- },
- formatTime(time) {
- if (!time) return ''
- const t = new Date(time)
- return t.getFullYear() + '-' + String(t.getMonth()+1).padStart(2,'0') + '-' + String(t.getDate()).padStart(2,'0')
- }
- }
- }
- </script>
- <style scoped>
- .container {
- padding: 30rpx;
- min-height: 100vh;
- background: #f5f7fa;
- }
- .balance-card {
- background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
- border-radius: 20rpx;
- padding: 40rpx;
- text-align: center;
- color: #fff;
- margin-bottom: 30rpx;
- }
- .balance-label {
- font-size: 26rpx;
- opacity: 0.9;
- }
- .balance-value {
- font-size: 56rpx;
- font-weight: bold;
- margin-top: 12rpx;
- }
- .form-card {
- background: #fff;
- border-radius: 20rpx;
- padding: 40rpx;
- margin-bottom: 30rpx;
- }
- .form-item {
- margin-bottom: 30rpx;
- }
- .form-label {
- font-size: 28rpx;
- color: #333;
- display: block;
- margin-bottom: 16rpx;
- }
- .input-row {
- display: flex;
- align-items: center;
- border: 1rpx solid #ddd;
- border-radius: 10rpx;
- padding: 20rpx;
- }
- .form-input {
- flex: 1;
- font-size: 28rpx;
- }
- .unit {
- font-size: 28rpx;
- color: #999;
- margin: 0 16rpx;
- }
- .btn-all {
- font-size: 24rpx;
- color: #3A7CC4;
- padding: 6rpx 12rpx;
- border: 1rpx solid #3A7CC4;
- border-radius: 6rpx;
- }
- .form-tip {
- font-size: 24rpx;
- color: #999;
- margin-bottom: 30rpx;
- }
- .submit-btn {
- background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
- color: #fff;
- font-size: 30rpx;
- border-radius: 40rpx;
- height: 80rpx;
- line-height: 80rpx;
- }
- .submit-btn::after { border: none; }
- .history-section {
- background: #fff;
- border-radius: 20rpx;
- padding: 30rpx;
- }
- .section-title {
- font-size: 28rpx;
- font-weight: bold;
- color: #333;
- display: block;
- margin-bottom: 20rpx;
- }
- .history-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #f0f0f0;
- }
- .history-item:last-child { border-bottom: none; }
- .history-left {
- flex: 1;
- }
- .history-amount {
- font-size: 28rpx;
- font-weight: bold;
- display: block;
- }
- .history-time {
- font-size: 22rpx;
- color: #999;
- margin-top: 4rpx;
- }
- .history-status {
- font-size: 24rpx;
- }
- .text-success { color: #52c41a; }
- .text-warning { color: #faad14; }
- .text-danger { color: #ff4d4f; }
- </style>
|