-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (84 loc) · 3.1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Vue.use(VueMaterial.default);
var app = new Vue({
el: "#app",
data() {
return {
type: "",
page: "query",
isQueryPage: true,
lotCounter: 1,
lots: [{ base1: '', comp: '', base2: '' }],
groupby: '',
status: '',
showLoader: true,
hasInputError: false,
};
},
watch: {
lots: {
deep: true, // added this so that the nested element will be watched as well
handler(lot) {
if (this.lots[this.lotCounter - 1].base1 !== '' || this.lots[this.lotCounter - 1].comp !== '' || this.lots[this.lotCounter - 1].base2 !== '') {
this.lots.push({ base1: '', comp: '', base2: '' });
this.lotCounter++;
}
}
}
},
methods: {
change_page: function (page) {
this.page = page;
if (this.page === 'query') {
this.isQueryPage = true;
}
else {
this.isQueryPage = false;
}
},
validate_input: function () {
if (this.lots.length === 1) {
this.status = `Error: Please insert lot numbers!`
this.hasInputError = true;
this.showLoader = false;
return;
}
this.lots.pop(); // last elememt is always empty
for (let index = 0; index < this.lots.length; index++) {
if (this.lots[index].base1 === '') {
this.status = `Error in lot set #${index + 1}: Base1 lot cannot be empty!`
this.hasInputError = true;
this.showLoader = false;
return;
} else if (this.lots[index].comp === '') {
this.status = `Error in lot set #${index + 1}: Comp lot cannot be empty!`
this.hasInputError = true;
this.showLoader = false;
return;
}
if (!this.lots[index].base1.includes('/') || !this.lots[index].comp.includes('/')) {
this.status = `Error in lot set #${index + 1}: lot must be in slash format!`
this.hasInputError = true;
this.showLoader = false;
return;
}
if (this.lots[index].base1 !== '' && !this.lots[index].base1.includes('/')) {
this.status = `Error in lot set #${index + 1}: lot must be in slash format!`
this.hasInputError = true;
this.showLoader = false;
return;
}
}
},
clearError: function () {
this.hasInputError = false;
this.showLoader = true;
},
submit: function () {
this.status = 'Validating Input...';
this.validate_input();
this.status = 'Pulling Data...';
this.lots = [{ base1: '', comp: '', base2: '' }];
this.lotCounter = 1;
}
},
});