常用成本增加银链家里18元由麦麦付款

This commit is contained in:
summer committed 2026-11-19 13:41:58 +08:00
1 parent 294c430884
commit 5777036743
3 files changed
+45 -20

No files matched your search

+5 -1
View File
@@ -9,6 +9,7 @@
if(['快递','快递费','运费','京东快递','圆通快递'].includes(value))return 'shipping';
if(['包装','包装盒','盒子'].includes(value)||/^盒子(\d+个 × 3元\/个)$/.test(value))return 'box';
if(['钢绳','钢绳(店里)','钢绳(店里)'].includes(value))return 'braiding';
if(['银链','银链(家里)','银链(家里)'].includes(value))return 'silverChain';
return '';
}
function boxCount(value){
@@ -21,16 +22,19 @@
if(item.key==='shipping'&&item.note==='京东快递'&&Number(item.amount)===8&&item.payer==='owner')return 'jd';
if(item.key==='shipping'&&item.note==='圆通快递'&&Number(item.amount)===6&&['owner','assistant','assistant2'].includes(item.payer))return 'yt';
if(item.key==='braiding'&&item.note==='钢绳(店里)'&&Number(item.amount)===7&&item.payer==='owner')return 'steel';
if(item.key==='other'&&item.note==='银链(家里)'&&Number(item.amount)===18&&item.payer==='owner')return 'silver';
const match=item.key==='box'&&String(item.note).match(/^盒子(([^)]*)个 × 3元\/个)$/);
if(match&&item.payer==='owner'){if(item.amount==='')return 'box';try{if(Number(item.amount)===boxCount(match[1])*3)return 'box';}catch{}}
return '';
}
function checkboxFees({shipping='',box=false,quantity='1',steel=false}={},member='assistant'){
function checkboxFees({shipping='',box=false,quantity='1',steel=false,silver=false}={},member='assistant'){
const items=[],add=(key,note,amount,payer)=>items.push({key,note,amount:String(amount),payer,status:'estimated',edited:true});
if(shipping==='jd')add('shipping','京东快递',8,'owner');
else if(shipping==='yt')add('shipping','圆通快递',6,['owner','assistant','assistant2'].includes(member)?member:'assistant');
if(box){const count=boxCount(quantity);add('box',`盒子(${count}个 × 3元/个)`,count*3,'owner');}
if(steel)add('braiding','钢绳(店里)',7,'owner');
// 沿用其他直接费用的兼容键,由名称区分家里银链。
if(silver)add('other','银链(家里)',18,'owner');
return items;
}
function sync(existing,lines,{addShipping=false,defaultPayer='assistant',shopDefaults={},checkboxCosts=false}={}){
+5 -5
View File
@@ -8,7 +8,7 @@ function orderCostFeeCategory(item){
}
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?'全部':''):'';
return count?'已有'+({shipping:'快递',box:'包装',braiding:'店内钢绳',silverChain:'家里银链'})[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}}));
@@ -23,15 +23,15 @@ function orderCostPresetsHTML(items){
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)}><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>`;
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元','麦麦付款')}${option('silver','silverChain','银链(家里)','18元','麦麦付款')}</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];
const category={cost_jd:'shipping',cost_yt:'shipping',cost_box:'box',cost_steel:'braiding',cost_silver:'silverChain'}[target?.name],feeKey=category==='silverChain'?'other':category;
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();
else if(item.key===feeKey)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;
@@ -42,7 +42,7 @@ function readOrderCostPresets(){
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')};
const selection={shipping:checked('jd')?'jd':checked('yt')?'yt':'',box:checked('box'),quantity,steel:checked('steel'),silver:checked('silver')};
root.querySelector('[data-cost-yt-payer]').textContent=teamMemberName(member)+'付款(订单归属人)';
const boxTotal=root.querySelector('[data-cost-box-total]');
let items;