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 && !cartItem.isCoveredByInsurance)
"
>{{ getFormattedAmount(cartItem.category, Math.abs(cartItem.subTotal)) }}</span
>{{
getFormattedAmount(cartItem.category, Math.abs(cartItem.subTotal))
}}</span
>
</div>

View file

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

View file

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