Created
July 23, 2020 08:40
-
-
Save Lunberg88/4847cc6b9337c5df1c875302ebe6262f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
methods: { | |
checkParams(params, model, selection) { | |
// Searching params | |
let searching = { | |
arrival: params.arrival, | |
departure: params.departure, | |
propertyId: parseInt(params.propertyID), | |
rooms: parseInt(params.rooms), | |
}; | |
// Persisted object | |
let persisted = { | |
arrival: model.startDate, | |
departure: model.endDate, | |
propertyId: parseInt(model.propertyId), | |
rooms: selection.length, | |
}; | |
let persistedOccupancy = {adult: 0, children: []}; | |
selection.forEach((room) => { | |
persistedOccupancy.adult += room.adult; | |
room.child.forEach(ch => persistedOccupancy.children.push(ch.age)) | |
}); | |
persisted.adults = persistedOccupancy.adult; | |
persisted.child = persistedOccupancy.children; | |
// Searching params | |
let searchOccupancy = {adult: 0, children: []}; | |
for (let x = 0; x < params.rooms; x++) { | |
let adultNum = params[`r${x + 1}a`]; | |
searchOccupancy.adult += parseInt(adultNum); | |
// Children | |
Object.keys(params).find((key) => { | |
let regex = new RegExp(`c${x + 1}`, 'gi'); | |
if (key.match(regex)) { | |
searchOccupancy.children.push(parseInt(params[key])); | |
} | |
}); | |
} | |
searching.adult = searchOccupancy.adult; | |
searching.child = searchOccupancy.children; | |
return JSON.stringify(searching) === JSON.stringify(persisted); | |
}, | |
// Search | |
async updateSearchByRouteParams(params) {...} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment