447 lines
19 KiB
Vue
447 lines
19 KiB
Vue
<template>
|
|
<Form
|
|
ref="theForm"
|
|
v-slot="{ meta }"
|
|
@submit="onSubmit"
|
|
@invalidSubmit="onInvalidSubmit">
|
|
<div class="page-container-grouped-styles">
|
|
<div class="fade-on-route-transition position-relative">
|
|
<siteHeader cmsWidgetName="SiteHeaderWidget" />
|
|
<div class="container-fluid pb-2">
|
|
<div class="row mt-2 px-3">
|
|
<div class="col">
|
|
<alert
|
|
v-if="shouldDisplayVehicleChangeAlert"
|
|
ref="vehicleChangeAlert"
|
|
class="mt-5 mb-0"
|
|
cmsWidgetName="VehicleChangeAlert"
|
|
alertClass="alert-warning"
|
|
:isDismissible="false" />
|
|
<vehicleBanner
|
|
class="mb-4"
|
|
cmsWidgetName="VehicleBannerWidget"
|
|
:displayGenericVehicleImage="false" />
|
|
<siteSubHeader cmsWidgetName="SiteSubHeaderWidget" />
|
|
<damageLocationQuestion
|
|
ref="damageLocation"
|
|
v-model="selectedDamageLocations"
|
|
cmsWidgetName="DamageLocationQuestion"
|
|
groupName="DamageLocationQuestion" />
|
|
<windshieldOptions
|
|
ref="windshieldOptions"
|
|
v-model="selectedWindshieldOptions"
|
|
:hasRepairReplaceConflict="hasRepairReplaceConflict"
|
|
:hasSplitSingleConflict="hasSplitSingleConflict"
|
|
:selectedDamageLocations="selectedDamageLocations"
|
|
class="mb-3" />
|
|
<alert
|
|
v-if="hasRepairReplaceConflict"
|
|
class="my-5"
|
|
cmsWidgetName="HasReplacementConflict"
|
|
alertClass="alert-danger"
|
|
:isDismissible="false" />
|
|
<sideDoorOptions
|
|
v-show="!hasRepairReplaceConflict"
|
|
ref="sideDoorOptions"
|
|
v-model="sideDoorOptionsData"
|
|
cmsWidgetName="SideDoorSideQuestion"
|
|
groupName="SideDoorSideQuestion"
|
|
:selectedDamageLocations="selectedDamageLocations"
|
|
class="mb-1" />
|
|
<replaceOptionsQuestion
|
|
ref="backGlassOptions"
|
|
v-model="selectedRearReplaceOptions"
|
|
cmsWidgetName="RearReplaceOptionsQuestion"
|
|
:isAvailable="isRearWindowDamageLocation && !hasRepairReplaceConflict"
|
|
groupName="BackGlassReplaceOptionsQuestion"
|
|
validationRules="replace-options-required" />
|
|
<site-footer
|
|
ref="siteFooter"
|
|
class="mt-5"
|
|
cmsWidgetName="SiteFooterWidget"
|
|
:isForwardActionDisabled="!meta.valid"
|
|
@backClicked="backButtonAction"
|
|
@forwardClicked="forwardButtonAction" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Form>
|
|
</template>
|
|
|
|
<script>
|
|
// Components
|
|
import siteHeader from '@/iss-components/site-header/site-header.vue';
|
|
import siteFooter from '@/iss-components/site-footer/site-footer.vue';
|
|
import vehicleBanner from '@/iss-components/vehicle-banner/vehicle-banner.vue';
|
|
import siteSubHeader from '@/iss-components/site-sub-header/site-sub-header.vue';
|
|
import sideDoorOptions from '@/layouts/vehicle-damage/side-door-options/side-door-options.vue';
|
|
import damageLocationQuestion from '@/layouts/vehicle-damage/damage-location-question/damage-location-question.vue';
|
|
import windshieldOptions from '@/layouts/vehicle-damage/windshield-options/windshield-options.vue';
|
|
import replaceOptionsQuestion from '@/layouts/vehicle-damage/replace-options-question/replace-options-question.vue';
|
|
import alert from '@/ux-components/alert/alert.vue';
|
|
|
|
// Supporting files
|
|
import BaseFormMixin from '@/mixins/base-form-mixin.js';
|
|
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
|
|
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
|
|
import settleAllPromises from '@/helpers/layout-helper';
|
|
import { Form, defineRule } from 'vee-validate';
|
|
import { required } from '@/helpers/validation-rules';
|
|
import errorMessages from '@/constants/error-messages';
|
|
import damageLocationsCms from '@/constants/damage-locations-cms.js';
|
|
import damageLocationsSelected from '@/constants/damage-locations-selected.js';
|
|
import { useMainStore } from '@/store';
|
|
|
|
// DEFINE VALIDATION RULES
|
|
defineRule('replace-options-required', required(errorMessages.REPLACE_OPTIONS_REQUIRED));
|
|
|
|
export default {
|
|
name: 'vehicle-damage',
|
|
|
|
components: {
|
|
siteHeader,
|
|
siteFooter,
|
|
vehicleBanner,
|
|
siteSubHeader,
|
|
sideDoorOptions,
|
|
damageLocationQuestion,
|
|
windshieldOptions,
|
|
replaceOptionsQuestion,
|
|
// eslint-disable-next-line vue/no-reserved-component-names
|
|
Form,
|
|
alert
|
|
},
|
|
mixins: [BaseFormMixin, vehicleQuestionsMixin],
|
|
async beforeRouteEnter(to, from, next) {
|
|
const store = useMainStore();
|
|
|
|
// Call APIs
|
|
const cmsContentPromise = fetchCmsContentForPage(to.query.issPage);
|
|
const damageOptionsPromise = store.getDamageOptions(store.order.vehicle.carId);
|
|
|
|
// Settle promises and get results
|
|
const promiseResultMap = [
|
|
{
|
|
resultKey: 'cmsContent',
|
|
promise: cmsContentPromise
|
|
},
|
|
{
|
|
resultKey: 'damageOptions',
|
|
promise: damageOptionsPromise
|
|
}
|
|
];
|
|
|
|
const resultMap = await settleAllPromises(promiseResultMap);
|
|
|
|
// Call the "next" function to complete the transition to this page.
|
|
next((vm) => {
|
|
vm.setCmsContent(resultMap.cmsContent);
|
|
vm.$refs.damageLocation.initializeComponent(resultMap.damageOptions);
|
|
vm.$refs.sideDoorOptions.initializeComponent(
|
|
resultMap.damageOptions.driverSideOptions.availableReplacementOptions,
|
|
resultMap.damageOptions.passengerSideOptions.availableReplacementOptions
|
|
);
|
|
vm.$refs.windshieldOptions.initializeComponent(resultMap.damageOptions.windshieldOptions.availableReplacementOptions);
|
|
vm.$refs.backGlassOptions.initializeComponent(resultMap.damageOptions.backGlassOptions.availableReplacementOptions);
|
|
});
|
|
},
|
|
setup() {
|
|
const mainStore = useMainStore();
|
|
|
|
return { mainStore };
|
|
},
|
|
data() {
|
|
return {
|
|
selectedDamageLocations: this.getDamageLocationsFromStore(),
|
|
sideDoorOptionsData: {
|
|
selectedDoorSides: this.getDoorSidesFromStore(),
|
|
selectedDriverSideReplaceOptions: this.getDriverSideReplaceOptionsFromStore(),
|
|
selectedPassengerSideReplaceOptions: this.getPassengerSideReplaceOptionsFromStore()
|
|
},
|
|
selectedWindshieldOptions: this.getWindshieldOptionsFromStore(),
|
|
selectedRearReplaceOptions: this.getRearReplaceOptionsFromStore()
|
|
};
|
|
},
|
|
computed: {
|
|
isWindshieldDamageLocation() {
|
|
return this.selectedDamageLocations.some((selectedDamages) => selectedDamages.toUpperCase() === damageLocationsCms.WINDSHIELD);
|
|
},
|
|
isSideDoorDamageLocation() {
|
|
return this.selectedDamageLocations.some((selectedDamages) => selectedDamages.toUpperCase() === damageLocationsCms.SIDEDOOR);
|
|
},
|
|
isRearWindowDamageLocation() {
|
|
return this.selectedDamageLocations.some((selectedDamages) => selectedDamages.toUpperCase() === damageLocationsCms.REARWINDOW);
|
|
},
|
|
isWindshieldRepair() {
|
|
return (
|
|
this.isWindshieldDamageLocation
|
|
&& this.selectedWindshieldOptions.selectedWindshieldDamageType
|
|
=== damageLocationsSelected.REPAIR
|
|
);
|
|
},
|
|
isDriverSideReplace() {
|
|
if (!this.isSideDoorDamageLocation) return false;
|
|
|
|
return this
|
|
.sideDoorOptionsData.selectedDoorSides
|
|
.some((selectedDriverSide) => selectedDriverSide.toUpperCase() === damageLocationsCms.DRIVERSIDE);
|
|
},
|
|
isPassengerSideReplace() {
|
|
if (!this.isSideDoorDamageLocation) return false;
|
|
|
|
return this
|
|
.sideDoorOptionsData.selectedDoorSides
|
|
.some((selectedPassengerSide) => selectedPassengerSide.toUpperCase() === damageLocationsCms.PASSENGERSIDE);
|
|
},
|
|
hasRepairReplaceConflict() {
|
|
return (
|
|
this.isWindshieldDamageLocation
|
|
&& this.selectedDamageLocations.length > 1
|
|
&& this.isWindshieldRepair
|
|
);
|
|
},
|
|
hasSplitSingleConflict() {
|
|
if (
|
|
!this.selectedDamageLocations?.includes('Windshield')
|
|
|| this.selectedWindshieldOptions.selectedWindshieldDamageType
|
|
=== damageLocationsSelected.REPAIR
|
|
|| !this.selectedWindshieldOptions.selectedWindshieldReplaceOptions
|
|
) return false;
|
|
|
|
return (
|
|
this.selectedWindshieldOptions.selectedWindshieldReplaceOptions?.some((selectedSingleWindshield) => (
|
|
selectedSingleWindshield.toUpperCase()
|
|
=== damageLocationsSelected.SINGLE.toUpperCase()
|
|
))
|
|
&& (this.selectedWindshieldOptions.selectedWindshieldReplaceOptions?.some((selectedDriverWindshield) => (
|
|
selectedDriverWindshield.toUpperCase()
|
|
=== damageLocationsSelected.DRIVER.toUpperCase()
|
|
))
|
|
|| this.selectedWindshieldOptions.selectedWindshieldReplaceOptions?.some((selectedPassengerWindshield) => (
|
|
selectedPassengerWindshield.toUpperCase()
|
|
=== damageLocationsSelected.PASSENGER.toUpperCase()
|
|
)))
|
|
);
|
|
},
|
|
shouldDisplayVehicleChangeAlert() {
|
|
return this.$route.params[this.routerParams.DISPLAY_VEHICLE_CHANGE_ALERT];
|
|
}
|
|
},
|
|
methods: {
|
|
arePagePrerequisitesValid() {
|
|
if (useMainStore().order.vehicle.carId) {
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
|
|
backButtonAction() {
|
|
// route to move backwards
|
|
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
|
|
},
|
|
|
|
getDamageLocationsFromStore() {
|
|
const glassSelections = [];
|
|
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => glass.glassLocation === damageLocationsSelected.WINDSHIELD)
|
|
|| this.mainStore.order.damage.isRepair
|
|
) {
|
|
glassSelections.push(damageLocationsSelected.WINDSHIELD);
|
|
}
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => (
|
|
glass.glassLocation === damageLocationsSelected.DRIVER
|
|
|| glass.glassLocation === damageLocationsSelected.PASSENGER
|
|
))
|
|
) {
|
|
glassSelections.push(damageLocationsSelected.SIDEDOOR);
|
|
}
|
|
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => glass.glassLocation === damageLocationsSelected.REAR)
|
|
) {
|
|
glassSelections.push(damageLocationsSelected.REARWINDOW);
|
|
}
|
|
|
|
return glassSelections;
|
|
},
|
|
|
|
getWindshieldOptionsFromStore() {
|
|
const windShieldOptions = {
|
|
selectedWindshieldDamageType: '',
|
|
selectedWindshieldChipCount: null,
|
|
selectedWindshieldReplaceOptions: []
|
|
};
|
|
|
|
if (this.mainStore.order.damage.isRepair === undefined) return windshieldOptions;
|
|
|
|
if (this.mainStore.order.damage.isRepair) {
|
|
windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPAIR;
|
|
windShieldOptions.selectedWindshieldChipCount = this.mainStore.order.damage.numberOfChips;
|
|
} else {
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => (
|
|
glass.glassLocation === damageLocationsSelected.WINDSHIELD
|
|
&& glass.glassName === damageLocationsSelected.SINGLE
|
|
))
|
|
) {
|
|
windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE;
|
|
windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.SINGLE);
|
|
}
|
|
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => (
|
|
glass.glassLocation === damageLocationsSelected.WINDSHIELD
|
|
&& glass.glassName === damageLocationsSelected.DRIVER
|
|
))
|
|
) {
|
|
windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE;
|
|
windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.DRIVER);
|
|
}
|
|
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => (
|
|
glass.glassLocation === damageLocationsSelected.WINDSHIELD
|
|
&& glass.glassName === damageLocationsSelected.PASSENGER
|
|
))
|
|
) {
|
|
windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE;
|
|
windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.PASSENGER);
|
|
}
|
|
}
|
|
|
|
return windShieldOptions;
|
|
},
|
|
|
|
getDoorSidesFromStore() {
|
|
const doorSides = [];
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => glass.glassLocation === damageLocationsSelected.DRIVER)
|
|
) {
|
|
doorSides.push(damageLocationsSelected.DRIVERSIDE);
|
|
}
|
|
|
|
if (
|
|
this.mainStore.order.damage.glassToReplace?.some((glass) => glass.glassLocation === damageLocationsSelected.PASSENGER)
|
|
) {
|
|
doorSides.push(damageLocationsSelected.PASSENGERSIDE);
|
|
}
|
|
|
|
return doorSides;
|
|
},
|
|
|
|
getDriverSideReplaceOptionsFromStore() {
|
|
const driverSideReplaceOptions = [];
|
|
|
|
this.mainStore.order.damage.glassToReplace?.forEach((glass) => {
|
|
if (glass.glassLocation === damageLocationsSelected.DRIVER) {
|
|
driverSideReplaceOptions.push(glass.glassName);
|
|
}
|
|
});
|
|
|
|
return driverSideReplaceOptions;
|
|
},
|
|
|
|
getPassengerSideReplaceOptionsFromStore() {
|
|
const passengerSideReplaceOptions = [];
|
|
|
|
this.mainStore.order.damage.glassToReplace?.forEach((glass) => {
|
|
if (glass.glassLocation === damageLocationsSelected.PASSENGER) {
|
|
passengerSideReplaceOptions.push(glass.glassName);
|
|
}
|
|
});
|
|
|
|
return passengerSideReplaceOptions;
|
|
},
|
|
|
|
getRearReplaceOptionsFromStore() {
|
|
const rearReplaceOptions = this.mainStore.order.damage
|
|
.glassToReplace?.filter((glass) => glass.glassLocation === damageLocationsSelected.REAR)[0]?.glassName;
|
|
|
|
return rearReplaceOptions;
|
|
},
|
|
|
|
async forwardButtonAction() {
|
|
this.mainStore.saveVehicleDamage(
|
|
this.isWindshieldRepair,
|
|
this.selectedGlassToReplace(),
|
|
this.selectedWindshieldOptions.selectedWindshieldChipCount
|
|
);
|
|
|
|
if (this.isWindshieldRepair) {
|
|
const supportingItems = await useMainStore().getSupportingItems();
|
|
this.mainStore.saveSupportingItems(supportingItems.data);
|
|
}
|
|
|
|
if (this.mainStore.damage.isRepair) {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_WITH_REPAIR,
|
|
this.$route
|
|
);
|
|
} else if (this.mainStore.order.vehicle.vin) {
|
|
// If vin already exists, navigate directly to vin-lookup
|
|
|
|
const partsOrQuestionsResponse = await this.getPartsOrQuestions();
|
|
if (partsOrQuestionsResponse.error) {
|
|
// To Do: Need requirement on what to do here
|
|
window.console.error('Error on retrieving PartsOrQuestions');
|
|
this.$refs.siteFooter.removeLoader();
|
|
return null;
|
|
}
|
|
|
|
// Comes from vehicleQuestionsMixin.navigateForward()
|
|
await this.navigateForward(partsOrQuestionsResponse.data.partsOrQuestions, this);
|
|
} else {
|
|
this.$router.navigate(
|
|
this.navigationScenarios.CLICKED_FORWARD_WITHOUT_VIN,
|
|
this.$route
|
|
);
|
|
}
|
|
|
|
return null;
|
|
},
|
|
|
|
selectedGlassToReplace() {
|
|
const selectedGlassToReplace = [];
|
|
if (this.isWindshieldDamageLocation && !this.isWindshieldRepair) {
|
|
this.selectedWindshieldOptions.selectedWindshieldReplaceOptions.forEach((wsItem) => {
|
|
selectedGlassToReplace.push({
|
|
glassLocation: damageLocationsSelected.WINDSHIELD,
|
|
glassName: wsItem
|
|
});
|
|
});
|
|
}
|
|
|
|
if (this.isDriverSideReplace) {
|
|
this.sideDoorOptionsData.selectedDriverSideReplaceOptions.forEach((driverItem) => {
|
|
selectedGlassToReplace.push({
|
|
glassLocation: damageLocationsSelected.DRIVER,
|
|
glassName: driverItem
|
|
});
|
|
});
|
|
}
|
|
|
|
if (this.isPassengerSideReplace) {
|
|
this.sideDoorOptionsData.selectedPassengerSideReplaceOptions.forEach((passengerItem) => {
|
|
selectedGlassToReplace.push({
|
|
glassLocation: damageLocationsSelected.PASSENGER,
|
|
glassName: passengerItem
|
|
});
|
|
});
|
|
}
|
|
|
|
if (this.isRearWindowDamageLocation) {
|
|
selectedGlassToReplace.push({
|
|
glassLocation: damageLocationsSelected.REAR,
|
|
glassName: this.selectedRearReplaceOptions
|
|
});
|
|
}
|
|
|
|
return selectedGlassToReplace;
|
|
}
|
|
}
|
|
};
|
|
</script>
|