64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
import store from "@/store";
|
|
import baseMixin from "@/mixins/base-mixin.js";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
|
|
export function getDamageString() {
|
|
const damageLocations = store.getters.damage.glassToReplace;
|
|
const isRepair = store.getters.damage.isRepair;
|
|
|
|
let returnString;
|
|
if (!damageLocations) {
|
|
return;
|
|
}
|
|
// If it's a repair it's always a windshield.
|
|
if(isRepair){
|
|
return "windshield"
|
|
}
|
|
|
|
if (damageLocations.length > 1) {
|
|
returnString = "match"
|
|
} else {
|
|
switch(damageLocations[0]?.location) {
|
|
case "Windshield":
|
|
returnString = "windshield"
|
|
break;
|
|
case "Driver":
|
|
case "Passenger":
|
|
returnString = "side window"
|
|
break;
|
|
case "Rear":
|
|
returnString = "rear window"
|
|
}
|
|
}
|
|
return returnString;
|
|
}
|
|
|
|
export function getIsWindshieldOnly () {
|
|
const damageLocations = store.getters.damage.glassToReplace;
|
|
const returnString = damageLocations.length === 1 && damageLocations[0]?.location === "Windshield" ? "windshield" : "glass";
|
|
return returnString;
|
|
}
|
|
|
|
export async function isGlassAvailableForCarId(carId){
|
|
const newGlassOptions = await baseMixin.methods.dispatchStoreAction(
|
|
storeActions.GET_DAMAGE_OPTIONS,
|
|
{ carId: carId }
|
|
);
|
|
|
|
const currentGlassOptions = store.getters.damage.glassToReplace;
|
|
|
|
const optionsMap = {
|
|
Windshield: "windshieldOptions",
|
|
Driver: "driverSideOptions",
|
|
Passenger: "passengerSideOptions",
|
|
Rear: "backGlassOptions"
|
|
}
|
|
|
|
for(const option of currentGlassOptions){
|
|
if(!newGlassOptions.data[optionsMap[option.location]].availableReplacementOptions.includes(option.name)){
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|