'use strict'; // 仅供普通新开单使用。历史费用仍在原费用行中按原金额、付款人显示。 function orderCostPresetsHTML(items){ const selected=new Map(items.map(item=>[FeeEstimates.presetKind(item),item]).filter(([kind])=>kind)); const blocked=new Set(items.filter(item=>!FeeEstimates.presetKind(item)).map(item=>['shipping','box','braiding'].includes(item.key)?item.key:FeeEstimates.checkboxCategory(item.sourceName||item.note)).filter(Boolean)); const disabled=category=>blocked.has(category)?' disabled':'',checked=kind=>selected.has(kind)?' checked':''; const box=selected.get('box'),count=box?box.note.match(/(([^)]*)个 ×/)[1]:'1'; const option=(kind,category,title,amount,payer)=>``; return `
`; } function syncOrderCostPresets(target){ const root=$('#order-cost-presets');if(!root)return; if(target?.checked&&['cost_jd','cost_yt'].includes(target.name))root.querySelector('[name="'+(target.name==='cost_jd'?'cost_yt':'cost_jd')+'"]').checked=false; root.querySelector('[name="cost_box_quantity"]').disabled=!root.querySelector('[name="cost_box"]').checked||root.querySelector('[name="cost_box"]').disabled; root.querySelector('[name="cost_box_quantity"]').required=!root.querySelector('[name="cost_box_quantity"]').disabled; } function readOrderCostPresets(){ const root=$('#order-cost-presets');if(!root)return []; const checked=name=>{const input=root.querySelector('[name="cost_'+name+'"]');return input.checked&&!input.disabled;}; const member=orderFormMember(),quantity=root.querySelector('[name="cost_box_quantity"]').value; const selection={shipping:checked('jd')?'jd':checked('yt')?'yt':'',box:checked('box'),quantity,steel:checked('steel')}; root.querySelector('[data-cost-yt-payer]').textContent=teamMemberName(member)+'付款(订单归属人)'; const boxTotal=root.querySelector('[data-cost-box-total]'); let items; try{items=FeeEstimates.checkboxFees(selection,member);boxTotal.textContent=selection.box?FeeEstimates.boxCount(quantity)+'个 × 3元 = '+FeeEstimates.boxCount(quantity)*3+'元':'勾选后计费';} catch{items=FeeEstimates.checkboxFees({...selection,box:false},member);items.push({key:'box',note:`盒子(${quantity}个 × 3元/个)`,amount:'',payer:'owner',status:'estimated',edited:true});boxTotal.textContent='请填写正整数数量';} return items; }