Blame view

src/pages/custom-service/components/complaint-acceptance.js 6.19 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
import { contactMethodCheck, policyNumberCheck } from '@utils/utils.js';
joe committed
8 9 10

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

import { checkName } from '@/utils/utils.js';
import { Select, Option } from 'element-ui';

joe committed
16 17 18
import Vue from 'vue';
import { Loading } from 'vant';
Vue.use(Loading);
joe committed
19 20
Vue.use(Select);
Vue.use(Option);
21

simon committed
22 23 24 25
export default {
	data() {
		return {
			key: 'value',
joe committed
26 27
			isHkCus: true,
			checked: false,
1  
joe committed
28
			isSubmit: false,
joe committed
29
			contactIconShow: "",
joe committed
30
			contactTypeShow: "",
1  
joe committed
31
			contactPlaceHolderShow: "",
joe committed
32
			contactDateError: false,
joe committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
			data: {
				name: "",
				contactType: "",
				contactMethod: "",
				complain: "",
				policyNumber: "",
				contactDate: ""
			},
			errorTips: {
				nameErr: "",
				contactTypeErr: "",
				contactMethodErr: "",
				complainErr: "",
				policyNumberErr: "",
				contactDateErr: ""
joe committed
48
			},
joe committed
49
			// 联系方式
joe committed
50 51 52 53 54
			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
simon committed
55 56
		}
	},
57
	components: {
joe committed
58 59 60
		DatePicker,
		Auth,
		modalComp
61
	},
simon committed
62 63 64 65 66 67
	computed: {
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
joe committed
68 69 70
		},
		contactTypes() {
			return this.i18n.complaintAcceptance.contactTypes;
71 72 73 74
		},
		submitBtnDisabled() {
			let b1 = !this.checked;
			let b2 = this.data.contactDate ? false : true;
joe committed
75
			let b3 = checkName(this.data.name) ? false : true;
76 77
			let b4 = this.checkContactMethod() ? true : false;
			let b5 = this.data.complain ? false : true;
joe committed
78 79 80
			let b6 = this.contactDateError;
			let b7 = this.data.policyNumber && !policyNumberCheck(this.data.policyNumber);
			return b1 || b2 || b3 || b4 || b5 || b6 || b7;
simon committed
81 82 83
		}
	},
	methods: {
joe committed
84 85 86 87 88 89
		checkDate(data) {
			this.contactDateError = data.disable;
			if (this.contactDateError) {
				this.errorTips.contactDateErr = this.i18n.reservation.errorTips.e4;
			}
		},
joe committed
90 91 92 93 94 95 96 97 98
		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
99
		initData() {
joe committed
100
			this.data.contactType = this.contactTypes[0].value;
joe committed
101 102
			this.contactTypeShow = this.contactTypes[0].show;
			this.contactIconShow = this.contactTypes[0].icon;
joe committed
103 104 105 106 107
		},
		submitHandler() {
			if (!this.checked || this.isSubmit) {
				return;
			}
108 109 110 111
			let b3 = this.checkContactMethod();
			if (b3) {
				this.errorTips.contactMethodErr = b3;
			}
joe committed
112 113 114 115 116
			this.checkName();
			this.checkContactType();
			this.checkComplain();
			this.checkPolicyNumber();
			this.checkContactDate();
joe committed
117

joe committed
118
			if (!this.submitBtnDisabled) {
joe committed
119 120 121 122 123 124 125 126 127 128 129 130 131
				this.isSubmit = true;
				httpPost({
					url: api.saveComplain,
					data: this.data
				}).then(() => {
					this.showSubmitSuccess();
					this.isSubmit = false;
				}).catch(() => {
					this.isSubmit = false;
				})
			}
		},
		showSubmitSuccess() {
joe committed
132
			this.showModal(this.i18n.complaintAcceptance.success);
1  
joe committed
133 134
			// this.data.name = "";
			// this.data.contactMethod = "";
joe committed
135 136 137
			this.data.complain = "";
			this.data.policyNumber = "";
			this.data.contactDate = "";
joe committed
138
			this.checked = false;
joe committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
		},
		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) {
156
				return this.i18n.complaintAcceptance.errorTips.e1;
joe committed
157
			}
