reservation.js
2.73 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
export default {
data() {
return {
isSubmit: false,
key: 'value',
isHkCus: true,
checked: false,
data: {
name: "",
contactType: "",
contactMethod: "",
reservationType: "",
instruction: "",
hkCustomer: "",
contactDate: ""
},
errorTips: {
e1: "",
e2: "",
e3: "",
e4: "",
e5: "",
e6: "",
e7: ""
}
}
},
components: {},
computed: {
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
},
contactMethods() {
return this.i18n.customService.reservation.contactMethods;
},
reservationTypes() {
return this.i18n.customService.reservation.reservationTypes;
}
},
methods: {
initData() {
this.data.contactType = this.contactMethods[0];
this.data.reservationType = this.reservationTypes[0];
},
submitHandler() {
if (this.isSubmit) {
return;
}
let b1 = this.checkName();
let b2 = this.checkContactMethod();
let b3 = this.checkInstruction();
let b4 = this.checkContactDate();
let b = b1 & b2 & b3 & b4;
if (b) {
this.isSubmit = true;
this.data.hkCustomer = this.isHkCus ? 1 : 0;
httpPost({
url: api.saveReservation,
data: this.data
}).then(() => {
this.showSubmitSuccess();
this.isSubmit = false;
}).catch(() => {
this.isSubmit = false;
})
}
},
showSubmitSuccess(){
alert("提交成功");
this.data.name = "";
this.data.contactMethod = "";
this.data.instruction = "";
},
checkName() {
if (!this.data.name) {
let message = this.i18n.customService.reservation.errorTips.e1;
this.errorTips.e1 = message;
return false;
}
return true;
},
checkContactMethod() {
if (!this.data.contactMethod) {
let message = this.i18n.customService.reservation.errorTips.e1;
this.errorTips.e3 = message;
return false;
}
return true;
},
checkInstruction() {
if (!this.data.instruction) {
let message = this.i18n.customService.reservation.errorTips.e1;
this.errorTips.e5 = message;
return false;
}
return true;
},
checkContactDate() {
if (!this.data.contactDate) {
let message = this.i18n.customService.reservation.errorTips.e1;
this.errorTips.e7 = message;
return false;
}
return true;
}
},
watch: {
'data.name': function () {
this.errorTips.e1 = "";
},
'data.contactMethod': function () {
this.errorTips.e3 = "";
},
'data.instruction': function () {
this.errorTips.e5 = "";
},
'data.contactDate': function () {
this.errorTips.e7 = "";
}
},
mounted() {
this.initData();
},
created() { }
}