允许手动移除附加成本并保留草稿模板删除状态
This commit is contained in:
1 parent
5777036743
commit
a3262a455d
8 files changed
+109
-11
No files matched your search
+22
-4
@@ -312,7 +312,24 @@ function chargeHTML(c={}){
|
||||
// 只给新选择预填报价;旧金额、手填0和主动清空都原样保留。
|
||||
const amount=Object.hasOwn(c,'amount')?(c.amount??''):(chargeSaleDefaults[type]??'');
|
||||
const prices={...c.chargePrices,[type]:amount};
|
||||
return `<div class="charge-row" data-charge-id="${e(c.id||crypto.randomUUID())}" data-charge-type="${e(type)}" data-charge-prices="${e(JSON.stringify(prices))}">${choice('附加项目','chargeType',[...chargeNames,'其他'],type)}${field('附加项目名称','chargeName',c.customName??(type==='其他'?c.name:''),'text','maxlength="40"')}${amountInput('附加金额(元)','chargeAmount',amount,'required placeholder="没有收费填0,可修改金额"')}${button('移除附加项','remove-charge','quiet')}</div>`;
|
||||
return `<div class="charge-row" data-charge-id="${e(c.id||crypto.randomUUID())}" data-charge-type="${e(type)}" data-charge-prices="${e(JSON.stringify(prices))}"${c.costRemoved===true?' data-cost-removed="true"':''}>${choice('附加项目','chargeType',[...chargeNames,'其他'],type)}${field('附加项目名称','chargeName',c.customName??(type==='其他'?c.name:''),'text','maxlength="40"')}${amountInput('附加金额(元)','chargeAmount',amount,'required placeholder="没有收费填0,可修改金额"')}<div>${button('移除附加项','remove-charge','quiet')}<small class="charge-cost-status muted"${c.costRemoved===true?'':' hidden'}>内部成本已移除 ${button('恢复内部成本','restore-charge-cost','quiet')}</small></div></div>`;
|
||||
}
|
||||
function setChargeCostRemoved(row,removed){
|
||||
if(removed)row.dataset.costRemoved='true';else delete row.dataset.costRemoved;
|
||||
const status=row.querySelector('.charge-cost-status');if(status)status.hidden=!removed;
|
||||
}
|
||||
function removeFeeRow(row){
|
||||
if(!row||row.dataset.automaticFee)return;
|
||||
const key=row.dataset.fee;
|
||||
for(const charge of document.querySelectorAll('#lines .charge-row')){
|
||||
const type=charge.querySelector('[name="chargeType"]').value,name=type==='其他'?charge.querySelector('[name="chargeName"]').value:type;
|
||||
if(key==='charge:'+charge.dataset.chargeId||key==='shipping'&&FeeEstimates.normalize(name.trim())==='快递')setChargeCostRemoved(charge,true);
|
||||
}
|
||||
// 已交付锁价单的销售项目只读,仍需在其独立草稿里保留明确移除记录。
|
||||
if(typeof priceLockOrderEditable==='function'&&priceLockOrderEditable()&&orderEditForm()?.dataset.priceLockEdit==='true')for(const line of orderEditEntry.inputs.lines)for(const charge of line.charges||[]){
|
||||
if(key==='charge:'+charge.id||key==='shipping'&&FeeEstimates.normalize(charge.name)==='快递')charge.costRemoved=true;
|
||||
}
|
||||
row.remove();
|
||||
}
|
||||
function syncChargePrice(target){
|
||||
const row=target.closest('.charge-row');if(!row||!['chargeType','chargeAmount'].includes(target.name))return;
|
||||
@@ -346,7 +363,7 @@ function feeRowHTML(item){
|
||||
'<div class="fee-title"><strong class="fee-name"'+(manual?' hidden':'')+'>'+e(item.note)+'</strong>'+(manual?field('费用项目名称','feeNote',item.note,'text','required maxlength="150"'):'')+'<span class="small muted fee-source">'+(automatic?'已记录的信用卡收款手续费':linked?'商品 '+item.lineNumber+' 的附加项目':'整单费用')+'</span></div>'+
|
||||
amountInput(automatic?'手续费(元,自动)':'实际成本(元)','feeAmount',item.amount??'',automatic?'required readonly':'required placeholder="没有成本填0"')+choice('费用付款人','feePayer',teamMemberOptions(true),item.payer||(automatic?'owner':teamDefaultPayer()))+
|
||||
(tab==='order-edit'?field('本笔费用支付日期','feeDate',item.date||$('#order-form [name="fees_date"]')?.value||orderEditEntry.inputs.fees_date||orderEditEntry.inputs.date,'date',`required max="${state.today}"${automatic?' readonly':''}`):'')+
|
||||
(automatic?'<small class="muted fee-help">沿用已记录的手续费金额与费率,支付日期保留。</small>':linked?'<small class="muted fee-help">随上方项目同步;没有成本填0</small>':button('移除费用','remove-fee','quiet'))+(typeof reimbursementFundingHTML==='function'&&!automatic?reimbursementFundingHTML('fee',item.funding):'')+'</div>';
|
||||
(automatic?'<small class="muted fee-help">沿用已记录的手续费金额与费率,支付日期保留。</small>':button('移除费用','remove-fee','quiet'))+(typeof reimbursementFundingHTML==='function'&&!automatic?reimbursementFundingHTML('fee',item.funding):'')+'</div>';
|
||||
}
|
||||
function readFeeRows(root=$('#fee-rows'),includePresets=true){const items=[...root.querySelectorAll('.fee-row')].map(row=>{const date=row.querySelector('[name="feeDate"]')?.value||row.dataset.feeDate,amount=row.querySelector('[name="feeAmount"]').value,payer=row.querySelector('[name="feePayer"]').value;if(row.dataset.automaticFee)return {...JSON.parse(row.dataset.automaticFee),...(date?{date}:{}),amount,payer};return {key:row.dataset.fee,sourceName:row.dataset.source||undefined,edited:row.dataset.edited==='true',...(row.dataset.expenseId?{expense_id:row.dataset.expenseId}:{}),...(date?{date}:{}),...(row.dataset.status==='estimated'?{status:'estimated'}:{}),note:row.querySelector('[name="feeNote"]')?.value??row.querySelector('.fee-name').textContent,amount,payer,...(typeof readReimbursementFunding==='function'&&row.querySelector('.cost-funding')?{funding:readReimbursementFunding(row.querySelector('.cost-funding'))}:{})};});return includePresets&&root===$('#fee-rows')&&typeof readOrderCostPresets==='function'?[...items,...readOrderCostPresets()]:items;}
|
||||
function syncFeeRows(){
|
||||
@@ -402,7 +419,7 @@ function renderCreate(){
|
||||
}
|
||||
function collectLine(row){
|
||||
const values=Object.fromEntries([...row.querySelectorAll('input,select')].filter(el=>!el.closest('.charge-row')).map(el=>[el.name,el.value]));
|
||||
values.charges=[...row.querySelectorAll('.charge-row')].map(r=>{const get=n=>r.querySelector(`[name="${n}"]`).value;const type=get('chargeType'),customName=get('chargeName');return {id:r.dataset.chargeId,nameType:type,customName,name:type==='其他'?customName:type,amount:get('chargeAmount'),chargePrices:JSON.parse(r.dataset.chargePrices)};});
|
||||
values.charges=[...row.querySelectorAll('.charge-row')].map(r=>{const get=n=>r.querySelector(`[name="${n}"]`).value;const type=get('chargeType'),customName=get('chargeName');return {id:r.dataset.chargeId,nameType:type,customName,name:type==='其他'?customName:type,amount:get('chargeAmount'),chargePrices:JSON.parse(r.dataset.chargePrices),...(r.dataset.costRemoved==='true'?{costRemoved:true}:{})};});
|
||||
values.name=values.nameType==='其他'?values.customName:values.nameType;
|
||||
if(!pocketCountsEnabled(values.pocket)||values.unit!=='g')delete values.stockCount;
|
||||
else if(String(values.stockCount??'').trim()==='')values.stockCount=null;
|
||||
@@ -1995,7 +2012,8 @@ document.addEventListener('click',async ev=>{
|
||||
}
|
||||
if(a==='split-cost'){const row=b.closest('.line-item'),unit=row.querySelector('[name="unit"]').value,payer=row.querySelector('[name="payer"]');row.dataset.legacy='false';payer.closest('label').remove();row.querySelector('.cost-fields').innerHTML=costFields({material:'',labor:'',accessories:'0',other:'0'},'cost-',true,{}, {mode:unit==='g'?'gram':'total'},{},unit,costPayerInput({payer:payer.value}),{compact:true,payer:payer.value,...(row.closest('#order-form')?{poolLine:{payer:payer.value}}:{})});updateTotal();return loadMaterialPoolChoices();}
|
||||
if(a==='add-fee'){$('#fee-rows').insertAdjacentHTML('beforeend',feeRowHTML({key:'manual:'+crypto.randomUUID(),note:'其他费用',amount:'',payer:teamDefaultPayer(),status:'estimated',edited:true}));return updateTotal();}
|
||||
if(a==='remove-fee'){b.closest('.fee-row').remove();return updateTotal();}
|
||||
if(a==='remove-fee'){removeFeeRow(b.closest('.fee-row'));return updateTotal();}
|
||||
if(a==='restore-charge-cost'){setChargeCostRemoved(b.closest('.charge-row'),false);return updateTotal();}
|
||||
if(a==='add-charge'){const list=b.closest('.line-item').querySelector('.charge-list');if(list.children.length>=100)throw new Error('每行最多填写100项附加项目');list.insertAdjacentHTML('beforeend',chargeHTML());return updateTotal();}
|
||||
if(a==='remove-charge'){b.closest('.charge-row').remove();return updateTotal();}
|
||||
if(a==='add-line'){$('#lines').insertAdjacentHTML('beforeend',lineHTML({},$('#lines').children.length+1,{materialPool:!!b.closest('#order-form')}));if(typeof loadReturnedStockLots==='function')loadReturnedStockLots();return updateTotal();}
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
for(const item of raw){
|
||||
if(!item||typeof item!=='object')throw new Error('附加项目格式无效');
|
||||
const id=item.id==null?'':String(item.id);if(id&&!/^[a-f0-9-]{36}$/.test(id))throw new Error('附加项目标识无效');
|
||||
if(item.costRemoved!==undefined&&typeof item.costRemoved!=='boolean')throw new Error('内部成本移除标记无效');
|
||||
const blank=item.amount==null||item.amount==='';const name=String(item.name??'').trim();
|
||||
if(blank&&(!id||!name))continue;
|
||||
if(!name||name.length>40)throw new Error('附加项目名称须为1~40字');
|
||||
const amount=blank?null:cents(item.amount,'附加项目金额');items.push({...(id?{id}:{}),name,amount});total+=amount||0;
|
||||
const amount=blank?null:cents(item.amount,'附加项目金额');items.push({...(id?{id}:{}),name,amount,...(item.costRemoved===true?{costRemoved:true}:{})});total+=amount||0;
|
||||
}
|
||||
if(total>100000000000)throw new Error('附加项目合计超出支持范围');
|
||||
return {items,total};
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
const remaining=existing.map(r=>({...r})),linked=[];
|
||||
for(const [index,line] of lines.entries())for(const charge of line.charges||[]){
|
||||
const name=String(charge.name||'').trim();if(!charge.id||!name)continue;
|
||||
if(charge.costRemoved===true)continue;
|
||||
const normalized=normalize(name);
|
||||
if(checkboxCosts&&checkboxCategory(name))continue;
|
||||
// 快递默认按整单一笔,不能因多件商品重复生成运费。
|
||||
@@ -62,7 +63,8 @@
|
||||
}
|
||||
const managedKeys=new Set(lines.flatMap(line=>(line.charges||[]).filter(charge=>checkboxCategory(charge.name)).map(charge=>'charge:'+charge.id)));
|
||||
const manual=remaining.filter(r=>!r.key.startsWith('charge:')||checkboxCosts&&(checkboxCategory(r.sourceName||r.note)||managedKeys.has(r.key)));
|
||||
if(addShipping&&!checkboxCosts&&!manual.some(r=>r.key==='shipping'))manual.unshift({key:'shipping',note:'快递费',amount:configured['快递'],payer:defaultPayer,status:'estimated',edited:false});
|
||||
const removedShipping=lines.some(line=>(line.charges||[]).some(charge=>charge.costRemoved===true&&normalize(String(charge.name||'').trim())==='快递'));
|
||||
if(addShipping&&!checkboxCosts&&!removedShipping&&!manual.some(r=>r.key==='shipping'))manual.unshift({key:'shipping',note:'快递费',amount:configured['快递'],payer:defaultPayer,status:'estimated',edited:false});
|
||||
return [...manual,...linked];
|
||||
}
|
||||
const api={sync,defaults,normalize,checkboxCategory,boxCount,presetKind,checkboxFees};if(typeof module==='object'&&module.exports)module.exports=api;else root.FeeEstimates=api;
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
}
|
||||
const completed=['delivered','returned','cancelled'].includes(order.status);
|
||||
for(const [index,line] of lines.entries())for(const charge of line.charges){
|
||||
if(charge.costRemoved===true)continue;
|
||||
const shipping=Fees.normalize(charge.name)==='快递',key=shipping?'shipping':'charge:'+charge.id;
|
||||
if(items.some(item=>item.key===key))continue;
|
||||
const found=items.find(item=>item.key.startsWith('manual:')&&Fees.normalize(item.note)===Fees.normalize(charge.name));
|
||||
@@ -61,7 +62,7 @@
|
||||
const source=inputs(order),chargeIds=new Map(),locked=!!order.price_lock_id||order.lines.some(line=>line.materialAllocations?.length);
|
||||
const lines=source.lines.map(line=>{
|
||||
const result=Object.fromEntries(['name','nameType','customName','unit','quantity','pocket','stockCount','payer','pricingMode','goldPrice','laborMode','laborRate','pieces','priceNote','sale','baseSale'].filter(key=>Object.hasOwn(line,key)).map(key=>[key,line[key]]));
|
||||
result.charges=line.charges.map(charge=>{const id=newId();if(charge.id)chargeIds.set(charge.id,id);return {id,name:charge.name,amount:charge.amount};});
|
||||
result.charges=line.charges.map(charge=>{const id=newId();if(charge.id)chargeIds.set(charge.id,id);return {id,name:charge.name,amount:charge.amount,...(charge.costRemoved===true?{costRemoved:true}:{})};});
|
||||
if(line.costParts){
|
||||
result.costParts={...line.costParts};result.costMaterial={...line.costMaterial};result.costLabor={...line.costLabor};
|
||||
result.costPayers={material:line.costPayers?.material??line.payer??'owner',labor:line.costPayers?.labor??line.payer??'owner'};
|
||||
|
||||
@@ -45,10 +45,11 @@
|
||||
result.charges=rawCharges.map(rawCharge=>{
|
||||
const c=object(rawCharge,'附加项目'),old=string(c.id,'附加项目标识',36);if(old&&(!uuid.test(old)||seen.has(old)))throw new Error('附加项目标识无效或重复');if(old)seen.add(old);
|
||||
const name=string(c.name,'附加项目名称',40),nameType=pick(c.nameType,[...charges,'其他'],'附加项目',charges.includes(name)?name:name?'其他':'编绳');
|
||||
if(c.costRemoved!==undefined&&typeof c.costRemoved!=='boolean')throw new Error('内部成本移除标记无效');
|
||||
const id=newId();if(old)ids.set(old,id);
|
||||
const customName=string(c.customName??(nameType==='其他'?name:''),'附加项目名称',40),amount=numeric(c.amount,'附加金额');
|
||||
const prices={};if(c.chargePrices!=null){object(c.chargePrices,'附加项目预设报价');for(const key of [...charges,'其他'])if(Object.hasOwn(c.chargePrices,key))prices[key]=numeric(c.chargePrices[key],'附加项目报价');}
|
||||
return {id,nameType,customName,name:nameType==='其他'?customName:nameType,amount,chargePrices:{...prices,[nameType]:amount}};
|
||||
return {id,nameType,customName,name:nameType==='其他'?customName:nameType,amount,chargePrices:{...prices,[nameType]:amount},...(c.costRemoved===true?{costRemoved:true}:{})};
|
||||
});
|
||||
if(line.costParts!=null){
|
||||
object(line.costParts,'分项成本');const parts=Object.fromEntries(['material','labor','accessories','other'].map(key=>[key,numeric(line.costParts[key],'货品成本')]));
|
||||
|
||||
Reference in new issue
Block a user