complaint-acceptance.js 5.26 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'
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);

export default {
	data() {
		return {
			key: 'value',
			isHkCus: true,
			checked: false,
			isSubmit: false,
			contactIconShow: "",
			contactTypeShow: "",
			contactPlaceHolderShow: "",
			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].show;
			this.contactIconShow = this.contactTypes[0].icon;
		},
		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() {
			this.data.policyNumber = this.data.policyNumber ? this.data.policyNumber.replace(/\s*/g, "") : "";
			if (this.data.policyNumber && this.data.policyNumber.length != 16) {
				this.errorTips.policyNumberErr = this.i18n.complaintAcceptance.errorTips.e3;
				return false;
			}
			return true;
		},
		checkContactDate() {
			if (!this.data.contactDate) {
				this.errorTips.contactDateErr = this.i18n.complaintAcceptance.errorTips.e1;
				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.nameErr = "";
		},
		'data.contactType': function (val) {
			this.errorTips.contactTypeErr = "";
			this.contactTypeShow = this.contactTypes[val - 1].show;
			this.contactIconShow = this.contactTypes[val - 1].icon;
			this.contactPlaceHolderShow = this.contactTypes[val - 1].placeholder;
		},
		'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() { }
}