保存同行基础版:店铺配置与员工管理
This commit is contained in:
1 parent
ecb8d6dec0
commit
b7b987064b
84 files changed
+1884
-573
No files matched your search
@@ -2,7 +2,7 @@
|
||||
// 助理修改已保存订单时先留申请;复核通过才由服务端更正原单。
|
||||
let orderChangeDetail=null,orderChangeFormEntry=null,orderActionChangeEntry=null;
|
||||
let orderChangeCountRequest=0,orderChangeListRequest=0,orderChangeListStatus='pending';
|
||||
const orderChangeStatus={pending:'待麦麦复核',approved:'已同意变更',rejected:'已驳回'};
|
||||
const orderChangeStatus={pending:'待店主复核',approved:'已同意变更',rejected:'已驳回'};
|
||||
const orderChangeActionLabels={edit:'修改订单',expense:'费用补记',fees:'旧费用核实',refund:'退款',return:'退货',cost:'成本补录'};
|
||||
function orderChangeActionLabel(request){if((request.action_input||request.action_details)?.afterSale)return '处理订单售后';return request.action_label||orderChangeActionLabels[request.action||'edit']||'订单变更';}
|
||||
function orderActionUsesChangeForm(kind){return state.user.role==='assistant'&&['expense','fees','refund','return','cost'].includes(kind);}
|
||||
@@ -56,10 +56,10 @@ function orderChangeDetailHTML(order){
|
||||
if(!data)return `<section class="panel order-change-panel"><h2>变更申请与复核</h2><p class="${entry?.error?'danger-text':'muted'}" role="status">${e(entry?.error||'变更申请资料尚未读取,请先重新读取订单。')}</p>${button('重新读取订单','reload-order-change','',`data-id="${e(order.id)}"`)}</section>`;
|
||||
if(!request&&!data.requests.length)return '';
|
||||
const canReview=state.user.role==='owner'&&data.canApprove&&request?.status==='pending';
|
||||
return `<section class="panel order-change-panel" id="order-change-panel"><div class="panel-title"><h2>变更申请与复核</h2>${request?'<span class="badge warn">待麦麦复核</span>':''}</div>${request?`<p><strong>本次申请:${e(orderChangeActionLabel(request))}。</strong>申请期间仍按原订单计账,本次申请尚未生效。麦麦同意后才更新原单;复核完成前暂停本单其他记账和取消申请。</p>${request.stale?'<div class="error" role="status">订单在申请后已有变动,原申请不能同意。请麦麦驳回后按最新订单重新申请。</div>':''}${canReview?`<div class="actions">${!request.stale?button('查看变更并复核','approve-order-change','primary',`data-id="${e(request.id)}"`):''}${button('驳回变更申请','reject-order-change','',`data-id="${e(request.id)}"`)}</div>`:'<p class="small muted">由麦麦账号核对原值与申请值后复核。</p>'}`:''}<details ${request?'open':''}><summary>变更申请与复核记录(${data.requests.length})</summary><ul class="timeline change-history">${data.requests.map(orderChangeHistoryHTML).join('')}</ul></details></section>`;
|
||||
return `<section class="panel order-change-panel" id="order-change-panel"><div class="panel-title"><h2>变更申请与复核</h2>${request?'<span class="badge warn">待店主复核</span>':''}</div>${request?`<p><strong>本次申请:${e(orderChangeActionLabel(request))}。</strong>申请期间仍按原订单计账,本次申请尚未生效。店主同意后才更新原单;复核完成前暂停本单其他记账和取消申请。</p>${request.stale?'<div class="error" role="status">订单在申请后已有变动,原申请不能同意。请店主驳回后按最新订单重新申请。</div>':''}${canReview?`<div class="actions">${!request.stale?button('查看变更并复核','approve-order-change','primary',`data-id="${e(request.id)}"`):''}${button('驳回变更申请','reject-order-change','',`data-id="${e(request.id)}"`)}</div>`:'<p class="small muted">由店主账号核对原值与申请值后复核。</p>'}`:''}<details ${request?'open':''}><summary>变更申请与复核记录(${data.requests.length})</summary><ul class="timeline change-history">${data.requests.map(orderChangeHistoryHTML).join('')}</ul></details></section>`;
|
||||
}
|
||||
function orderChangeMoney(value){return value==null?'待补齐':'¥'+yuan(value);}
|
||||
function orderChangePayer(value){return ({owner:'麦麦',assistant:'娜娜',assistant2:'小昊'})[value]||'待补齐';}
|
||||
function orderChangePayer(value){return value?teamMemberName(value):'待补齐';}
|
||||
function orderChangeCell(value){return e(value==null||value===''?'未填写':value).replace(/\n/g,'<br>');}
|
||||
function orderChangePair(title,before,after){const changed=String(before??'')!==String(after??'');return `<tr${changed?' class="order-change-modified"':''}><th scope="row">${e(title)}${changed?'<span class="change-mark">已修改</span>':''}</th><td>${orderChangeCell(before)}</td><td>${orderChangeCell(after)}</td></tr>`;}
|
||||
function orderChangeLineValue(line,kind){
|
||||
@@ -135,7 +135,7 @@ function requireOrderChangeDetail(){
|
||||
if(pending())throw new Error('请先点击顶部“恢复原操作”,确认上次提交结果后再处理修改申请。');
|
||||
const order=currentOrder,entry=currentOrderChange(order);
|
||||
if(!order||!entry?.data||entry.error)throw new Error('请重新读取订单并核对修改申请。');
|
||||
if(typeof orderOwnershipPending==='function'?orderOwnershipPending(order):order.ownershipPending)throw new Error('归属申请待麦麦复核,请处理完成后再修改订单。');
|
||||
if(typeof orderOwnershipPending==='function'?orderOwnershipPending(order):order.ownershipPending)throw new Error('归属申请待店主复核,请处理完成后再修改订单。');
|
||||
return {order,entry,data:entry.data};
|
||||
}
|
||||
function prepareOrderActionChange(kind){
|
||||
@@ -148,7 +148,7 @@ function orderActionChangeReviewHTML(kind){
|
||||
const approval=orderActionRequiresApproval(kind);
|
||||
return `<div class="note" id="order-action-mode" aria-live="polite">${orderActionModeText(kind,approval)}</div>${kind==='return'?'':`<label><span id="order-action-reason-label">${approval?'申请原因':'登记原因'}</span><textarea name="change_reason" maxlength="200" rows="2" required placeholder="写清本次需要登记或更正的原因。"></textarea></label>`}${['cost','expense'].includes(kind)?'<label class="check"><input type="checkbox" name="verified" required>已核实本次金额、实际付款人与凭据一致。</label>':''}<div id="order-action-change-error" aria-live="polite"></div>`;
|
||||
}
|
||||
function orderActionModeText(kind,approval){return approval?`本次提交${e(orderChangeActionLabels[kind])}申请。麦麦同意后才记账;待批期间原订单、收退款、费用、库存和利润均不变。系统不会发起真实付款。`:'原单与本次业务日期均为今天,核实后直接记账,无需麦麦审批。改为其他业务日期须提交申请。系统不会发起真实付款。';}
|
||||
function orderActionModeText(kind,approval){return approval?`本次提交${e(orderChangeActionLabels[kind])}申请。店主同意后才记账;待批期间原订单、收退款、费用、库存和利润均不变。系统不会发起真实付款。`:'原单与本次业务日期均为今天,核实后直接记账,无需店主审批。改为其他业务日期须提交申请。系统不会发起真实付款。';}
|
||||
function syncOrderActionChangeMode(){
|
||||
const form=$('#action-form[data-order-change="true"]'),entry=orderActionChangeEntry;if(!form||!entry)return;
|
||||
const approval=orderActionRequiresApproval(entry.kind,form.querySelector('[name="date"]')?.value||state.today),direct=String(!approval),changed=form.dataset.orderDirect!==undefined&&form.dataset.orderDirect!==direct;
|
||||
@@ -173,7 +173,7 @@ function orderActionChangeError(err,operation=null){
|
||||
orderActionChangeEntry.forceApproval=true;orderActionChangeEntry.submittedDirect=false;
|
||||
const checkbox=$('#action-form[data-order-change="true"] [name="verified"]');if(checkbox)checkbox.checked=false;
|
||||
syncOrderActionChangeMode();
|
||||
const message=err.message+' 输入已保留,请重新核实后提交麦麦审批。',target=$('#order-action-change-error')||$('#detail-error');
|
||||
const message=err.message+' 输入已保留,请重新核实后提交店主审批。',target=$('#order-action-change-error')||$('#detail-error');
|
||||
if(target)target.innerHTML=`<div class="error">${e(message)}</div>`;
|
||||
applyOrderActionChangeRestrictions();toast(message,true);return;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ async function submitOrderActionChange(form,input){
|
||||
function showOrderChangeForm(kind){
|
||||
const {order,data}=requireOrderChangeDetail(),request=data.pending;
|
||||
if(!['approve','reject'].includes(kind))throw new Error('修改复核操作无效,请重新读取订单。');
|
||||
if(state.user.role!=='owner'||!data.canApprove||request?.status!=='pending')throw new Error('修改申请由麦麦账号复核。');
|
||||
if(state.user.role!=='owner'||!data.canApprove||request?.status!=='pending')throw new Error('修改申请由店主账号复核。');
|
||||
if(kind==='approve'&&(!request.canApprove||request.stale||request.order_revision!==order.revision))throw new Error('订单已有变动,请重新读取后复核;过期申请需驳回后重新申请。');
|
||||
orderChangeFormEntry={kind,id:order.id,user:orderChangeUser(),revision:order.revision,requestId:request.id,requestRevision:request.order_revision};
|
||||
const reason=`<p><strong>本次申请:${e(orderChangeActionLabel(request))}</strong></p><p>申请人:${e(request.requester_name)} · ${e(orderChangeTime(request.created))}</p><p class="change-reason">申请原因:${e(request.reason)}</p>`;
|
||||
@@ -235,7 +235,7 @@ function orderChangeError(err,operation=null){
|
||||
async function submitOrderChange(form){
|
||||
const {order,data}=requireOrderChangeDetail(),entry=orderChangeFormEntry;
|
||||
if(form!==$('#order-change-form')||!entry||entry.id!==order.id||entry.user!==orderChangeUser()||entry.revision!==order.revision)throw new Error('请重新读取订单后核对修改申请。');
|
||||
const request=data.pending;if(state.user.role!=='owner'||!data.canApprove||request?.status!=='pending'||request.id!==entry.requestId)throw new Error('修改申请由麦麦账号复核,请重新读取。');
|
||||
const request=data.pending;if(state.user.role!=='owner'||!data.canApprove||request?.status!=='pending'||request.id!==entry.requestId)throw new Error('修改申请由店主账号复核,请重新读取。');
|
||||
const note=String(form.querySelector('[name="note"]')?.value||'').trim();if(note.length>200||entry.kind==='reject'&&!note)throw new Error(entry.kind==='reject'?'驳回意见请填写1~200字。':'复核备注最多200字。');
|
||||
let input={note};
|
||||
if(entry.kind==='approve'){
|
||||
@@ -249,7 +249,7 @@ async function submitOrderChange(form){
|
||||
}
|
||||
async function finishOrderChangeSave(url,input,result,detailContext=captureOrderDetailReload(result.id||result.order?.id)){
|
||||
const operation=orderChangeOperation(url),id=result.id||result.order?.id||operation?.orderId;if(!id)throw new Error('操作已保存,请重新读取订单列表查看结果。');
|
||||
const actionLabel=orderChangeActionLabel(result.request||{action:input.action||'edit'}),title=operation?.kind==='approve'?'已同意'+actionLabel+',原订单已更新':operation?.kind==='reject'?actionLabel+'申请已驳回':actionLabel+'申请已提交,等待麦麦复核';
|
||||
const actionLabel=orderChangeActionLabel(result.request||{action:input.action||'edit'}),title=operation?.kind==='approve'?'已同意'+actionLabel+',原订单已更新':operation?.kind==='reject'?actionLabel+'申请已驳回':actionLabel+'申请已提交,等待店主复核';
|
||||
const fromEdit=operation?.kind==='request'&&tab==='order-edit';
|
||||
if(operation?.kind==='request'&&typeof orderEditDraftKey==='function'){
|
||||
localStorage.removeItem(orderEditDraftKey(id));if(localStorage.getItem(orderEditActiveKey())===id)localStorage.removeItem(orderEditActiveKey());
|
||||
@@ -285,7 +285,7 @@ async function openOrderChanges(status='pending'){
|
||||
orderChangeListStatus=Object.hasOwn(orderChangeStatus,status)||status==='all'?status:'pending';
|
||||
let dialog=$('#order-changes-dialog');
|
||||
if(!dialog){dialog=document.createElement('dialog');dialog.id='order-changes-dialog';dialog.setAttribute('aria-labelledby','order-changes-title');dialog.addEventListener('cancel',()=>{++orderChangeListRequest;});document.body.append(dialog);}
|
||||
dialog.innerHTML=`<button class="dialog-close" data-action="close-order-changes" aria-label="关闭变更申请列表">×</button><h2 id="order-changes-title">变更申请与复核</h2><p class="small muted">全部日期,不受订单页的日期、搜索或状态筛选影响。待批期间仍按原订单计账,包含改单、费用、成本、退款与退货;麦麦同意后才更新原单。</p><div id="order-changes-list" aria-live="polite" aria-busy="true">正在读取…</div>`;
|
||||
dialog.innerHTML=`<button class="dialog-close" data-action="close-order-changes" aria-label="关闭变更申请列表">×</button><h2 id="order-changes-title">变更申请与复核</h2><p class="small muted">全部日期,不受订单页的日期、搜索或状态筛选影响。待批期间仍按原订单计账,包含改单、费用、成本、退款与退货;店主同意后才更新原单。</p><div id="order-changes-list" aria-live="polite" aria-busy="true">正在读取…</div>`;
|
||||
if(!dialog.open)dialog.showModal();return await loadOrderChanges();
|
||||
}
|
||||
async function loadOrderChanges(){
|
||||
|
||||
Reference in new issue
Block a user