Update quote page to use new package logic.
This commit is contained in:
parent
717a8c50b5
commit
4d47b27308
1 changed files with 92 additions and 184 deletions
|
|
@ -18,12 +18,17 @@ import { processIfStatements } from "@/helpers/cms-content-helper";
|
||||||
import { damageLocationsSelected as glassLocations } from "@/constants/damage-locations-selected";
|
import { damageLocationsSelected as glassLocations } from "@/constants/damage-locations-selected";
|
||||||
import servicePackageRadio from "./service-package-radio/service-package-radio";
|
import servicePackageRadio from "./service-package-radio/service-package-radio";
|
||||||
import { partTypeStrings } from "@/constants/part-type-strings";
|
import { partTypeStrings } from "@/constants/part-type-strings";
|
||||||
|
import { packageNames } from "@/constants/package-names";
|
||||||
const packageNames = {
|
import {
|
||||||
TIER_ONE: "TierOne",
|
shouldFrontWipersBeAvailable,
|
||||||
TIER_TWO: "TierTwo",
|
shouldRearWipersBeAvailable,
|
||||||
TIER_THREE: "TierThree",
|
shouldRainDefenseBeAvailable,
|
||||||
};
|
getAvailablePackages,
|
||||||
|
getHighestRequiredTier,
|
||||||
|
getPackageContents,
|
||||||
|
containsLineItemWithPartType,
|
||||||
|
findLineItemsWithPartType,
|
||||||
|
} from "@/helpers/service-package-helper";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "servicePackageQuestion",
|
name: "servicePackageQuestion",
|
||||||
|
|
@ -65,11 +70,17 @@ export default {
|
||||||
if (!cmsAnswersContent) {
|
if (!cmsAnswersContent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!this.shouldDisplayTierTwoPackage) {
|
|
||||||
cmsAnswersContent = cmsAnswersContent.filter(
|
const availablePackages = getAvailablePackages(
|
||||||
(answer) => answer.Name != packageNames.TIER_TWO
|
this.glassToReplace,
|
||||||
);
|
this.nullSafeAvailableLineItems,
|
||||||
}
|
this.isRepair
|
||||||
|
);
|
||||||
|
|
||||||
|
cmsAnswersContent = cmsAnswersContent.filter((answer) =>
|
||||||
|
availablePackages.some((tier) => answer.Name === tier.packageName)
|
||||||
|
);
|
||||||
|
|
||||||
const modifiedAnswers = cmsAnswersContent.map((answer) => ({
|
const modifiedAnswers = cmsAnswersContent.map((answer) => ({
|
||||||
value: answer.Name,
|
value: answer.Name,
|
||||||
buttonLabel: this.getHeaderTextFromCms(answer.SubWidgetName),
|
buttonLabel: this.getHeaderTextFromCms(answer.SubWidgetName),
|
||||||
|
|
@ -81,67 +92,56 @@ export default {
|
||||||
return modifiedAnswers;
|
return modifiedAnswers;
|
||||||
},
|
},
|
||||||
isRecalibrationOnOrder() {
|
isRecalibrationOnOrder() {
|
||||||
return this.lineItemsContainsPartType(partTypeStrings.RECALIBRATION);
|
return containsLineItemWithPartType(
|
||||||
|
partTypeStrings.RECALIBRATION,
|
||||||
|
this.nullSafeAvailableLineItems
|
||||||
|
);
|
||||||
},
|
},
|
||||||
frontWipersApplicableForTierTwo() {
|
frontWipersApplicableForTierTwo() {
|
||||||
const frontWipersAreAvailable = this.lineItemsContainsPartType(
|
return shouldFrontWipersBeAvailable(
|
||||||
partTypeStrings.FRONT_WIPER
|
this.glassToReplace,
|
||||||
|
this.nullSafeAvailableLineItems,
|
||||||
|
this.isRepair,
|
||||||
|
packageNames.TIER_TWO
|
||||||
);
|
);
|
||||||
const isRepair = this.$store.getters.order.damage.isRepair;
|
|
||||||
const glassToReplaceContainsWindshield = this.glassToReplaceContainsGlassLocation(
|
|
||||||
glassLocations.WINDSHIELD
|
|
||||||
);
|
|
||||||
if (frontWipersAreAvailable) {
|
|
||||||
if (isRepair) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
if (glassToReplaceContainsWindshield) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
rearWiperApplicableForTierTwo() {
|
rearWiperApplicableForTierTwo() {
|
||||||
const rearWiperIsAvailable = this.lineItemsContainsPartType(partTypeStrings.REAR_WIPER);
|
return shouldRearWipersBeAvailable(
|
||||||
return (
|
this.glassToReplace,
|
||||||
this.glassToReplaceContainsGlassLocation(glassLocations.REAR) &&
|
this.nullSafeAvailableLineItems,
|
||||||
rearWiperIsAvailable
|
this.isRepair,
|
||||||
|
packageNames.TIER_TWO
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
frontWipersApplicableForTierThree() {
|
frontWipersApplicableForTierThree() {
|
||||||
const frontWipersAreAvailable = this.lineItemsContainsPartType(
|
return shouldFrontWipersBeAvailable(
|
||||||
partTypeStrings.FRONT_WIPER
|
this.glassToReplace,
|
||||||
|
this.nullSafeAvailableLineItems,
|
||||||
|
this.isRepair,
|
||||||
|
packageNames.TIER_THREE
|
||||||
);
|
);
|
||||||
return frontWipersAreAvailable;
|
|
||||||
},
|
},
|
||||||
rearWiperApplicableForTierThree() {
|
rearWiperApplicableForTierThree() {
|
||||||
const rearWiperIsAvailable = this.lineItemsContainsPartType(partTypeStrings.REAR_WIPER);
|
return shouldRearWipersBeAvailable(
|
||||||
const frontWipersAreAvailable = this.lineItemsContainsPartType(
|
this.glassToReplace,
|
||||||
partTypeStrings.FRONT_WIPER
|
this.nullSafeAvailableLineItems,
|
||||||
);
|
this.isRepair,
|
||||||
return (
|
packageNames.TIER_THREE
|
||||||
rearWiperIsAvailable &&
|
|
||||||
(this.glassToReplaceContainsGlassLocation(glassLocations.REAR) ||
|
|
||||||
!frontWipersAreAvailable)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
rainDefenseApplicableForTierThree() {
|
rainDefenseApplicableForTierThree() {
|
||||||
if (
|
return shouldRainDefenseBeAvailable(
|
||||||
this.rearWiperApplicableForTierTwo &&
|
this.glassToReplace,
|
||||||
!this.frontWipersApplicableForTierTwo &&
|
this.nullSafeAvailableLineItems,
|
||||||
this.frontWipersApplicableForTierThree
|
this.isRepair,
|
||||||
) {
|
packageNames.TIER_THREE
|
||||||
return false;
|
);
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
shouldDisplayTierTwoPackage() {
|
glassToReplace() {
|
||||||
return this.frontWipersApplicableForTierTwo || this.rearWiperApplicableForTierTwo;
|
return this.$store.getters.order.damage.glassToReplace;
|
||||||
|
},
|
||||||
|
isRepair() {
|
||||||
|
return this.$store.getters.order.damage.isRepair;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -170,65 +170,31 @@ export default {
|
||||||
: baseMixin.methods.getTierOnePackagePrice(
|
: baseMixin.methods.getTierOnePackagePrice(
|
||||||
baseMixin.methods.filterOutFees(this.nullSafeAvailableLineItems)
|
baseMixin.methods.filterOutFees(this.nullSafeAvailableLineItems)
|
||||||
);
|
);
|
||||||
if (packageName === packageNames.TIER_TWO) {
|
|
||||||
priceFloat += this.getTierTwoPackageVapsPrice();
|
priceFloat += this.getVapsPrice(packageName);
|
||||||
} else if (packageName === packageNames.TIER_THREE) {
|
|
||||||
priceFloat += this.getTierThreePackageVapsPrice();
|
|
||||||
}
|
|
||||||
return priceFloat;
|
return priceFloat;
|
||||||
},
|
},
|
||||||
getTierTwoPackageVapsPrice() {
|
getVapsPrice(packageName) {
|
||||||
let vapsPrice = 0;
|
const vapsItems = this.getVapsLineItemsForSelectedPackage(packageName);
|
||||||
const priceFrontWipers = this.frontWipersApplicableForTierTwo;
|
|
||||||
const priceRearWipers = this.rearWiperApplicableForTierTwo;
|
let price = 0;
|
||||||
this.nullSafeAvailableLineItems.forEach((item) => {
|
|
||||||
if (
|
vapsItems.forEach((item) => {
|
||||||
(priceFrontWipers &&
|
price += baseMixin.methods.getTotalLineItemPrice(item);
|
||||||
item.partType.toUpperCase() === partTypeStrings.FRONT_WIPER) ||
|
|
||||||
(priceRearWipers && item.partType.toUpperCase() === partTypeStrings.REAR_WIPER)
|
|
||||||
) {
|
|
||||||
vapsPrice += baseMixin.methods.getTotalLineItemPrice(item);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return vapsPrice;
|
|
||||||
},
|
return price;
|
||||||
getTierThreePackageVapsPrice() {
|
|
||||||
let vapsPrice = 0;
|
|
||||||
const priceFrontWipers = this.frontWipersApplicableForTierThree;
|
|
||||||
const priceRearWipers = this.rearWiperApplicableForTierThree;
|
|
||||||
const priceRainDefense = this.rainDefenseApplicableForTierThree;
|
|
||||||
this.nullSafeAvailableLineItems.forEach((item) => {
|
|
||||||
if (
|
|
||||||
(priceFrontWipers &&
|
|
||||||
item.partType.toUpperCase() === partTypeStrings.FRONT_WIPER) ||
|
|
||||||
(priceRearWipers &&
|
|
||||||
item.partType.toUpperCase() === partTypeStrings.REAR_WIPER) ||
|
|
||||||
(priceRainDefense &&
|
|
||||||
item.partType.toUpperCase() === partTypeStrings.RAIN_DEFENSE)
|
|
||||||
) {
|
|
||||||
vapsPrice += baseMixin.methods.getTotalLineItemPrice(item);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return vapsPrice;
|
|
||||||
},
|
},
|
||||||
selectDefaultPackage() {
|
selectDefaultPackage() {
|
||||||
const vapsFromStore = this.$store.getters.lineItems.vaps;
|
const vapsFromStore = this.$store.getters.lineItems.vaps ?? [];
|
||||||
let lowestTierForPackage = packageNames.TIER_ONE;
|
|
||||||
if (vapsFromStore?.length > 0) {
|
this.selectedPackageName = getHighestRequiredTier(
|
||||||
vapsFromStore.every((vapsItem) => {
|
this.glassToReplace,
|
||||||
let lowestTierForThisItem = this.getLowestTierForThisItem(vapsItem);
|
this.nullSafeAvailableLineItems,
|
||||||
if (lowestTierForThisItem === packageNames.TIER_THREE) {
|
this.isRepair,
|
||||||
lowestTierForPackage = packageNames.TIER_THREE;
|
vapsFromStore
|
||||||
return false;
|
);
|
||||||
} else if (lowestTierForThisItem === packageNames.TIER_TWO) {
|
|
||||||
lowestTierForPackage = packageNames.TIER_TWO;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.selectedPackageName = lowestTierForPackage;
|
|
||||||
},
|
},
|
||||||
allGlassPartsAndSupportingItemsHavePrices(lineItems) {
|
allGlassPartsAndSupportingItemsHavePrices(lineItems) {
|
||||||
if (lineItems?.glassParts) {
|
if (lineItems?.glassParts) {
|
||||||
|
|
@ -254,63 +220,22 @@ export default {
|
||||||
(lineItem.sellingPrice == null || lineItem.sellingPrice == 0)
|
(lineItem.sellingPrice == null || lineItem.sellingPrice == 0)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getLowestTierForThisItem(vapsItem) {
|
|
||||||
let lowestTierForThisItem = null;
|
|
||||||
switch (vapsItem.partType) {
|
|
||||||
case partTypeStrings.FRONT_WIPER:
|
|
||||||
if (this.frontWipersApplicableForTierThree) {
|
|
||||||
lowestTierForThisItem = packageNames.TIER_THREE;
|
|
||||||
}
|
|
||||||
if (this.frontWipersApplicableForTierTwo) {
|
|
||||||
lowestTierForThisItem = packageNames.TIER_TWO;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case partTypeStrings.REAR_WIPER:
|
|
||||||
if (this.rearWiperApplicableForTierThree) {
|
|
||||||
lowestTierForThisItem = packageNames.TIER_THREE;
|
|
||||||
}
|
|
||||||
if (this.rearWiperApplicableForTierTwo) {
|
|
||||||
lowestTierForThisItem = packageNames.TIER_TWO;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case partTypeStrings.RAIN_DEFENSE:
|
|
||||||
if (this.rainDefenseApplicableForTierThree) {
|
|
||||||
lowestTierForThisItem = packageNames.TIER_THREE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return lowestTierForThisItem;
|
|
||||||
},
|
|
||||||
getVapsLineItemsForSelectedPackage(packageName) {
|
getVapsLineItemsForSelectedPackage(packageName) {
|
||||||
const vapsLineItemsForSelectedPackage = [];
|
const packageContentTypes = getPackageContents(
|
||||||
if (packageName === packageNames.TIER_TWO) {
|
this.glassToReplace,
|
||||||
if (this.frontWipersApplicableForTierTwo) {
|
this.nullSafeAvailableLineItems,
|
||||||
vapsLineItemsForSelectedPackage.push(
|
this.isRepair,
|
||||||
...this.getLineItemsContainingPartType(partTypeStrings.FRONT_WIPER)
|
packageName
|
||||||
);
|
);
|
||||||
}
|
|
||||||
if (this.rearWiperApplicableForTierTwo) {
|
let vapsLineItemsForSelectedPackage = [];
|
||||||
vapsLineItemsForSelectedPackage.push(
|
|
||||||
...this.getLineItemsContainingPartType(partTypeStrings.REAR_WIPER)
|
packageContentTypes.forEach((vapType) => {
|
||||||
);
|
vapsLineItemsForSelectedPackage.push(
|
||||||
}
|
...findLineItemsWithPartType(vapType, this.nullSafeAvailableLineItems)
|
||||||
} else if (packageName === packageNames.TIER_THREE) {
|
);
|
||||||
if (this.frontWipersApplicableForTierThree) {
|
});
|
||||||
vapsLineItemsForSelectedPackage.push(
|
|
||||||
...this.getLineItemsContainingPartType(partTypeStrings.FRONT_WIPER)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (this.rearWiperApplicableForTierThree) {
|
|
||||||
vapsLineItemsForSelectedPackage.push(
|
|
||||||
...this.getLineItemsContainingPartType(partTypeStrings.REAR_WIPER)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (this.rainDefenseApplicableForTierThree) {
|
|
||||||
vapsLineItemsForSelectedPackage.push(
|
|
||||||
...this.getLineItemsContainingPartType(partTypeStrings.RAIN_DEFENSE)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return vapsLineItemsForSelectedPackage;
|
return vapsLineItemsForSelectedPackage;
|
||||||
},
|
},
|
||||||
getCustomValueFromString(str) {
|
getCustomValueFromString(str) {
|
||||||
|
|
@ -331,23 +256,6 @@ export default {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getLineItemsContainingPartType(partType) {
|
|
||||||
const partTypeMatches = this.nullSafeAvailableLineItems.filter(
|
|
||||||
(lineItem) => lineItem.partType.toUpperCase() === partType
|
|
||||||
);
|
|
||||||
return partTypeMatches;
|
|
||||||
},
|
|
||||||
lineItemsContainsPartType(partType) {
|
|
||||||
const partTypeMatches = this.getLineItemsContainingPartType(partType);
|
|
||||||
return !!partTypeMatches.length;
|
|
||||||
},
|
|
||||||
glassToReplaceContainsGlassLocation(glassLocation) {
|
|
||||||
const glassLocationMatches =
|
|
||||||
this.$store.getters.order.damage.glassToReplace?.filter(
|
|
||||||
(glassToReplace) => glassToReplace.glassLocation === glassLocation
|
|
||||||
) ?? [];
|
|
||||||
return !!glassLocationMatches.length;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
buttonQuestion,
|
buttonQuestion,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue