Files
tms-erp-web/src/utils/settlement-adjust-rule.js
T
b2894lxlx e7c76c803f ✨ 结算单业务模式运输方式与编辑体验优化
预结算/收付款结算支持业务模式与运输方式展示导出;完善结算调整、对账导入与变更记录;组织合同初始流水号未填不再显示-1。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-21 16:42:02 +08:00

48 lines
1.6 KiB
JavaScript

export function isFreightFeeName(name) {
const text = String(name || '');
return text.includes('运费') || text.includes('运输费');
}
function parseBillingRules(row = {}) {
const rule = row.billingRule || {};
const nested = Array.isArray(rule.rules) ? rule.rules : [];
if (nested.length) return nested;
const raw = row.billingRulesJson ?? row.billingRules;
if (Array.isArray(raw)) return raw.filter(item => item && typeof item === 'object');
if (typeof raw === 'string' && raw.trim()) {
try {
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed.filter(item => item && typeof item === 'object') : [];
} catch (error) {
return [];
}
}
return [];
}
/** 运输单价对应的运费计费类型。 */
export function freightBillingType(row = {}) {
const rule = row.billingRule || {};
const rules = parseBillingRules(row);
const freightRule = rules.find(
item => isFreightFeeName(item?.feeItem) || isFreightFeeName(item?.feeType)
);
return freightRule?.billingType || row.billingType || rule.billingType || '';
}
export function isTierUnitPrice(row) {
return freightBillingType(row) === '阶梯单价';
}
export function isIntervalBilling(row) {
const type = freightBillingType(row);
return type === '区间单价' || (type.includes('区间') && type.includes('一口价'));
}
/** 阶梯单价、区间单价、区间一口价的运输单价不开放手工调整。 */
export function isUnitPriceAdjustable(row) {
const type = freightBillingType(row);
if (!type) return true;
return !isTierUnitPrice(row) && !isIntervalBilling(row);
}