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

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

View File

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

View File

@ -72,9 +72,6 @@
<view class="withdraw-btn" @click="submitWithdrawal">立即提现</view> <view class="withdraw-btn" @click="submitWithdrawal">立即提现</view>
</view> </view>
<!-- 可提现金额提示 -->
<view class="available-amount"> 可提现金额: {{ withdrawInfo.available }}</view>
<!-- 提现说明 --> <!-- 提现说明 -->
<view class="withdrawal-explanation"> <view class="withdrawal-explanation">
<view class="explanation-title">提现说明:</view> <view class="explanation-title">提现说明:</view>
@ -82,7 +79,7 @@
<text>提现金额: {{ withdrawalData.amount ? withdrawalData.amount + '元' : '0.00元' }}</text> <text>提现金额: {{ withdrawalData.amount ? withdrawalData.amount + '元' : '0.00元' }}</text>
</view> </view>
<view class="explanation-item"> <view class="explanation-item">
<text>实际到账: {{ actualAmount }}</text> <text>实际到账: {{ withdrawInfo.actualAmount }}</text>
</view> </view>
<view class="explanation-item"> <view class="explanation-item">
<text>提现手续费: {{ fee }}</text> <text>提现手续费: {{ fee }}</text>
@ -110,10 +107,11 @@
<script> <script>
import { commonEnum } from '@/enum/commonEnum.js' 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 { getUserBankList } from '@/api/account.js'
import AddCard from './addCard.vue' import AddCard from './addCard.vue'
import DeleteCardd from './deleteCard.vue' import DeleteCardd from './deleteCard.vue'
import debounce from '../../utils/debounce'
export default { export default {
components: { components: {
@ -124,12 +122,12 @@ export default {
return { return {
loading: false, loading: false,
withdrawInfo: { withdrawInfo: {
balance: '10000.00', balance: '0',
unsettled: '0.00', unsettled: '0.00',
available: '10000.00', fee: 0,
fee: 5.0, minAmount: 0,
minAmount: 5.0, maxAmount: 0,
maxAmount: 50000.0, actualAmount: 0,
}, },
withdrawalData: { withdrawalData: {
amount: '', amount: '',
@ -152,13 +150,7 @@ export default {
computed: { computed: {
fee() { fee() {
const amount = parseFloat(this.withdrawalData.amount) || 0 const amount = parseFloat(this.withdrawalData.amount) || 0
return this.withdrawInfo.fee || 1 // 使API1 return this.withdrawInfo.fee || 0 // 使API0
},
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'
}, },
}, },
onLoad() { onLoad() {
@ -194,8 +186,7 @@ export default {
try { try {
console.log('开始获取用户账号列表...123') console.log('开始获取用户账号列表...123')
const response = await getUserBankList() const response = await getUserBankList()
console.log('API响应123:', response)
console.log('row:')
if (response.code === 200 && response.rows) { if (response.code === 200 && response.rows) {
this.userBankList = response.rows || [] this.userBankList = response.rows || []
console.log('用户账号列表获取成功:') 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) { maskCardNumber(cardNumber) {
if (!cardNumber) return '' if (!cardNumber) return ''
@ -275,27 +287,11 @@ export default {
}, },
onAmountInput(e) { onAmountInput(e) {
const value = e.detail.value const value = e.detail.value
console.log('输入值:', value) console.log(value)
this.serviceAmount(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
}
}
}, },
withdrawAll() { withdrawAll() {
const available = parseFloat(this.withdrawInfo.available) || 0 this.withdrawalData.amount = this.withdrawInfo.balance
this.withdrawalData.amount = available.toString()
console.log('全部提现,设置金额:', this.withdrawalData.amount) console.log('全部提现,设置金额:', this.withdrawalData.amount)
}, },
selectBank() { 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 = { const ENV_CONFIG = {
develop: { develop: {
// 开发环境 // 开发环境
// baseUrl: 'http://192.168.2.136:4501', // baseUrl: 'http://192.168.2.174:4501',
baseUrl: 'http://192.168.2.143:4601', baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整 appId: 1, // TODO: 根据实际后端配置调整
}, },
trial: { trial: {
// 体验版 // 体验版
baseUrl: 'http://192.168.2.143:4601', baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整 appId: 1, // TODO: 根据实际后端配置调整
}, },
release: { release: {
// 正式版 // 正式版
baseUrl: 'http://192.168.2.143:4601', baseUrl: 'http://192.168.2.174:4601',
appId: 1, // TODO: 根据实际后端配置调整 appId: 1, // TODO: 根据实际后端配置调整
}, },
} }
@ -501,7 +501,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
} }
const header = { const header = {
...options.header ...options.header,
} }
// 只有在有token时才添加Authorization头部 // 只有在有token时才添加Authorization头部
@ -515,7 +515,7 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
name, name,
hasToken: !!token, hasToken: !!token,
tokenLength: token ? token.length : 0, tokenLength: token ? token.length : 0,
header: header header: header,
}) })
uni.uploadFile({ uni.uploadFile({
@ -525,11 +525,11 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
formData: formData, formData: formData,
header: header, header: header,
timeout: options.timeout || 60000, timeout: options.timeout || 60000,
success: (res) => { success: res => {
console.log('文件上传响应:', { console.log('文件上传响应:', {
statusCode: res.statusCode, statusCode: res.statusCode,
data: res.data, data: res.data,
header: res.header header: res.header,
}) })
try { try {
@ -547,13 +547,13 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
statusCode: res.statusCode, statusCode: res.statusCode,
code: data.code, code: data.code,
message: errorMsg, message: errorMsg,
data: data data: data,
}) })
uni.showToast({ uni.showToast({
title: errorMsg, title: errorMsg,
icon: 'none', icon: 'none',
duration: 3000 duration: 3000,
}) })
reject(new Error(errorMsg)) reject(new Error(errorMsg))
} }
@ -562,17 +562,17 @@ export function uploadFile(url, filePath, name = 'file', formData = {}, options
reject(new Error('响应数据格式错误')) reject(new Error('响应数据格式错误'))
} }
}, },
fail: (err) => { fail: err => {
console.error('文件上传失败:', err) console.error('文件上传失败:', err)
uni.showToast({ uni.showToast({
title: errorMessage, title: errorMessage,
icon: 'none', icon: 'none',
duration: 3000 duration: 3000,
}) })
reject(err) reject(err)
} },
}) })
}) })
} }