joe committed
158 159 160 161
			if (this.data.contactType == 1) {
				let hkMobile = contactMethodCheck('hkmobile', this.data.contactMethod);
				let zhMobile = contactMethodCheck('mobile', this.data.contactMethod);
				if (!hkMobile && !zhMobile) {
joe committed
162
					return this.i18n.complaintAcceptance.errorTips.e4;
joe committed
163 164 165 166
				}
			} else {
				let emailCheck = contactMethodCheck('email', this.data.contactMethod);
				if (!emailCheck) {
joe committed
167
					return this.i18n.complaintAcceptance.errorTips.e5;
joe committed
168 169
				}
			}
170
			return "";
joe committed
171 172 173 174 175 176 177 178 179
		},
		checkComplain() {
			if (!this.data.complain) {
				this.errorTips.complainErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
			return true;
		},
		checkPolicyNumber() {
1  
joe committed
180
			this.data.policyNumber = this.data.policyNumber ? this.data.policyNumber.replace(/\s*/g, "") : "";
joe committed
181
			if (this.data.policyNumber && !policyNumberCheck(this.data.policyNumber)) {
1  
joe committed
182 183 184
				this.errorTips.policyNumberErr = this.i18n.complaintAcceptance.errorTips.e3;
				return false;
			}
joe committed
185 186 187 188 189 190 191
			return true;
		},
		checkContactDate() {
			if (!this.data.contactDate) {
				this.errorTips.contactDateErr = this.i18n.complaintAcceptance.errorTips.e1;
				return false;
			}
joe committed
192 193 194
			if (this.contactDateError) {
				return false;
			}
joe committed
195
			return true;
joe committed
196 197 198 199
		},
		userLogin(uinfo) {
			if (uinfo && uinfo.hadFullInfo == "1") {
				httpPost({ url: api.profile, sid: true }).then(res => {
1  
joe committed
200
					if (res && res.fullName) {
joe committed
201 202 203
						this.data.name = res.fullName;
						this.data.contactMethod = res.mobileNo;
					}
1  
joe committed
204
				}).catch(err => {
joe committed
205 206 207

				});
			}
joe committed
208 209 210 211
		}
	},
	watch: {
		'data.name': function () {
joe committed
212 213 214 215 216 217 218
			// this.errorTips.nameErr = "";

			if (checkName(this.data.name)) {
				this.errorTips.nameErr = "";
			} else {
				this.errorTips.nameErr = this.i18n.error.nameTip;
			}
joe committed
219
		},
joe committed
220
		'data.contactType': function (val) {
joe committed
221
			this.errorTips.contactTypeErr = "";
joe committed
222 223
			this.contactTypeShow = this.contactTypes[val - 1].show;
			this.contactIconShow = this.contactTypes[val - 1].icon;
1  
joe committed
224
			this.contactPlaceHolderShow = this.contactTypes[val - 1].placeholder;
joe committed
225 226
		},
		'data.contactMethod': function () {
joe committed
227 228 229 230 231 232
			let b3 = this.checkContactMethod();
			if (b3) {
				this.errorTips.contactMethodErr = b3;
			} else {
				this.errorTips.contactMethodErr = "";
			}
joe committed
233 234 235 236 237 238 239 240 241 242 243 244 245
		},
		'data.complain': function () {
			this.errorTips.complainErr = "";
		},
		'data.policyNumber': function () {
			this.errorTips.policyNumberErr = "";
		},
		'data.contactDate': function () {
			this.errorTips.contactDateErr = "";
		}
	},
	mounted() {
		this.initData();
simon committed
246
	},
joe committed
247
	created() { }
simon committed
248
}