refactored

This commit is contained in:
Jason Wheeler 2023-02-16 14:19:38 -05:00
parent be3f574cac
commit 76b31a3faa

View file

@ -115,7 +115,6 @@ export default {
return this.modelValue?.partNumber; return this.modelValue?.partNumber;
}, },
set(newValue) { set(newValue) {
console.log(this.selectedPartNumber)
this.$emit( this.$emit(
"update:modelValue", "update:modelValue",
this.partsForSelectedTint.filter((part) => part.partNumber == newValue.value)[0] this.partsForSelectedTint.filter((part) => part.partNumber == newValue.value)[0]
@ -184,40 +183,28 @@ export default {
// Also checks if only a single part is present for the tint. // Also checks if only a single part is present for the tint.
ResetTintAndPartSelections() { ResetTintAndPartSelections() {
this.selectedPartNumber = null; this.selectedPartNumber = null;
this.AutoSelectIfSinglePart(); this.AutoSelect();
}, },
// Check if only a single part is present for the tint and set the v-model if it is.
AutoSelectIfSinglePart() { AutoSelect() {
// Check if only a single part is present for the tint and set the v-model if it is.
if (this.partsForSelectedTint?.length == 1) { if (this.partsForSelectedTint?.length == 1) {
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber }; this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
this.$nextTick(() => {
//select element with matching partNumber
const element = document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
});
} }
else{ else{
if(this.selectedPartNumber && this.partsForSelectedTint.filter(x => x.partNumber == this.selectedPartNumber).length > 0) // If selected part isn't in the current list or it's null, select the first part
if(!this.selectedPartNumber || this.partsForSelectedTint.filter(x => x.partNumber == this.selectedPartNumber).length === 0)
{ {
this.$nextTick(() => { this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
//select element with matching partNumber
const element = document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
});
}
else{
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber }
this.$nextTick(() => {
//select element with matching partNumber
const element = document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
});
} }
} }
},
//select element with matching partNumber
this.$nextTick(() => {
document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
});
},
// Loads the preselected values from the store. // Loads the preselected values from the store.
LoadPreselectedValues() { LoadPreselectedValues() {
this.$nextTick(() => { this.$nextTick(() => {
@ -230,7 +217,7 @@ export default {
}, },
watch: { watch: {
selectedTint() { selectedTint() {
this.AutoSelectIfSinglePart(); this.AutoSelect();
}, },
}, },
}; };