申请提现计算手续费的防抖

This commit is contained in:
WindowBird 2025-08-25 10:11:25 +08:00
parent d42af2e2dc
commit 74ea2392e4
5 changed files with 70 additions and 61 deletions

View File

@ -188,11 +188,12 @@ export function getWithdrawInfo() {
* 获取服务费用明细
* @returns {Promise} 返回服务费用明细
*/
export function computedServiceAmount() {
export function computedServiceAmount(amount) {
return request({
url: '/app/withdraw/serviceAmount',
method: 'GET',
showLoading: false,
params: { amount },
}).catch(error => {
console.warn('服务费用API调用失败使用模拟数据:', error)
return createMockResponse(mockWithdrawInfo)

View File

@ -2,7 +2,7 @@
export const DEV_CONFIG = {
// 临时token用于开发测试
TEMP_TOKEN:
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImEwMmVhNzAyLTU5Y2MtNDgyMS1hZGIzLTRjYWY0NzNjYjFhZSJ9.LNW_DJufVd4KfvQWNSH2MbLbVKAMMOcykOybK2Yrngg_IpepeDmlX1e26HQr3PFMpmXy6AYEtObIjjSQEqS61g',
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImY5YWQ3NGQzLWUyM2ItNDQxYy1iYTk2LWYxMDBhNzRmYWI4NyJ9.hAI6gDAp3PT6tu-x2VKGGCUI5HokC01eHdOsgPGTw1WIKyvbBQ7aPr7boG1aqTLswhTVgpunMNMHcdFZJXXRAA',
// 是否使用临时token
USE_TEMP_TOKEN: true,

View File

@ -72,9 +72,6 @@
<view class="withdraw-btn" @click="submitWithdrawal">立即提现</view>
</view>
<!-- 可提现金额提示 -->
<view class="available-amount"> 可提现金额: {{ withdrawInfo.available }}</view>
<!-- 提现说明 -->
<view class="withdrawal-explanation">
<view class="explanation-title">提现说明:</view>
@ -82,7 +79,7 @@
<text>提现金额: {{ withdrawalData.amount ? withdrawalData.amount + '元' : '0.00元' }}</text>
</view>
<view class="explanation-item">
<text>实际到账: {{ actualAmount }}</text>
<text>实际到账: {{ withdrawInfo.actualAmount }}</text>
</view>
<view class="explanation-item">
<text>提现手续费: {{ fee }}</text>
@ -110,10 +107,11 @@
<script>
import { commonEnum } from '@/enum/commonEnum.js'
import { getWithdrawInfo, submitWithdraw } from '@/api/user/user.js'
import { getWithdrawInfo, submitWithdraw, computedServiceAmount } from '@/api/user/user.js'
import { getUserBankList } from '@/api/account.js'
import AddCard from './addCard.vue'
import DeleteCardd from './deleteCard.vue'
import debounce from '../../utils/debounce'
export default {
components: {
@ -124,12 +122,12 @@ export default {
return {
loading: false,
withdrawInfo: {
balance: '10000.00',
balance: '0',
unsettled: '0.00',
available: '10000.00',
fee: 5.0,
minAmount: 5.0,
maxAmount: 50000.0,
fee: 0,
minAmount: 0,
maxAmount: 0,
actualAmount: 0,
},
withdrawalData: {
amount: '',
@ -152,13 +150,7 @@ export default {
computed: {
fee() {
const amount = parseFloat(this.withdrawalData.amount) || 0
return this.withdrawInfo.fee || 1 // 使API1
},
actualAmount() {
const amount = parseFloat(this.withdrawalData.amount) || 0
const fee = parseFloat(this.fee)
const result = amount - fee
return result > 0 ? result.toFixed(2) : '0.00'
return this.withdrawInfo.fee || 0 // 使API0
},
},
onLoad() {
@ -194,8 +186,7 @@ export default {
try {
console.log('开始获取用户账号列表...123')
const response = await getUserBankList()
console.log('API响应123:', response)
console.log('row:')
if (response.code === 200 && response.rows) {
this.userBankList = response.rows || []
console.log('用户账号列表获取成功:')
@ -233,6 +224,27 @@ export default {
}
},
serviceAmount: debounce(async function (amount) {
try {
console.log('发送参数', amount)
if (!amount) {
this.withdrawInfo.fee = 0
this.withdrawInfo.actualAmount = 0
this.withdrawalData.amount = 0
return
}
const res = await computedServiceAmount(amount)
if (res.code === 200 && res.data) {
const info = res.data
this.withdrawInfo.fee = info.serviceCharge
this.withdrawInfo.actualAmount = info.amount
this.withdrawalData.amount = info.withdrawAmount
}
} catch (error) {
console.error('服务费获取失败:', error)
}
}, 600), // 600ms
//
maskCardNumber(cardNumber) {
if (!cardNumber) return ''
@ -275,27 +287,11 @@ export default {
},
onAmountInput(e) {
const value = e.detail.value
console.log('输入值:', value)
//
const filteredValue = value.replace(/[^\d.]/g, '')
//
const parts = filteredValue.split('.')
if (parts.length > 2) {
this.withdrawalData.amount = parts[0] + '.' + parts.slice(1).join('')
} else {
// 2
if (parts.length === 2 && parts[1].length > 2) {
this.withdrawalData.amount = parts[0] + '.' + parts[1].substring(0, 2)
} else {
this.withdrawalData.amount = filteredValue
}
}
console.log(value)
this.serviceAmount(value)
},
withdrawAll() {
const available = parseFloat(this.withdrawInfo.available) || 0
this.withdrawalData.amount = available.toString()
this.withdrawalData.amount = this.withdrawInfo.balance
console.log('全部提现,设置金额:', this.withdrawalData.amount)
},
selectBank() {

12
utils/debounce.js Normal file
View File

@ -0,0 +1,12 @@
function debounce(fn, delay = 500) {
let timer = null
return function (...args) {
clearTimeout(timer) // 清除之前的延迟调用
timer = setTimeout(() => {
fn.apply(this, args) // 延迟执行
}, delay)
}
}
// 导出
export default debounce

View File

@ -18,18 +18,18 @@ import {
const ENV_CONFIG = {
develop: {
// 开发环境
// baseUrl: 'http://192.168.2.136:4501',
baseUrl: 'http://192.168.2.143:4601',
// baseUrl: 'http://192.168.2.174:4501',
baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整
},
trial: {
// 体验版
baseUrl: 'http://192.168.2.143:4601',
baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整
},
release: {
// 正式版
baseUrl: 'http://192.168.2.143:4601',
baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整
},
}
@ -501,7 +501,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
}
const header = {
...options.header
...options.header,
}
// 只有在有token时才添加Authorization头部
@ -515,7 +515,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
name,
hasToken: !!token,
tokenLength: token ? token.length : 0,
header: header
header: header,
})
uni.uploadFile({
@ -525,11 +525,11 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
formData: formData,
header: header,
timeout: options.timeout || 60000,
success: (res) => {
success: res => {
console.log('文件上传响应:', {
statusCode: res.statusCode,
data: res.data,
header: res.header
header: res.header,
})
try {
@ -547,13 +547,13 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
statusCode: res.statusCode,
code: data.code,
message: errorMsg,
data: data
data: data,
})
uni.showToast({
title: errorMsg,
icon: 'none',
duration: 3000
duration: 3000,
})
reject(new Error(errorMsg))
}
@ -562,17 +562,17 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
reject(new Error('响应数据格式错误'))
}
},
fail: (err) => {
fail: err => {
console.error('文件上传失败:', err)
uni.showToast({
title: errorMessage,
icon: 'none',
duration: 3000
duration: 3000,
})
reject(err)
}
},
})
})
}