code optimize
This commit is contained in:
hiteshkumar87 2024-05-13 17:53:40 +05:30
parent 07201731ac
commit cb825a51c7
3 changed files with 83 additions and 36 deletions

View file

@ -100,7 +100,9 @@
!showCoverageAsVerified || !showCoverageAsVerified ||
(showCoverageAsVerified && !cartItem.isCoveredByInsurance) (showCoverageAsVerified && !cartItem.isCoveredByInsurance)
" "
>{{ getFormattedAmount(cartItem.category, Math.abs(cartItem.subTotal)) }}</span >{{
getFormattedAmount(cartItem.category, Math.abs(cartItem.subTotal))
}}</span
> >
</div> </div>

View file

@ -28,8 +28,8 @@
groupName="ServicePackageQuestion" groupName="ServicePackageQuestion"
:availableLineItems="availableLineItems" :availableLineItems="availableLineItems"
:isInsuranceSelected="isInsuranceSelected" :isInsuranceSelected="isInsuranceSelected"
:isServicePackageDiscount="getServicePackageDiscount"
@vapsItemsSelected="vapsItemsSelectedAction" @vapsItemsSelected="vapsItemsSelectedAction"
@servicePackageDiscountSelected="servicePackageDiscountSelectedAction"
:activePromos="lineItems.promos" :activePromos="lineItems.promos"
:lineItems="lineItems" :lineItems="lineItems"
v-on="{ 'buttonEvent.openModal': openModalAction }" v-on="{ 'buttonEvent.openModal': openModalAction }"
@ -109,7 +109,7 @@ import { queryStrings } from "@/constants/query-strings";
import { getQuerystringParameter } from "@/helpers/querystring-helper"; import { getQuerystringParameter } from "@/helpers/querystring-helper";
import promoModalQuestion from "@/fmg-components/promo-modal-question/promo-modal-question"; import promoModalQuestion from "@/fmg-components/promo-modal-question/promo-modal-question";
import { experimentSettings } from "@/constants/experiments"; import { experimentSettings } from "@/constants/experiments";
import { partTypeStrings } from "@/constants/part-type-strings";
defineRule("option-required", required(errorMessages.OPTION_REQUIRED)); defineRule("option-required", required(errorMessages.OPTION_REQUIRED));
export default { export default {
@ -164,12 +164,17 @@ export default {
); );
const isServicePackageDiscount = servicePackageDiscountSettingValue === "True"; const isServicePackageDiscount = servicePackageDiscountSettingValue === "True";
if (isServicePackageDiscount) { if (isServicePackageDiscount) {
const servicePackageDiscount = await baseMixin.methods.dispatchStoreActionWithLogging( const servicePackageDiscountPart =
storeActions.CASH_SERVICE_PACKAGE_DISCOUNT, await baseMixin.methods.dispatchStoreActionWithLogging(
null, storeActions.CASH_SERVICE_PACKAGE_DISCOUNT,
"quote" null,
); "quote"
lineItems.supportingItems = [...resultMap.supportingItems, servicePackageDiscount.data]; );
//add service package discount part to supporting items to get price together
lineItems.supportingItems = [
...resultMap.supportingItems,
servicePackageDiscountPart.data,
];
} else { } else {
lineItems.supportingItems = resultMap.supportingItems; lineItems.supportingItems = resultMap.supportingItems;
} }
@ -188,7 +193,12 @@ export default {
"quote", "quote",
false false
); );
if (isServicePackageDiscount) {
//remove service package discount part after pricing
lineItems.supportingItems = lineItems.supportingItems.filter((item) => {
item.partType !== partTypeStrings.SERVICE_PACKAGE_DISCOUNT;
});
}
baseMixin.methods.dispatchStoreAction( baseMixin.methods.dispatchStoreAction(
storeActions.SAVE_SUPPORTING_ITEMS, storeActions.SAVE_SUPPORTING_ITEMS,
lineItems.supportingItems, lineItems.supportingItems,
@ -248,21 +258,12 @@ export default {
availableLineItems: null, availableLineItems: null,
lineItems: [], lineItems: [],
addableVaps: [], addableVaps: [],
servicePackageDiscountLineItems: [],
}; };
}, },
computed: { computed: {
lineItemsCloneForWatcher() { lineItemsCloneForWatcher() {
return Object.assign({}, this.lineItems); return Object.assign({}, this.lineItems);
}, },
getServicePackageDiscount() {
const servicePackageDiscountSettingValue = this.getSettingValue(
experimentSettings.SERVICE_PACKAGE_DISCOUNT
);
const isServicePackageDiscount = servicePackageDiscountSettingValue === "True";
return isServicePackageDiscount;
},
}, },
methods: { methods: {
openModalAction(modalName) { openModalAction(modalName) {
@ -305,6 +306,9 @@ export default {
vapsItemsSelectedAction(vapsItemsSelected) { vapsItemsSelectedAction(vapsItemsSelected) {
this.lineItems.vaps = vapsItemsSelected; this.lineItems.vaps = vapsItemsSelected;
}, },
servicePackageDiscountSelectedAction(servicePackageDiscountSelected) {
this.lineItems.supportingItems = servicePackageDiscountSelected;
},
backButtonAction() { backButtonAction() {
vehicleQuestionsMixin.methods.navigateBack(this); vehicleQuestionsMixin.methods.navigateBack(this);
}, },
@ -342,7 +346,11 @@ export default {
false false
); );
} }
this.dispatchStoreAction(
this.storeActions.SAVE_SUPPORTING_ITEMS,
this.lineItems.supportingItems,
false
);
this.dispatchStoreAction(this.storeActions.SAVE_VAPS, this.lineItems.vaps, false); this.dispatchStoreAction(this.storeActions.SAVE_VAPS, this.lineItems.vaps, false);
this.dispatchStoreAction( this.dispatchStoreAction(
storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS, storeActions.SAVE_ACTIVE_AND_OR_INACTIVE_PROMOS,

View file

@ -47,7 +47,6 @@ export default {
isInsuranceSelected: Boolean, isInsuranceSelected: Boolean,
availableLineItems: null, availableLineItems: null,
lineItems: null, lineItems: null,
isServicePackageDiscount: Boolean,
activePromos: null, activePromos: null,
}, },
data() { data() {
@ -71,12 +70,34 @@ export default {
selectedPackageName(newValue) { selectedPackageName(newValue) {
const VapsProductsInSelectedPackage = this.getVapsLineItemsForSelectedPackage(newValue); const VapsProductsInSelectedPackage = this.getVapsLineItemsForSelectedPackage(newValue);
this.$emit("vapsItemsSelected", VapsProductsInSelectedPackage); this.$emit("vapsItemsSelected", VapsProductsInSelectedPackage);
const servicePackageDiscountPartInSelectedPackage =
this.getServicePackageDiscountPartForSelectedPackage(newValue);
let supportingItems = this.supportingLineItems;
if (servicePackageDiscountPartInSelectedPackage?.length > 0) {
supportingItems.push(servicePackageDiscountPartInSelectedPackage[0]);
} else {
if (
supportingItems?.length > 0 &&
containsLineItemWithPartType(
partTypeStrings.SERVICE_PACKAGE_DISCOUNT,
supportingItems
)
) {
supportingItems = supportingItems.filter(
(item) => item.partType !== partTypeStrings.SERVICE_PACKAGE_DISCOUNT
);
}
}
this.$emit("servicePackageDiscountSelected", supportingItems);
}, },
}, },
computed: { computed: {
nullSafeAvailableLineItems() { nullSafeAvailableLineItems() {
return this.availableLineItems ?? []; return this.availableLineItems ?? [];
}, },
supportingLineItems() {
return this.lineItems.supportingItems;
},
servicePackageAnswers() { servicePackageAnswers() {
const cmsWidgetName = this.isInsuranceSelected const cmsWidgetName = this.isInsuranceSelected
? this.insuranceCmsWidgetName ? this.insuranceCmsWidgetName
@ -103,12 +124,13 @@ export default {
buttonBodyCopy: this.getBodyTextFromCms(answer.SubWidgetName), buttonBodyCopy: this.getBodyTextFromCms(answer.SubWidgetName),
buttonAuxillaryCopy: this.getDiscountedPackagePriceString( buttonAuxillaryCopy: this.getDiscountedPackagePriceString(
answer.Name, answer.Name,
this.isServicePackageDiscount && answer.Text != "" this.isServicePackageDiscountOnOrder && answer.Text != ""
), ),
buttonFooterCopy: this.getFooterTextFromCms(answer.SubWidgetName), buttonFooterCopy: this.getFooterTextFromCms(answer.SubWidgetName),
additionalButtonData: { additionalButtonData: {
strikeThroughPrice: this.getPackagePriceString(answer.Name), strikeThroughPrice: this.getPackagePriceString(answer.Name),
servicePackageDiscount: this.isServicePackageDiscount && answer.Text != "", servicePackageDiscount:
this.isServicePackageDiscountOnOrder && answer.Text != "",
Text: answer.Text + this.getServicePackageDiscountPrice(), Text: answer.Text + this.getServicePackageDiscountPrice(),
}, },
})); }));
@ -120,6 +142,12 @@ export default {
this.nullSafeAvailableLineItems this.nullSafeAvailableLineItems
); );
}, },
isServicePackageDiscountOnOrder() {
return containsLineItemWithPartType(
partTypeStrings.SERVICE_PACKAGE_DISCOUNT,
this.nullSafeAvailableLineItems
);
},
frontWipersApplicableForTierTwo() { frontWipersApplicableForTierTwo() {
return shouldFrontWipersBeAvailable( return shouldFrontWipersBeAvailable(
this.glassToReplace, this.glassToReplace,
@ -166,6 +194,12 @@ export default {
isRepair() { isRepair() {
return this.$store.getters.order.damage.isRepair; return this.$store.getters.order.damage.isRepair;
}, },
servicePackageDiscountParts() {
return findLineItemsWithPartType(
partTypeStrings.SERVICE_PACKAGE_DISCOUNT,
this.nullSafeAvailableLineItems
);
},
}, },
methods: { methods: {
processIfStatements, processIfStatements,
@ -200,14 +234,11 @@ export default {
}, },
getPackagePrice(packageName, { discountedPrice = false, servicePackageDiscount = false }) { getPackagePrice(packageName, { discountedPrice = false, servicePackageDiscount = false }) {
var lineItemsToPrice = [...this.nullSafeAvailableLineItems]; var lineItemsToPrice = [...this.nullSafeAvailableLineItems];
//remove service package discount part //remove service package discount part
const servicePackageDiscountParts = findLineItemsWithPartType( if (this.isServicePackageDiscountOnOrder) {
partTypeStrings.SERVICE_PACKAGE_DISCOUNT,
this.nullSafeAvailableLineItems
);
if (servicePackageDiscountParts?.length > 0) {
lineItemsToPrice = this.nullSafeAvailableLineItems.filter((item) => { lineItemsToPrice = this.nullSafeAvailableLineItems.filter((item) => {
return item.partType != servicePackageDiscountParts[0].partType; return item.partType != this.servicePackageDiscountParts[0].partType;
}); });
} }
@ -215,7 +246,7 @@ export default {
lineItemsToPrice.push(...removeVapsPromosFromPromoArray(this.activePromos)); lineItemsToPrice.push(...removeVapsPromosFromPromoArray(this.activePromos));
} }
if (servicePackageDiscount) { if (servicePackageDiscount) {
lineItemsToPrice.push(...servicePackageDiscountParts); lineItemsToPrice.push(...this.servicePackageDiscountParts);
} }
let priceFloat = this.isInsuranceSelected let priceFloat = this.isInsuranceSelected
? 0 ? 0
@ -228,13 +259,11 @@ export default {
return priceFloat; return priceFloat;
}, },
getServicePackageDiscountPrice() { getServicePackageDiscountPrice() {
const servicePackageDiscountParts = findLineItemsWithPartType( if (this.isServicePackageDiscountOnOrder) {
partTypeStrings.SERVICE_PACKAGE_DISCOUNT,
this.nullSafeAvailableLineItems
);
if (servicePackageDiscountParts?.length > 0) {
let price = 0; let price = 0;
price += baseMixin.methods.getTotalLineItemPrice(servicePackageDiscountParts[0]); price += baseMixin.methods.getTotalLineItemPrice(
this.servicePackageDiscountParts[0]
);
return Math.abs(price); return Math.abs(price);
} }
}, },
@ -295,6 +324,14 @@ export default {
return vapsLineItemsForSelectedPackage; return vapsLineItemsForSelectedPackage;
}, },
getServicePackageDiscountPartForSelectedPackage(packageName) {
const selectedPackage = this.servicePackageAnswers.filter((item) => {
return item.value === packageName;
});
if (selectedPackage?.[0]?.additionalButtonData?.servicePackageDiscount) {
return this.servicePackageDiscountParts;
} else return [];
},
combineLineItemsWithoutDuplicates(lineItemsOne, lineItemsTwo) { combineLineItemsWithoutDuplicates(lineItemsOne, lineItemsTwo) {
const combinedLineItemArray = [...lineItemsTwo]; const combinedLineItemArray = [...lineItemsTwo];
lineItemsOne.forEach((lineItemOne) => { lineItemsOne.forEach((lineItemOne) => {