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;
},
set(newValue) {
console.log(this.selectedPartNumber)
this.$emit(
"update:modelValue",
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.
ResetTintAndPartSelections() {
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) {
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{
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(() => {
//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;
});
this.selectedPartNumber = { value: this.partsForSelectedTint[0].partNumber };
}
}
},
//select element with matching partNumber
this.$nextTick(() => {
document.querySelector('input[value=' + this.selectedPartNumber + ']').checked = true;
});
},
// Loads the preselected values from the store.
LoadPreselectedValues() {
this.$nextTick(() => {
@ -230,7 +217,7 @@ export default {
},
watch: {
selectedTint() {
this.AutoSelectIfSinglePart();
this.AutoSelect();
},
},
};