需求列表状态刷新优化
This commit is contained in:
@@ -56,3 +56,39 @@ export function fetchHome() {
|
||||
export function fetchConfig() {
|
||||
return wx.$util.request(wx.$api.CommonGetMiniConfig, {}, 'GET');
|
||||
}
|
||||
|
||||
// 与后端 site.platform_commission_ratio 默认值一致,接口失败时兜底
|
||||
const DEFAULT_COMMISSION_RATIO = 0.1;
|
||||
let commissionRatioCache = null;
|
||||
|
||||
/**
|
||||
* 获取平台服务费比例(0~1),成功后缓存,失败返回默认值且不缓存,下次重新请求
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
export async function fetchPlatformCommissionRatio() {
|
||||
if (commissionRatioCache !== null) {
|
||||
return commissionRatioCache;
|
||||
}
|
||||
try {
|
||||
const res = await fetchConfig();
|
||||
const ratio = Number(res?.data?.platform_commission_ratio);
|
||||
if (res.code === 1 && ratio >= 0 && ratio <= 1) {
|
||||
commissionRatioCache = ratio;
|
||||
return ratio;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('fetchPlatformCommissionRatio failed:', err);
|
||||
}
|
||||
return DEFAULT_COMMISSION_RATIO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算扣除平台服务费后的预计到手金额(保留两位小数)
|
||||
* @param {number|string} amount 报价/总费用(元)
|
||||
* @param {number} ratio 平台服务费比例
|
||||
* @returns {number}
|
||||
*/
|
||||
export function calcActualAccount(amount, ratio) {
|
||||
const value = Number(amount) || 0;
|
||||
return Math.round(value * (1 - ratio) * 100) / 100;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user