Blame view

src/pages/custom-service/components/reservation.js 5.04 KB
joe committed
1 2 3 4 5 6
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'

joe committed
7 8 9 10 11
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';
joe committed
12 13 14

import { checkName } from '@/utils/utils.js';

joe committed
15 16 17
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);
18

joe committed
19 20 21
export default {
	data() {
		return {
joe committed
22
			isSubmit: false,
1  
joe committed
23
			key: 'value',
joe committed
24 25
			isHkCus: true,
			checked: false,
joe committed
26
			contactDateError: false,
joe committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
			data: {
				name: "",
				contactType: "",
				contactMethod: "",
				reservationType: "",
				instruction: "",
				hkCustomer: "",
				contactDate: ""
			},
			errorTips: {
				e1: "",
				e2: "",
				e3: "",
				e4: "",
				e5: "",
				e6: "",
43 44
				e7: "",
				e8: ""
joe committed
45 46 47 48 49 50
			},
			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
joe committed
51 52
		}
	},
53
	components: {
joe committed
54 55 56
		DatePicker,
		Auth,
		modalComp
57
	},
joe committed
58 59 60 61 62 63
	computed: {
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
joe committed
64
		},
joe committed
65
		contactTypes() {
joe committed
66
			return this.i18n.reservation.contactTypeCadidates;
joe committed
67 68
		},
		reservationTypes() {
joe committed
69
			return this.i18n.reservation.reservationCandidates;
70 71 72 73
		},
		submitBtnDisabled() {
			let b1 = !this.checked;
			let b2 = this.data.contactDate ? false : true;
joe committed
74
			let b3 = checkName(this.data.name) ? false : true;
75
			let b4 = this.checkContactMethod() ? true : false;
joe committed
76 77
			let b5 = this.contactDateError;
			return b1 || b2 || b3 || b4 || b5;
joe committed
78 79 80
		}
	},
	methods: {
simon committed
81
		// 校验日期,日期变更后触发,包含点击和文本输入
joe committed
82 83 84 85 86
		checkDate(data) {
			this.contactDateError = data.disable;
			if (this.contactDateError) {
				this.errorTips.e7 = this.i18n.reservation.errorTips.e4;
			}
simon committed
87
		},
joe committed
88 89 90 91 92 93 94 95 96
		showModal(content, icon) {
			icon = !icon || typeof icon === "undefined" ? "succ" : icon;
			this.modalIcon = icon;
			this.modalContent = content;
			this.modalVisiable = true;
		},
		modalCallback() {
			this.modalVisiable = false;
		},
joe committed
97
		initData() {
joe committed
98 99
			this.data.contactType = this.contactTypes[0].value;
			this.data.reservationType = this.reservationTypes[0].value;
joe committed
100 101
		},
		submitHandler() {
joe committed
102
			if (!this.checked || this.isSubmit) {
joe committed
103 104
				return;
			}
105 106 107 108 109
			let err = this.checkContactMethod();
			if (err) {
				this.errorTips.e3 = err;
				return;
			}
joe committed
110 111 112 113 114
			this.checkName();
			this.checkInstruction();
			this.checkContactDate();
			if (this.submitBtnDisabled) {
				return;
joe committed
115
			}
joe committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

			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;
			});
joe committed
133
		},
joe committed
134
		showSubmitSuccess() {
joe committed
135
			this.showModal(this.i18n.reservation.success);
joe committed
136 137 138
			this.data.name = "";
			this.data.contactMethod = "";
			this.data.instruction = "";
joe committed
139
			this.checked = false;
joe committed
140 141 142
		},
		checkName() {
			if (!this.data.name) {
joe committed
143
				let message = this.i18n.reservation.errorTips.e1;
joe committed
144 145 146 147 148 149
				this.errorTips.e1 = message;
				return false;
			}
			return true;
		},
		checkContactMethod() {
1  
joe committed
150 151 152
			let hkMobile = contactMethodCheck('hkmobile', this.data.contactMethod);
			let zhMobile = contactMethodCheck('mobile', this.data.contactMethod);
			if (!hkMobile && !zhMobile) {
153
				return this.i18n.login.tips.oe0;
joe committed
154
			}
155
			return "";
joe committed
156 157
		},
		checkInstruction() {
joe committed
158 159 160 161 162
			// if (!this.data.instruction) {
			// 	let message = this.i18n.reservation.errorTips.e1;
			// 	this.errorTips.e5 = message;
			// 	return false;
			// }
joe committed
163 164 165 166
			return true;
		},
		checkContactDate() {
			if (!this.data.contactDate) {
joe committed
167
				let message = this.i18n.reservation.errorTips.e1;
joe committed
168 169 170
				this.errorTips.e7 = message;
				return false;
			}
joe committed
171 172 173
			if (this.contactDateError) {
				return false;
			}
joe committed
174
			return true;
joe committed
175 176 177 178
		},
		userLogin(uinfo) {
			if (uinfo && uinfo.hadFullInfo == "1") {
				httpPost({ url: api.profile, sid: true }).then(res => {
1  
joe committed
179
					if (res && res.fullName) {
joe committed
180 181 182
						this.data.name = res.fullName;
						this.data.contactMethod = res.mobileNo;
					}
1  
joe committed
183
				}).catch(err => {
joe committed
184 185 186

				});
			}
joe committed
187 188 189 190
		}
	},
	watch: {
		'data.name': function () {
joe committed
191
			this.errorTips.e8 = "";
joe committed
192 193 194 195 196 197

			if (checkName(this.data.name)) {
				this.errorTips.e1 = "";
			} else {
				this.errorTips.e1 = this.i18n.error.nameTip;
			}
joe committed
198 199
		},
		'data.contactMethod': function () {
joe committed
200 201 202 203 204 205 206 207
			this.errorTips.e8 = "";
			let b = this.checkContactMethod();
			if (b) {
				this.errorTips.e3 = b;
			} else {
				this.errorTips.e3 = "";
			}

joe committed
208
		},
1  
joe committed
209
		'data.instruction': function (v, ov) {
1  
joe committed
210
			if (v && v.length > 1000) {
1  
joe committed
211 212
				this.data.instruction = v.substring(0, 1000);
			}
joe committed
213
			this.errorTips.e8 = "";
joe committed
214 215
			this.errorTips.e5 = "";
		},
216 217 218
		'data.reservationType': function () {
			this.errorTips.e8 = "";
		},
joe committed
219
		'data.contactDate': function () {
joe committed
220
			this.errorTips.e8 = "";
joe committed
221 222 223 224 225
			this.errorTips.e7 = "";
		}
	},
	mounted() {
		this.initData();
joe committed
226
	},
joe committed
227
	created() { }
joe committed
228
}