旧模板成本支持勾选替换并避免重复计费
This commit is contained in:
1 parent
6047cc360b
commit
294c430884
2 files changed
+63
-9
No files matched your search
@@ -1,21 +1,45 @@
|
||||
'use strict';
|
||||
// 仅供普通新开单使用。历史费用仍在原费用行中按原金额、付款人显示。
|
||||
function orderCostFeeCategory(item){
|
||||
if(item.key==='shipping'||item.key==='box')return item.key;
|
||||
// 旧版 braiding 是编绳,只有明确写了钢绳才属于店内钢绳成本。
|
||||
if(String(item.note||'').trim()==='编绳')return '';
|
||||
return FeeEstimates.checkboxCategory(item.note)||FeeEstimates.checkboxCategory(item.sourceName);
|
||||
}
|
||||
function orderCostReplacementHint(items,category){
|
||||
const count=items.filter(item=>!FeeEstimates.presetKind(item)&&orderCostFeeCategory(item)===category).length;
|
||||
return count?'已有'+({shipping:'快递',box:'包装',braiding:'店内钢绳'})[category]+'费用'+(count>1?'('+count+'项)':'')+',勾选后替换'+(count>1?'全部':''):'';
|
||||
}
|
||||
function orderCostLegacyRows(){
|
||||
return [...($('#fee-rows')?.querySelectorAll('.fee-row')||[])].filter(row=>!row.dataset.automaticFee).map(row=>({row,item:{key:row.dataset.fee,sourceName:row.dataset.source,note:row.querySelector('[name="feeNote"]')?.value??row.querySelector('.fee-name')?.textContent}}));
|
||||
}
|
||||
function syncOrderCostReplacementHints(){
|
||||
const root=$('#order-cost-presets');if(!root)return;
|
||||
const items=orderCostLegacyRows().map(value=>value.item);
|
||||
for(const hint of root.querySelectorAll('[data-cost-replacement]'))hint.textContent=orderCostReplacementHint(items,hint.dataset.costReplacement);
|
||||
}
|
||||
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 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)=>`<label class="order-cost-option"><input type="checkbox" name="cost_${kind}"${checked(kind)}${disabled(category)}><span><strong>${title}</strong><span class="order-cost-price">${amount}</span><small>${payer}${blocked.has(category)?' · 已有费用保留在下方':''}</small></span></label>`;
|
||||
return `<fieldset id="order-cost-presets" class="order-cost-presets"><legend>常用成本 · 按实际发生勾选</legend><p class="small muted">快递二选一,也可不选;取消勾选不记成本。</p><div class="order-cost-options">${option('jd','shipping','京东快递','8元','麦麦付款')}${option('yt','shipping','圆通快递','6元','<span data-cost-yt-payer>订单归属人付款</span>')}<div class="order-cost-box">${option('box','box','盒子','3元/个','麦麦付款')}<label class="order-cost-quantity">盒子数量(个)<input type="number" name="cost_box_quantity" min="1" max="333333333" step="1" inputmode="numeric" value="${e(count)}"${!box||blocked.has('box')?' disabled':' required'}><small data-cost-box-total>${box?e(count)+'个 × 3元 = '+e(box.amount)+'元':'勾选后计费'}</small></label></div>${option('steel','braiding','钢绳(店里)','7元','麦麦付款')}</div></fieldset>`;
|
||||
const option=(kind,category,title,amount,payer)=>`<label class="order-cost-option"><input type="checkbox" name="cost_${kind}"${checked(kind)}><span><strong>${title}</strong><span class="order-cost-price">${amount}</span><small>${payer}</small><small data-cost-replacement="${category}">${e(orderCostReplacementHint(items,category))}</small></span></label>`;
|
||||
return `<fieldset id="order-cost-presets" class="order-cost-presets"><legend>常用成本 · 按实际发生勾选</legend><p class="small muted">快递二选一,也可不选;取消勾选不记成本。</p><div class="order-cost-options">${option('jd','shipping','京东快递','8元','麦麦付款')}${option('yt','shipping','圆通快递','6元','<span data-cost-yt-payer>订单归属人付款</span>')}<div class="order-cost-box">${option('box','box','盒子','3元/个','麦麦付款')}<label class="order-cost-quantity">盒子数量(个)<input type="number" name="cost_box_quantity" min="1" max="333333333" step="1" inputmode="numeric" value="${e(count)}"${!box?' disabled':' required'}><small data-cost-box-total>${box?e(count)+'个 × 3元 = '+e(box.amount)+'元':'勾选后计费'}</small></label></div>${option('steel','braiding','钢绳(店里)','7元','麦麦付款')}</div></fieldset>`;
|
||||
}
|
||||
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;
|
||||
const category={cost_jd:'shipping',cost_yt:'shipping',cost_box:'box',cost_steel:'braiding'}[target?.name];
|
||||
if(target?.checked&&category)for(const {row,item} of orderCostLegacyRows()){
|
||||
if(orderCostFeeCategory(item)===category)row.remove();
|
||||
else if(item.key===category)row.dataset.fee='manual:'+crypto.randomUUID();
|
||||
}
|
||||
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;
|
||||
syncOrderCostReplacementHints();
|
||||
}
|
||||
function readOrderCostPresets(){
|
||||
const root=$('#order-cost-presets');if(!root)return [];
|
||||
syncOrderCostReplacementHints();
|
||||
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')};
|
||||
|
||||
Reference in new issue
Block a user