137 lines
4.8 KiB
Vue
137 lines
4.8 KiB
Vue
<template>
|
|
<div class="page-container-grouped-styles">
|
|
<funnelHeader cmsWidgetName="FunnelHeaderWidget" />
|
|
<div class="select-car">
|
|
<div class="select-car-form rounded text-center">
|
|
<vehicleBanner cmsWidgetName="VehicleBannerWidget" displayGenericVehicleImage />
|
|
<funnelSubHeader
|
|
cmsWidgetName="FunnelSubHeaderWidget"
|
|
:hasBackButton="true"
|
|
@click-event="backButtonAction"
|
|
headerColor="light-header" />
|
|
<div class="fade-on-route-transition">
|
|
<styleQuestion
|
|
v-model="selectedStyle"
|
|
ref="styleQuestion"
|
|
cmsWidgetName="VehicleStyleQuestion" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
// Components
|
|
import baseMixin from "@/mixins/base-mixin.js";
|
|
import styleQuestion from "@/layouts/vehicle-style/style-question/style-question";
|
|
import funnelHeader from "@/fmg-components/funnel-header/funnel-header";
|
|
import funnelSubHeader from "@/fmg-components/funnel-sub-header/funnel-sub-header";
|
|
import vehicleBanner from "@/fmg-components/vehicle-banner/vehicle-banner";
|
|
|
|
// Supporting files
|
|
import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
|
|
import { settleAllPromises } from "@/helpers/layout-helper";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
import store from "@/store";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
|
|
import router from "@/router";
|
|
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios";
|
|
|
|
export default {
|
|
name: "vehicle-style",
|
|
data() {
|
|
return {
|
|
selectedStyle: null,
|
|
};
|
|
},
|
|
|
|
computed: {},
|
|
|
|
async beforeRouteEnter(to, from, next) {
|
|
// Call APIs
|
|
const cmsContentPromise = fetchCmsContentForPage(to.query.fmgPage);
|
|
const styleQuestionInitialDataPromise = styleQuestion.methods.loadInitialData();
|
|
|
|
// Settle promises and get results
|
|
const promiseResultMap = [
|
|
{
|
|
resultKey: "cmsContent",
|
|
promise: cmsContentPromise,
|
|
},
|
|
{
|
|
resultKey: "styleQuestionInitialData",
|
|
promise: styleQuestionInitialDataPromise,
|
|
},
|
|
];
|
|
|
|
const resultMap = await settleAllPromises(promiseResultMap);
|
|
const visitedVehicleDamage =
|
|
JSON.stringify(store.getters.applicationUser.pageData).indexOf(
|
|
fmgPageValues.VEHICLE_DAMAGE
|
|
) < 0
|
|
? false
|
|
: true;
|
|
|
|
// If we have exactly one style then navigate directly to vehicle-damage
|
|
if (resultMap.styleQuestionInitialData.length === 1 && !visitedVehicleDamage) {
|
|
store.commit(storeMutations.UPDATE_STYLE, resultMap.styleQuestionInitialData[0]);
|
|
|
|
await baseMixin.methods.dispatchStoreAction(storeActions.SET_VEHICLE, {
|
|
year: store.getters.vehicle.year,
|
|
make: store.getters.vehicle.make,
|
|
model: store.getters.vehicle.model,
|
|
style: store.getters.vehicle.style,
|
|
});
|
|
|
|
//emulate selecting the vehicle style
|
|
router.overrideNavigation(navigationScenarios.SELECTED_STYLE, to, next, true);
|
|
} else {
|
|
next((vm) => {
|
|
vm.setCmsContent(resultMap.cmsContent);
|
|
vm.$refs.styleQuestion.initializeComponent(resultMap.styleQuestionInitialData);
|
|
});
|
|
}
|
|
},
|
|
|
|
methods: {
|
|
backButtonAction() {
|
|
// route to move backwards
|
|
this.$router.navigateWithoutSaving(this.navigationScenarios.CLICKED_BACK, this.$route);
|
|
},
|
|
setVehicle() {
|
|
return this.dispatchStoreAction(this.storeActions.SET_VEHICLE, {
|
|
year: this.$store.getters.vehicle.year,
|
|
make: this.$store.getters.vehicle.make,
|
|
model: this.$store.getters.vehicle.model,
|
|
style: this.$store.getters.vehicle.style,
|
|
});
|
|
},
|
|
arePagePrerequisitesValid() {
|
|
if (store.getters.vehicle.model) {
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
},
|
|
|
|
watch: {
|
|
selectedStyle(style) {
|
|
this.dispatchStoreAction(storeActions.SAVE_VEHICLE_STYLE, style, false);
|
|
this.setVehicle().then(() => {
|
|
this.$router.navigateWithSaving(
|
|
this.navigationScenarios.SELECTED_STYLE,
|
|
this.$route
|
|
);
|
|
});
|
|
},
|
|
},
|
|
|
|
components: {
|
|
styleQuestion,
|
|
funnelHeader,
|
|
funnelSubHeader,
|
|
vehicleBanner,
|
|
},
|
|
};
|
|
</script>
|