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'; 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: "" }, 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; } }, methods: { 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 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() { 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() { if (!this.data.contactMethod) { let message = this.i18n.reservation.errorTips.e1; this.errorTips.e3 = message; return false; } return true; }, 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; } 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() { } }