Blame view

src/pages/custom-service/components/complaint-acceptance.js 4.52 KB
simon 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
import { contactMethodCheck } from '@utils/utils.js';

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

simon committed
13 14 15 16
export default {
	data() {
		return {
			key: 'value',
joe committed
17 18
			isHkCus: true,
			checked: false,
joe committed
19
			contactTypeShow: "",
joe committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
			data: {
				name: "",
				contactType: "",
				contactMethod: "",
				complain: "",
				policyNumber: "",
				contactDate: ""
			},
			errorTips: {
				nameErr: "",
				contactTypeErr: "",
				contactMethodErr: "",
				complainErr: "",
				policyNumberErr: "",
				contactDateErr: ""
joe committed
35 36 37 38 39 40 41
			},

			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
simon committed
42 43
		}
	},
44
	components: {
joe committed
45 46 47
		DatePicker,
		Auth,
		modalComp
48
	},
simon committed
49 50 51 52 53 54
	computed: {
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
joe committed
55 56 57
		},
		contactTypes() {
			return this.i18n.complaintAcceptance.contactTypes;
simon committed
58 59 60
		}
	},
	methods: {
joe committed
61 62 63 64 65 66 67 68 69
		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
70
		initData() {
joe committed
71 72
			this.data.contactType = this.contactTypes[0].value;
			this.contactTypeShow = this.contactTypes[0].name;
joe committed
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
		},
		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() {
joe committed
100
			this.showModal(this.i18n.complaintAcceptance.success);
joe committed
101 102 103 104 105
			this.data.name = "";
			this.data.contactMethod = "";
			this.data.complain = "";
			this.data.policyNumber = "";
			this.data.contactDate = "";
joe committed
106
			this.checked = false;
joe committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
		},
		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;
			}
joe committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140
			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;
				}
			}
joe committed
141 142 143 144 145 146 147 148 149 150 151
			return true;
		},
		checkComplain() {
			if (!this.data.complain) {
				this.errorTips.complainErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		},
		checkPolicyNumber() {
			return true;
joe committed
152 153 154 155 156
			// if (!this.data.policyNumber) {
			// 	this.errorTips.policyNumberErr = this.i18n.complaintAcceptance.errorTips.e1;
			// 	return false;
			// }
			// return true;
joe committed
157 158 159 160 161 162 163 164 165 166 167 168 169
		},
		checkContactDate() {
			if (!this.data.contactDate) {
				this.errorTips.contactDateErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		}
	},
	watch: {
		'data.name': function () {
			this.errorTips.nameErr = "";
		},
joe committed
170
		'data.contactType': function (val) {
joe committed
171
			this.errorTips.contactTypeErr = "";
joe committed
172
			this.contactTypeShow = this.contactTypes[val - 1].name;
joe committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
		},
		'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();
simon committed
189
	},
joe committed
190
	created() { }
simon committed
191
}