CSR-343 Save glassParts

This commit is contained in:
Katie 2022-06-27 14:12:25 -04:00
parent 7e4494eb25
commit f208cb031c
3 changed files with 11 additions and 56 deletions

View file

@ -130,7 +130,6 @@ export default {
return this.modelValue; return this.modelValue;
}, },
set: function(newValue) { set: function(newValue) {
console.log(newValue)
this.$emit("update:modelValue", newValue); this.$emit("update:modelValue", newValue);
} }
}, },
@ -140,24 +139,19 @@ export default {
if (this.useTextForValue){ if (this.useTextForValue){
return answer.Text return answer.Text
} }
// console.log(answer.Name ? answer.Name : answer)
return answer.Name ? answer.Name : answer; return answer.Name ? answer.Name : answer;
}, },
handleCheckedChanged(val) { handleCheckedChanged(val) {
console.log(val)
console.log("A")
if(this.selectingInitiatesLoad) { if(this.selectingInitiatesLoad) {
console.log("B")
this.selectedValues = [val.value]; this.selectedValues = [val.value];
} else { } else {
if(Array.isArray(this.selectedValues)) { if(Array.isArray(this.selectedValues)) {
console.log("C")
const newSelectedValues = this.selectedValues; const newSelectedValues = this.selectedValues;
val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1); val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1);
this.selectedValues = newSelectedValues; this.selectedValues = newSelectedValues;
} }
else { else {
console.log("D")
this.selectedValues = val.value; this.selectedValues = val.value;
} }
} }

View file

@ -4,7 +4,6 @@
<p class="mb-0 color-question-text">{{ colorQuestionText }}</p> <p class="mb-0 color-question-text">{{ colorQuestionText }}</p>
</div> </div>
</div> </div>
{{ selectedPart }}
<div class="container nested-radio"> <div class="container nested-radio">
<div class="row my-2"> <div class="row my-2">
@ -119,7 +118,6 @@ export default {
return this.modelValue; return this.modelValue;
}, },
set: function (newValue) { set: function (newValue) {
console.log(newValue)
this.$emit("update:modelValue", newValue); this.$emit("update:modelValue", newValue);
}, },
}, },

View file

@ -62,12 +62,7 @@ import { settleAllPromises } from "@/helpers/layout-helper";
import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { storeMutations } from "@/constants/store-mutations"; import { storeMutations } from "@/constants/store-mutations";
import store from "@/store"; import store from "@/store";
import { Form, defineRule } from "vee-validate"; import { Form } from "vee-validate";
import { required } from "@/helpers/validation-rules";
import { errorMessages } from "@/constants/error-messages";
// DEFINE VALIDATION RULES
// defineRule("replace-options-required", required(errorMessages.OPTION_REQUIRED));
export default { export default {
name: "vehicle-parts", name: "vehicle-parts",
@ -166,53 +161,24 @@ methods: {
this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route); this.$router.navigate(this.navigationScenarios.CLICKED_BACK, this.$route);
}, },
forwardButtonAction() { forwardButtonAction() {
const selectedGlassPartNumbers = [];
const matchedParts = []; const matchedParts = [];
// Compile all selected parts from the page.
for (let [key, value] of Object.entries(this.glassParts)) {
selectedGlassPartNumbers.push(value);
// for (let [glassKey, glassValue] of Object.entries(value)) {
// selectedGlassPartNumbers.push(glassValue[0]);
// }
}
console.log(this.glassParts)
console.log(selectedGlassPartNumbers)
console.log(this.PartsFromApi.partsOrQuestions)
// Match them to the parts from the API. // Match them to the parts from the API.
for (let [key, value] of Object.entries(this.PartsFromApi.partsOrQuestions)) { this.PartsFromApi.partsOrQuestions.forEach(part => {
// const partsForGlassPart = value const selectedPartNumberForGlassLocationAndName = this.glassParts[`${part.glassLocation}-${part.glassName}`];
const isMatched = selectedGlassPartNumbers.some( const selectedPartData = part.parts.filter(part => part.partNumber == selectedPartNumberForGlassLocationAndName);
(p) => p === value.partNumber
);
if (isMatched) { matchedParts.push(selectedPartData[0]);
// matchedParts.push(currentPart); })
}
// for (let [partKey, partValue] of Object.entries(value.parts)) {
// const currentPart = this.PartsFromApi.partsOrQuestions[key].parts[partKey];
// const isMatched = selectedGlassPartNumbers.some(
// (p) => p === currentPart.partNumber
// );
// if (isMatched) {
// matchedParts.push(currentPart);
// }
// }
}
console.log(matchedParts)
// If no parts could be matched, throw an error. // If no parts could be matched, throw an error.
if (matchedParts.length === 0) { if (matchedParts.length === 0) {
this.$refs.funnelFooter.removeLoader();
throw new Error("Could not match any parts to the selected parts"); throw new Error("Could not match any parts to the selected parts");
} }
// // Save parts to the store. // Save parts to the store.
// store.commit(storeMutations.UPDATE_GLASS_PARTS, matchedParts); store.commit(storeMutations.UPDATE_GLASS_PARTS, matchedParts);
// // Navigate to the next page. // // Navigate to the next page.
// this.$router.navigateAfterSave( // this.$router.navigateAfterSave(
@ -227,10 +193,7 @@ methods: {
LoadInitialPartsData() { LoadInitialPartsData() {
const partsData = this.PartsFromApi; const partsData = this.PartsFromApi;
const alreadyPopulatedPartsData = const alreadyPopulatedPartsData = this.$store.getters.lineItems.glassParts === null ? {} : this.$store.getters.lineItems.glassParts;
this.$store.getters.lineItems.glassParts === null
? {}
: this.$store.getters.lineItems.glassParts;
partsData.partsOrQuestions.map((g) => { partsData.partsOrQuestions.map((g) => {
// If the part is already populated, use the value from the store and populate the v-model. // If the part is already populated, use the value from the store and populate the v-model.