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); }