HelloSun commited on
Commit
32b0a73
·
verified ·
1 Parent(s): f4f7f6e

Fix: preview refresh after deposit suggestion + price column alignment

Browse files
Files changed (1) hide show
  1. index.html +8 -9
index.html CHANGED
@@ -610,9 +610,9 @@ function renderSettings(){
610
  <table class="tbl"><thead><tr><th>房號</th><th>房型</th><th class="num">平日價</th><th class="num">假日價(週五六)</th><th></th></tr></thead>
611
  <tbody>${DB.rooms.map((r,i)=>`<tr data-i="${i}">
612
  <td><input class="r-no" style="width:80px" value="${esc(r.roomNo)}"></td>
613
- <td><input class="r-type" style="width:150px" value="${esc(r.type)}"></td>
614
- <td><input class="r-wd" type="number" min="0" style="width:100px;text-align:right" value="${+r.wd}"></td>
615
- <td><input class="r-we" type="number" min="0" style="width:100px;text-align:right" value="${+r.we}"></td>
616
  <td><button class="btn mini danger" data-act="rdel" data-i="${i}">🗑️</button></td></tr>`).join('')}</tbody></table></div>
617
  <div class="mact" style="justify-content:flex-start"><button class="btn" id="roomAdd">+ 新增房型</button></div>
618
  <p class="hint">※ 房號變更不會自動更新既有訂單,請先確認。</p>
@@ -695,20 +695,19 @@ function openBookingModal(no){
695
  const ci=$('#f_checkin').value,co=$('#f_checkout').value,roomNo=$('#f_room').value;
696
  const tmp={roomNo,checkin:ci,checkout:co,extra:+$('#f_extra').value||0,discount:+$('#f_discount').value||0};
697
  const n=ci&&co?Math.max(0,diffDays(ci,co)):0,t=n?calcTotalOf(tmp):0;
 
698
  const rec=b&&b.no?receivedOf(b.no):0;
699
- const needPay=$('#f_status')&&$('#f_status').value==='已付訂'&&(!b||rec===0);
700
  const depAmt=needPay?(+$('#f_depAmt').value||0):0;
701
  const effRec=rec+depAmt;
702
  const conf=ci&&co?DB.bookings.some(x=>x.no!==exclNo&&x.roomNo===roomNo&&x.status!=='取消'&&x.checkin<co&&ci<x.checkout):false;
703
  $('#bkCalc').innerHTML=`晚數 <b>${n}</b> 晚|總價 <b>${fmtMoney(t)}</b>(含加項 − 折扣)|已收 ${fmtMoney(effRec)}${needPay?'(含此次訂金)':''}|應收 <b>${fmtMoney(Math.max(0,t-effRec))}</b>|可訂 <b>${availRooms(ci,co,exclNo).length}</b> / ${DB.rooms.length} 間${conf?'<br>⚠ 此房號與既有訂單日期重疊,儲存時將再確認':''}`;
704
- updPayWrap(t);
705
  };
706
  const updPayWrap=tHint=>{ // 設「已付訂」必須輸入實收訂金,不可直接設為已付訂
707
  const need=$('#f_status').value==='已付訂'&&(!b||receivedOf(b.no)===0);
708
  $('#f_payWrap').style.display=need?'':'none';
709
- if(need&&!$('#f_depAmt').value){
710
- const t=tHint||0;
711
- $('#f_depAmt').value=t?Math.max(100,Math.round(t*0.3/100)*100):'';
712
  }
713
  };
714
  const updRooms=()=>{ // 房號下拉只列出所選期間未被訂走的房間
@@ -720,7 +719,7 @@ function openBookingModal(no){
720
  };
721
  const exclNo=$('#f_no').value;
722
  ['f_checkin','f_checkout'].forEach(id=>$('#'+id).addEventListener('input',updRooms));
723
- ['f_room','f_extra','f_discount'].forEach(id=>$('#'+id).addEventListener('input',upd));
724
  $('#f_room').addEventListener('change',upd);
725
  $('#f_status').addEventListener('change',upd);
726
  updRooms();
 
610
  <table class="tbl"><thead><tr><th>房號</th><th>房型</th><th class="num">平日價</th><th class="num">假日價(週五六)</th><th></th></tr></thead>
611
  <tbody>${DB.rooms.map((r,i)=>`<tr data-i="${i}">
612
  <td><input class="r-no" style="width:80px" value="${esc(r.roomNo)}"></td>
613
+ <td><input class="r-type" style="width:100%" value="${esc(r.type)}"></td>
614
+ <td><input class="r-wd" type="number" min="0" style="width:100%;text-align:right" value="${+r.wd}"></td>
615
+ <td><input class="r-we" type="number" min="0" style="width:100%;text-align:right" value="${+r.we}"></td>
616
  <td><button class="btn mini danger" data-act="rdel" data-i="${i}">🗑️</button></td></tr>`).join('')}</tbody></table></div>
617
  <div class="mact" style="justify-content:flex-start"><button class="btn" id="roomAdd">+ 新增房型</button></div>
618
  <p class="hint">※ 房號變更不會自動更新既有訂單,請先確認。</p>
 
695
  const ci=$('#f_checkin').value,co=$('#f_checkout').value,roomNo=$('#f_room').value;
696
  const tmp={roomNo,checkin:ci,checkout:co,extra:+$('#f_extra').value||0,discount:+$('#f_discount').value||0};
697
  const n=ci&&co?Math.max(0,diffDays(ci,co)):0,t=n?calcTotalOf(tmp):0;
698
+ updPayWrap(t); // 先填入建議訂金,預覽才會即時反映
699
  const rec=b&&b.no?receivedOf(b.no):0;
700
+ const needPay=$('#f_status').value==='已付訂'&&(!b||rec===0);
701
  const depAmt=needPay?(+$('#f_depAmt').value||0):0;
702
  const effRec=rec+depAmt;
703
  const conf=ci&&co?DB.bookings.some(x=>x.no!==exclNo&&x.roomNo===roomNo&&x.status!=='取消'&&x.checkin<co&&ci<x.checkout):false;
704
  $('#bkCalc').innerHTML=`晚數 <b>${n}</b> 晚|總價 <b>${fmtMoney(t)}</b>(含加項 − 折扣)|已收 ${fmtMoney(effRec)}${needPay?'(含此次訂金)':''}|應收 <b>${fmtMoney(Math.max(0,t-effRec))}</b>|可訂 <b>${availRooms(ci,co,exclNo).length}</b> / ${DB.rooms.length} 間${conf?'<br>⚠ 此房號與既有訂單日期重疊,儲存時將再確認':''}`;
 
705
  };
706
  const updPayWrap=tHint=>{ // 設「已付訂」必須輸入實收訂金,不可直接設為已付訂
707
  const need=$('#f_status').value==='已付訂'&&(!b||receivedOf(b.no)===0);
708
  $('#f_payWrap').style.display=need?'':'none';
709
+ if(need&&!$('#f_depAmt').value&&tHint){
710
+ $('#f_depAmt').value=Math.max(100,Math.round(tHint*0.3/100)*100);
 
711
  }
712
  };
713
  const updRooms=()=>{ // 房號下拉只列出所選期間未被訂走的房間
 
719
  };
720
  const exclNo=$('#f_no').value;
721
  ['f_checkin','f_checkout'].forEach(id=>$('#'+id).addEventListener('input',updRooms));
722
+ ['f_room','f_extra','f_discount','f_depAmt'].forEach(id=>$('#'+id).addEventListener('input',upd));
723
  $('#f_room').addEventListener('change',upd);
724
  $('#f_status').addEventListener('change',upd);
725
  updRooms();