Facebook
From Baby Butterfly, 4 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 58
  1. function calcUberFee() {
  2.   var km = document.getElementById("txtKm").value;
  3.   var waitingTime = document.getElementById("txtWaitingTime").value;
  4.   var uberType = "";
  5.   var total = 0;
  6.  
  7.   km = parseFloat(km);
  8.   waitingTime = parseFloat(waitingTime);
  9.  
  10.   var uberXInput = document.getElementById("uberX");
  11.   var uberSUVInput = document.getElementById("uberSUV");
  12.   var uberBlackInput = document.getElementById("uberBlack");
  13.  
  14.   var ele = document.getElementsByName("selector");
  15.   for (i = 0; i < ele.length; i++) {
  16.     if (ele[i].checked) uberType = ele[i].id;
  17.   }
  18.  
  19.   switch (uberType) {
  20.     case "uberX":
  21.       kmFirst = 8000;
  22.       kmBelow21 = 12000;
  23.       kmUpper21 = 10000;
  24.       waitFee = 2000;
  25.  
  26.       break;
  27.     case "uberSUV":
  28.       kmFirst = 9000;
  29.       kmBelow21 = 14000;
  30.       kmUpper21 = 12000;
  31.       waitFee = 3000;
  32.  
  33.       break;
  34.     case "uberBlack":
  35.       kmFirst = 10000;
  36.       kmBelow21 = 16000;
  37.       kmUpper21 = 14000;
  38.       waitFee = 4000;
  39.  
  40.       break;
  41.     default:
  42.       alert("Vui lòng chọn loại xe");
  43.   }
  44.  
  45.   total = caclTotal(km);
  46.  
  47.   function caclTotal(km) {
  48.     if (km <= 1) {
  49.       total = kmFirst + waitingTime * waitFee;
  50.     } else if (km <= 21) {
  51.       total = kmFirst + (km - 1) * kmBelow21 + waitingTime * waitFee;
  52.     } else {
  53.       total =
  54.         kmFirst +
  55.         20 * kmBelow21 +
  56.         (km - 21) * kmBelow21 +
  57.         waitingTime * waitFee;
  58.     }
  59.     return total;
  60.   }
  61.  
  62.   //   document.getElementsByClassName("result").innerHTML = alert(total);
  63.   document.getElementById("xuatTien").innerHTML = total.toLocaleString();
  64.   document.getElementById("divThanhTien").style.display = "block";
  65.  
  66.   console.log(total);
  67. }