整合公共店铺配置与动态员工管理,保留最新订单功能及历史账兼容
This commit is contained in:
commit
b87f774386
84 files changed
+1622
-715
No files matched your search
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
// 新开单和整单修改共用;修改中的原流水身份、付款人和日期必须保留。
|
||||
function orderCostConfig(){return FeeEstimates.presets(typeof state==='undefined'?undefined:state?.shopSettings?.costPresets);}
|
||||
const orderCostCategories={jd:'shipping',yt:'shipping',box:'box',steel:'braiding',silver:'silverChain'};
|
||||
function orderCostFeeCategory(item){
|
||||
if(item.key==='shipping'||item.key==='box')return item.key;
|
||||
@@ -9,7 +10,7 @@ function orderCostFeeCategory(item){
|
||||
}
|
||||
function orderCostReplacementHint(items,category){
|
||||
if(items.some(item=>item.funding&&orderCostFeeCategory(item)===category))return '已有报销关联费用,请在原费用行核对';
|
||||
const count=items.filter(item=>!FeeEstimates.presetKind(item)&&orderCostFeeCategory(item)===category).length;
|
||||
const count=items.filter(item=>!FeeEstimates.presetKind(item,{presets:orderCostConfig()})&&orderCostFeeCategory(item)===category).length;
|
||||
return count?'已有'+({shipping:'快递',box:'包装',braiding:'店内钢绳',silverChain:'家里银链'})[category]+'费用'+(count>1?'('+count+'项)':'')+',勾选后替换'+(count>1?'全部':''):'';
|
||||
}
|
||||
function orderCostLegacyRows(){
|
||||
@@ -22,12 +23,13 @@ function syncOrderCostReplacementHints(){
|
||||
for(const hint of root.querySelectorAll('[data-cost-replacement]'))hint.textContent=orderCostReplacementHint(items,hint.dataset.costReplacement);
|
||||
}
|
||||
function orderCostPresetsHTML(items,{editing=false}={}){
|
||||
const selected=new Map(items.map(item=>[FeeEstimates.presetKind(item,{recorded:editing}),item]).filter(([kind])=>kind)),originals=Object.fromEntries([...selected].map(([kind,item])=>[orderCostCategories[kind],item]));
|
||||
const selected=new Map(items.map(item=>[FeeEstimates.presetKind(item,{recorded:editing,presets:orderCostConfig()}),item]).filter(([kind])=>kind)),originals=Object.fromEntries([...selected].map(([kind,item])=>[orderCostCategories[kind],item]));
|
||||
const config=orderCostConfig(),payerText=kind=>config[kind].payer==='order'?'订单归属人付款':e(teamMemberName(config[kind].payer))+'付款';
|
||||
const checked=kind=>selected.has(kind)?' checked':'';
|
||||
const box=selected.get('box'),count=box?box.note.match(/(([^)]*)个 ×/)[1]:'1';
|
||||
const funded=category=>items.some(item=>item.funding&&orderCostFeeCategory(item)===category);
|
||||
const option=(kind,category,title,amount,payer)=>`<label class="order-cost-option"><input type="checkbox" name="cost_${kind}"${checked(kind)}${funded(category)?' disabled':''}><span><strong>${title}</strong><span class="order-cost-price">${amount}</span><small>${payer}</small>${editing&&originals[category]?.date?`<small>原支付日期 ${e(originals[category].date)}</small>`:''}<small data-cost-replacement="${category}">${e(orderCostReplacementHint(items,category))}</small></span></label>`;
|
||||
return `<fieldset id="order-cost-presets" class="order-cost-presets" data-cost-editing="${editing}" data-cost-originals="${e(JSON.stringify(originals))}"><legend>常用成本 · 按实际发生勾选</legend><p class="small muted">快递二选一,也可不选;${editing?'已有费用保留原支付日期,取消后保存会冲回对应成本。':'取消勾选不记成本。'}</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||funded('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>`;
|
||||
return `<fieldset id="order-cost-presets" class="order-cost-presets" data-cost-editing="${editing}" data-cost-originals="${e(JSON.stringify(originals))}"><legend>常用成本 · 按实际发生勾选</legend><p class="small muted">快递二选一,也可不选;${editing?'已有费用保留原支付日期,取消后保存会冲回对应成本。':'取消勾选不记成本。'}</p><div class="order-cost-options">${option('jd','shipping','京东快递',e(config.jd.amount)+'元',payerText('jd'))}${option('yt','shipping','圆通快递',e(config.yt.amount)+'元','<span data-cost-yt-payer>订单归属人付款</span>')}<div class="order-cost-box">${option('box','box','盒子',e(config.box.amount)+'元/个',payerText('box'))}<label class="order-cost-quantity">盒子数量(个)<input type="number" name="cost_box_quantity" min="1" max="333333333" step="1" inputmode="numeric" value="${e(count)}"${!box||funded('box')?' disabled':' required'}><small data-cost-box-total>${box?e(count)+'个 × '+e(config.box.amount)+'元 = '+e(box.amount)+'元':'勾选后计费'}</small></label></div>${option('steel','braiding','钢绳(店里)',e(config.steel.amount)+'元',payerText('steel'))}${option('silver','silverChain','银链(家里)',e(config.silver.amount)+'元',payerText('silver'))}</div></fieldset>`;
|
||||
}
|
||||
function syncOrderCostPresets(target){
|
||||
const root=$('#order-cost-presets');if(!root)return;
|
||||
@@ -49,14 +51,14 @@ function readOrderCostPresets(){
|
||||
syncOrderCostReplacementHints();
|
||||
const originals=JSON.parse(root.dataset?.costOriginals||'{}'),changed=JSON.parse(root.dataset?.costChanged||'{}'),editing=root.dataset?.costEditing==='true';
|
||||
const checked=name=>{const input=root.querySelector('[name="cost_'+name+'"]');return input.checked&&(!input.disabled||editing&&originals[orderCostCategories[name]]&&!changed[orderCostCategories[name]]);};
|
||||
const member=orderFormMember(),quantity=root.querySelector('[name="cost_box_quantity"]').value;
|
||||
const config=orderCostConfig(),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'),silver:checked('silver')};
|
||||
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='请填写正整数数量';}
|
||||
if(editing)items=items.map(item=>{const category=orderCostCategories[FeeEstimates.presetKind(item)]||'box',source=originals[category];return source?changed[category]?{...source,...item}:{...source}:item;});
|
||||
try{items=FeeEstimates.checkboxFees(selection,member,config);boxTotal.textContent=selection.box?FeeEstimates.boxCount(quantity)+'个 × '+config.box.amount+'元 = '+items.find(item=>item.key==='box').amount+'元':'勾选后计费';}
|
||||
catch{items=FeeEstimates.checkboxFees({...selection,box:false},member,config);items.push({key:'box',note:`盒子(${quantity}个 × ${config.box.amount}元/个)`,amount:'',payer:config.box.payer==='order'?member:config.box.payer,status:'estimated',edited:true});boxTotal.textContent='请填写正整数数量';}
|
||||
if(editing)items=items.map(item=>{const category=orderCostCategories[FeeEstimates.presetKind(item,{presets:orderCostConfig()})]||'box',source=originals[category];return source?changed[category]?{...source,...item}:{...source}:item;});
|
||||
const shipping=items.find(item=>item.note==='圆通快递');
|
||||
root.querySelector('[data-cost-yt-payer]').textContent=teamMemberName(shipping?.payer||member)+'付款'+(shipping&&editing&&!changed.shipping?'(原费用)':'(订单归属人)');
|
||||
root.querySelector('[data-cost-yt-payer]').textContent=teamMemberName(shipping?.payer||(config.yt.payer==='order'?member:config.yt.payer))+'付款'+(shipping&&editing&&!changed.shipping?'(原费用)':config.yt.payer==='order'?'(订单归属人)':'');
|
||||
return items;
|
||||
}
|
||||
Reference in new issue
Block a user