reservation.js
4.79 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import { contactMethodCheck } from '@utils/utils.js';
import DatePicker from '@/components/date-picker/date-picker.vue';
import Auth from '@components/auth/auth.vue';
import modalComp from '@/components/modal-comp/modal-comp.vue';
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);
export default {
data() {
return {
isSubmit: false,
key: 'value',
isHkCus: true,
checked: false,
contactDateError: false,
data: {
name: "",
contactType: "",
contactMethod: "",
reservationType: "",
instruction: "",
hkCustomer: "",
contactDate: ""
},
errorTips: {
e1: "",
e2: "",
e3: "",
e4: "",
e5: "",
e6: "",
e7: "",
e8: ""
},
modalSimpleVisiable: false,
modalVisiable: false,
targetPath: "",
modalIcon: "succ",
modalContent: "",
}
},
components: {
DatePicker,
Auth,
modalComp
},
computed: {
locale() {
return this.$i18n.locale || 'tc';
},
i18n() {
return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
},
contactTypes() {
return this.i18n.reservation.contactTypeCadidates;
},
reservationTypes() {
return this.i18n.reservation.reservationCandidates;
},
submitBtnDisabled() {
let b1 = !this.checked;
let b2 = this.data.contactDate ? false : true;
let b3 = this.data.name ? false : true;
let b4 = this.checkContactMethod() ? true : false;
let b5 = this.contactDateError;
return b1 || b2 || b3 || b4 || b5;
}
},
methods: {
// 校验日期,日期变更后触发,包含点击和文本输入
checkDate(data) {
this.contactDateError = data.disable;
if (this.contactDateError) {
this.errorTips.e7 = this.i18n.reservation.errorTips.e4;
}
},
showModal(content, icon) {
icon = !icon || typeof icon === "undefined" ? "succ" : icon;
this.modalIcon = icon;
this.modalContent = content;
this.modalVisiable = true;
},
modalCallback() {
this.modalVisiable = false;
},
initData() {
this.data.contactType = this.contactTypes[0].value;
this.data.reservationType = this.reservationTypes[0].value;
},
submitHandler() {
if (!this.checked || this.isSubmit) {
return;
}
let err = this.checkContactMethod();
if (err) {
this.errorTips.e3 = err;
return;
}
this.checkName();
this.checkInstruction();
this.checkContactDate();
if (this.submitBtnDisabled) {
return;
}
this.isSubmit = true;
this.data.hkCustomer = this.isHkCus ? 1 : 0;
httpPost({
url: api.saveReservation,
data: this.data
}).then(() => {
this.showSubmitSuccess();
this.isSubmit = false;
}).catch(e => {
switch (e.code) {
case 3001:
this.errorTips.e8 = this.i18n.reservation.errorTips.e3;
break;
}
this.isSubmit = false;
});
},
showSubmitSuccess() {
this.showModal(this.i18n.reservation.success);
this.data.name = "";
this.data.contactMethod = "";
this.data.instruction = "";
this.checked = false;
},
checkName() {
if (!this.data.name) {
let message = this.i18n.reservation.errorTips.e1;
this.errorTips.e1 = message;
return false;
}
return true;
},
checkContactMethod() {
let hkMobile = contactMethodCheck('hkmobile', this.data.contactMethod);
let zhMobile = contactMethodCheck('mobile', this.data.contactMethod);
if (!hkMobile && !zhMobile) {
return this.i18n.login.tips.oe0;
}
return "";
},
checkInstruction() {
// if (!this.data.instruction) {
// let message = this.i18n.reservation.errorTips.e1;
// this.errorTips.e5 = message;
// return false;
// }
return true;
},
checkContactDate() {
if (!this.data.contactDate) {
let message = this.i18n.reservation.errorTips.e1;
this.errorTips.e7 = message;
return false;
}
if (this.contactDateError) {
return false;
}
return true;
},
userLogin(uinfo) {
if (uinfo && uinfo.hadFullInfo == "1") {
httpPost({ url: api.profile, sid: true }).then(res => {
if (res && res.fullName) {
this.data.name = res.fullName;
this.data.contactMethod = res.mobileNo;
}
}).catch(err => {
});
}
}
},
watch: {
'data.name': function () {
this.errorTips.e8 = "";
this.errorTips.e1 = "";
},
'data.contactMethod': function () {
this.errorTips.e8 = "";
let b = this.checkContactMethod();
if (b) {
this.errorTips.e3 = b;
} else {
this.errorTips.e3 = "";
}
},
'data.instruction': function () {
this.errorTips.e8 = "";
this.errorTips.e5 = "";
},
'data.reservationType': function () {
this.errorTips.e8 = "";
},
'data.contactDate': function () {
this.errorTips.e8 = "";
this.errorTips.e7 = "";
}
},
mounted() {
this.initData();
},
created() { }
}