Javascript allows you to get different prices per day for a date segment (calculate the total price of your stay) and the total price of javascript
Code example
I recently encountered such a problem when developing a hotel mini-program project.
The price of a hotel room varies by hour or a special date. If you select a house for the next five days, and the prices for the past five days are not the same, there will be a special day price, how to calculate a total price for the next five days?
The following example lists all the dates in this date segment based on the check-in date and departure date:
You can use this function in a few places, so you need to encapsulate it: Create a js file separately.
Function Thedatefor (times, objroom) {// Date segment objroom price list, there are weeks and special dates var dateObj = [] var feoom = [] // calculated total price list var str = times [0]. split ("-") // check-in date var end = times [1]. split ("-") // departure Date var strs = new Date (); strs. setUTCFullYear (str [0], str [1]-1, str [2]); // set the year var ends = new Date (); ends. setUTCFullYear (end [0], end [1]-1, end [2]); // set the year var strdate = strs. getTime (); // millisecond var enddate = ends. getT Ime (); // millisecond for (var B = strdate; B <= enddate;) {// traverse all date segments dateObj. push (new Date (parseInt (B ))). format (). toString (); B = B + 24*60x60*1000;} for (var B = 0; B <dateObj. length; B ++) {// all dates obtained by dateObj var timedate = dateAllArr [B]. split ("-") var getDays = new Date (dateObj [B]). getDay () = 0? 7: new Date (dateObj [B]). getDay () // you can convert it to the for (var h = 0; h <(objroom. length-1); h ++) {if (parseInt (timedate [0] + timedate [1] + timedate [2]) = objroom [h]. match) {// compare the feoom of a special day. push ({response: objroom [h]. hour, date: dateObj [B]})} // obtain the daily price based on the day of the week and the special date if (getDays = objroom [h]. match) {// compare feoom of the week. push ({response: objroom [h]. expiration, date: dateObj [B]}) }}return feoom // The final list of daily prices and return date}
Times is passed in the check-in date and departure date format: '[2018-01-20, 2018-01-26]', objroom is a daily price list for this room for the next week.
Summary
The above section describes how to use javascript to obtain different daily prices for a specific date segment (calculate the total price). I hope this will help you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!