export function formatServiceItems(value, mainName = '', quantity = null) { if (value == null) return ''; let prefix = ''; let items = value; if (typeof items === 'string') { items = items.trim(); const match = items.match(/^服务项目[::]\s*/); if (match) { prefix = match[0]; items = items.slice(match[0].length).trim(); } if (!/^[\[{]/.test(items)) return prefix + items; try { items = JSON.parse(items); } catch (_) { return ''; } } if (!Array.isArray(items)) return ''; const parts = []; if (mainName && quantity != null && Number(quantity) > 0) parts.push(`${mainName}x${quantity}`); items.forEach(item => { if (!item || typeof item.name !== 'string' || !item.name.trim()) return; const count = item.num != null ? item.num : item.count; if (count != null && Number(count) <= 0) return; parts.push(item.name.trim() + (count != null ? `x${count}` : '')); }); return parts.length ? prefix + parts.join(';') : ''; } export function formatOrderServiceItems(order) { let main = ''; let quantity = null; try { const snapshot = typeof order.goods_images === 'string' ? JSON.parse(order.goods_images) : order.goods_images; const first = snapshot && Array.isArray(snapshot.goods_list) ? snapshot.goods_list[0] : null; if (first) { main = first.service_type_name || ''; quantity = first.num != null ? first.num : first.goods_num; } } catch (_) {} return formatServiceItems(order.service_items_text, main, quantity); }