complaint-acceptance.js 4.52 KB
import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'

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

import Auth from '@components/auth/auth.vue';
import modalComp from '@/components/modal-comp/modal-comp.vue';
import DatePicker from '@/components/date-picker/date-picker.vue'

export default {
	data() {
		return {
			key: 'value',
			isHkCus: true,
			checked: false,
			contactTypeShow: "",
			data: {
				name: "",
				contactType: "",
				contactMethod: "",
				complain: "",
				policyNumber: "",
				contactDate: ""
			},
			errorTips: {
				nameErr: "",
				contactTypeErr: "",
				contactMethodErr: "",
				complainErr: "",
				policyNumberErr: "",
				contactDateErr: ""
			},

			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.complaintAcceptance.contactTypes;
		}
	},
	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.contactTypeShow = this.contactTypes[0].name;
		},
		submitHandler() {
			if (!this.checked || this.isSubmit) {
				return;
			}
			let b1 = this.checkName();
			let b2 = this.checkContactType();
			let b3 = this.checkContactMethod();
			let b4 = this.checkComplain();
			let b5 = this.checkPolicyNumber();
			let b6 = this.checkContactDate();
			let b = b1 & b2 & b3 & b4 & b5 & b6;

			if (b) {
				this.isSubmit = true;
				httpPost({
					url: api.saveComplain,
					data: this.data
				}).then(() => {
					this.showSubmitSuccess();
					this.isSubmit = false;
				}).catch(() => {
					this.isSubmit = false;
				})
			}
		},
		showSubmitSuccess() {
			this.showModal(this.i18n.complaintAcceptance.success);
			this.data.name = "";
			this.data.contactMethod = "";
			this.data.complain = "";
			this.data.policyNumber = "";
			this.data.contactDate = "";
			this.checked = false;
		},
		checkName() {
			if (!this.data.name) {
				this.errorTips.nameErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		},
		checkContactType() {
			if (!this.data.contactType) {
				this.errorTips.contactTypeErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		},
		checkContactMethod() {
			if (!this.data.contactMethod) {
				this.errorTips.contactMethodErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			if (this.data.contactType == 1) {
				let hkMobile = contactMethodCheck('hkmobile', this.data.contactMethod);
				let zhMobile = contactMethodCheck('mobile', this.data.contactMethod);
				if (!hkMobile && !zhMobile) {
					this.errorTips.contactMethodErr = this.i18n.complaintAcceptance.errorTips.e2;
					return false;
				}
			} else {
				let emailCheck = contactMethodCheck('email', this.data.contactMethod);
				if (!emailCheck) {
					this.errorTips.contactMethodErr = this.i18n.complaintAcceptance.errorTips.e2;
					return false;
				}
			}
			return true;
		},
		checkComplain() {
			if (!this.data.complain) {
				this.errorTips.complainErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		},
		checkPolicyNumber() {
			return true;
			// if (!this.data.policyNumber) {
			// 	this.errorTips.policyNumberErr = this.i18n.complaintAcceptance.errorTips.e1;
			// 	return false;
			// }
			// return true;
		},
		checkContactDate() {
			if (!this.data.contactDate) {
				this.errorTips.contactDateErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		}
	},
	watch: {
		'data.name': function () {
			this.errorTips.nameErr = "";
		},
		'data.contactType': function (val) {
			this.errorTips.contactTypeErr = "";
			this.contactTypeShow = this.contactTypes[val - 1].name;
		},
		'data.contactMethod': function () {
			this.errorTips.contactMethodErr = "";
		},
		'data.complain': function () {
			this.errorTips.complainErr = "";
		},
		'data.policyNumber': function () {
			this.errorTips.policyNumberErr = "";
		},
		'data.contactDate': function () {
			this.errorTips.contactDateErr = "";
		}
	},
	mounted() {
		this.initData();
	},
	created() { }
}