Blame view

src/pages/custom-service/components/policy-change-information.js 12.7 KB
1  
joe committed
1 2
import { mapState } from "vuex";

simon committed
3 4
import api from '@/api/api'
import {
joe committed
5
	formdata,
simon committed
6 7 8
	httpPost
} from '@/api/fetch-api.js'

joe committed
9 10 11
import { getNationsList, getMarryList, getPolicyIdTypeList } from '@/utils/biz.js';
import { setTitle } from '@/utils/utils.js';

joe committed
12
import Auth from '@components/auth/auth.vue';
joe committed
13 14 15
import PolicyHeadList from "./policy-head-list.vue";
import DatePicker from '@/components/date-picker/date-picker.vue'
import modalComp from '@/components/modal-comp/modal-comp.vue';
simon committed
16
import modalUploadCardComp from '@/components/modal-upload-card-comp/modal-upload-card-comp.vue';
joe committed
17
import Vue from 'vue';
1  
joe committed
18
import { Loading, Field } from 'vant';
joe committed
19
Vue.use(Loading);
simon committed
20

simon committed
21 22 23
export default {
	data() {
		return {
joe committed
24 25
			loading: false,
			showForm: false,
simon committed
26
			key: 'value',
joe committed
27
			isOwner: true,
simon committed
28 29
			checked: false,
			modalUploadCardVisiable: false,
joe committed
30 31 32
			selectedPolicies: [],
			data: null,
			// 保单信息
1  
joe committed
33
			policyOld: null,
joe committed
34
			policy: null,
joe committed
35 36 37
			// ID证件照引用
			idFront: null,
			idBack: null,
joe committed
38 39 40 41 42 43 44

			// 模态窗
			modalSimpleVisiable: false,
			modalVisiable: false,
			targetPath: "",
			modalIcon: "succ",
			modalContent: "",
joe committed
45
			showIdNumber: false,
1  
joe committed
46 47

			showType: ""
simon committed
48 49
		}
	},
simon committed
50
	components: {
joe committed
51
		modalUploadCardComp,
joe committed
52 53 54 55
		PolicyHeadList,
		Auth,
		DatePicker,
		modalComp
simon committed
56
	},
simon committed
57
	computed: {
1  
joe committed
58 59 60
		...mapState({
			userInfo: state => state.userInfo
		}),
simon committed
61 62 63 64 65
		locale() {
			return this.$i18n.locale || 'tc';
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
joe committed
66 67 68 69 70 71 72 73 74
		},
		sexCandidates() {
			let i18n = this.$i18n.messages[this.$i18n.locale];
			return i18n.infomationImprove.candidates.sex;
		},
		idTypeCandidates() {
			let i18n = this.$i18n.messages[this.$i18n.locale];
			return i18n.infomationImprove.candidates.idType;
		},
joe committed
75
		nationList() {
joe committed
76
			return getNationsList(this.$i18n.locale);
joe committed
77 78
		},
		marryList() {
joe committed
79
			return getMarryList(this.$i18n.locale);
joe committed
80 81
		},
		policyIdTypeList() {
joe committed
82
			return getPolicyIdTypeList(this.$i18n.locale);
joe committed
83
		}
simon committed
84
	},
simon committed
85
	methods: {
joe committed
86

joe committed
87 88 89 90 91 92 93 94 95 96
		showModal(content, icon) {
			icon = !icon || typeof icon === "undefined" ? "succ" : icon;
			this.modalIcon = icon;
			this.modalContent = content;
			this.modalVisiable = true;
		},
		modalCallback() {
			this.modalVisiable = false;
		},
		loadData() {
joe committed
97 98 99
			// if (this.isOwner && this.data) {
			// 	return;
			// }
1  
joe committed
100

joe committed
101 102 103 104 105 106 107 108 109 110 111 112 113
			if (this.loading) {
				return;
			}
			this.loading = true;
			this.data = null;
			let param = {
				policyId: this.selectedPolicies[0].id,
				policyCode: this.selectedPolicies[0].code
			};
			httpPost({
				url: api.policyDetail,
				data: param,
				sid: true
joe committed
114
			}).then(res => {
joe committed
115
				this.loading = false;
joe committed
116
				if (res) {
1  
joe committed
117 118 119 120 121 122 123 124 125
					if (res != null) {
						this.policy = JSON.parse(JSON.stringify(res));
						this.policyOld = JSON.parse(JSON.stringify(res));
						this.policy.clientBirthday = this.policy.clientBirthday ? this.policy.clientBirthday.split(" ")[0] : "";
						this.policy.insuredBirthday = this.policy.insuredBirthday ? this.policy.insuredBirthday.split(" ")[0] : "";
						this.policyOld.clientBirthday = this.policyOld.clientBirthday ? this.policyOld.clientBirthday.split(" ")[0] : "";
						this.policyOld.insuredBirthday = this.policyOld.insuredBirthday ? this.policyOld.insuredBirthday.split(" ")[0] : "";
						this.initData();
					}
joe committed
126

1  
joe committed
127 128 129 130 131 132 133 134 135
					// let clientNameCn = res.clientNameCn ? res.clientNameCn : res.clientNameEn;
					// let clientNameEn = res.clientNameEn ? res.clientNameEn : res.clientNameCn;
					// let insuredNameCn = res.insuredNameCn ? res.insuredNameCn : res.insuredNameEn;
					// let insuredNameEn = res.insuredNameEn ? res.insuredNameEn : res.insuredNameCn;
					// this.policy.clientName = this.locale == 'en' ? clientNameEn : clientNameCn;
					// this.policy.insuredName = this.locale == 'en' ? insuredNameEn : insuredNameCn;
					// // 证件类型、证件号要备份,用于比较
					// this.policy.clientIdTypeBak = this.policy.clientIdType;
					// this.policy.clientIdNumberBak = this.policy.clientIdNumber;
joe committed
136

1  
joe committed
137 138
					// this.policy.insuredIdTypeBak = this.policy.insuredIdType;
					// this.policy.insuredIdNumberBak = this.policy.insuredIdNumber;
joe committed
139
				}
joe committed
140
			}).catch(err => {
joe committed
141
				this.loading = false;
joe committed
142
				this.handleErrResponse(err);
joe committed
143 144 145
			});
		},
		initData() {
joe committed
146 147
			this.idFront = null;
			this.idBack = null;
joe committed
148
			let res = this.policy;
joe committed
149 150
			if (res) {
				let isOwner = this.isOwner;
1  
joe committed
151

joe committed
152
				let data = {
1  
joe committed
153 154
					nameCn: isOwner ? res.clientNameCn : res.insuredNameCn,
					nameEn: isOwner ? res.clientNameEn : res.insuredNameEn,
joe committed
155 156 157 158 159 160 161 162 163 164 165
					idType: isOwner ? res.clientIdType : res.insuredIdType,
					idNumber: isOwner ? res.clientIdNumber : res.insuredIdNumber,
					idExpireAt: isOwner ? res.clientExpireAt : res.insuredExpireAt,
					nature: isOwner ? res.clientNationality : res.insuredNationality,
					company: isOwner ? res.clientCompany : res.insuredCompany,
					marriage: isOwner ? res.clientMarriage : res.insuredMarriage,
					sex: isOwner ? res.clientSex : res.insuredSex,
					birthday: isOwner ? res.clientBirthday : res.insuredBirthday
				};
				data.sex = data.sex ? data.sex : "M";
				this.$set(this, 'data', data);
joe committed
166 167 168 169 170 171
			}
		},
		handlePolicySelect(data) {
			this.selectedPolicies = data;
			this.loadData();
		},
1  
joe committed
172

joe committed
173
		handleUpdatePolicy() {
1  
joe committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
			if (this.loading) {
				return;
			}
			this.showType = null;
			let showUploadPicDialog = false;
			this.replaceData();
			let showOwner = this.policy.clientIdType != this.policyOld.clientIdType || this.policy.clientIdNumber != this.policyOld.clientIdNumber;
			let showInsured = this.policy.insuredIdType != this.policyOld.insuredIdType || this.policy.insuredIdNumber != this.policyOld.insuredIdNumber;
			let showType = showOwner ? "owner" : null;
			if (showInsured) {
				showType = showType ? "both" : "insured";
			}
			showUploadPicDialog = showType ? true : false;
			this.showType = showType;

			if (showUploadPicDialog) {
				this.modalUploadCardVisiable = true;
			} else {
				this.loading = true;
				this.updatePolicyInfoV2();
			}
		},
		handleUpdatePolicyWithFile(data) {
			this.modalUploadCardVisiable = false;
			if (this.loading) {
				return;
			}
			this.loading = true;
			let nameCache = [];
			let myFormData = new FormData();
			(data.ownerFrontPicFile) && (myFormData.append("files", data.ownerFrontPicFile), nameCache.push("clientIdFrontStoragePath"));
			(data.ownerBackPicFile) && (myFormData.append("files", data.ownerBackPicFile), nameCache.push("clientIdBackStoragePath"));
			(data.insuredFrontPicFile) && (myFormData.append("files", data.insuredFrontPicFile), nameCache.push("insuredIdFrontStoragePath"));
			(data.insuredBackPicFile) && (myFormData.append("files", data.insuredBackPicFile), nameCache.push("insuredIdBackStoragePath"));
			formdata({ "url": api.updateIdFileV2, "myFormData": myFormData, "sid": true }).then(res => {
				let list = res.content;
				let fileIds = {};
				for (let index = 0; index < list.length; index++) {
					fileIds[nameCache[index]] = list[index];
				}
				this.updatePolicyInfoV2(fileIds);
			}).catch(err => {
				this.loading = false;
				this.handleErrResponse(err);
			});

		},
		// 旧接口备份
		handleUpdatePolicyBak() {
joe committed
223 224 225 226 227 228 229 230 231 232 233 234
			let showUploadPicDialog = false;
			if (this.isOwner) {
				showUploadPicDialog = (this.policy.clientIdType != this.data.idType || this.policy.clientIdNumber != this.data.idNumber);
			} else {
				showUploadPicDialog = (this.policy.insuredIdType != this.data.idType || this.policy.insuredIdNumber != this.data.idNumber);
			}
			if (showUploadPicDialog) {
				this.modalUploadCardVisiable = true;
			} else {
				this.updatePolicyInfo();
			}
		},
1  
joe committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
		updatePolicyInfoV2(idFiles) {
			let data = {
				policyId: this.policy.policyId,
				policyCode: this.policy.policyCode,
				insuredNameEn: this.policy.insuredNameEn,
				insuredNameCn: this.policy.insuredNameCn,
				insuredIdType: this.policy.insuredIdType,
				insuredIdNumber: this.policy.insuredIdNumber,
				insuredExpireAt: this.policy.insuredExpireAt,
				insuredNationality: this.policy.insuredNationality,
				insuredCompany: this.policy.insuredCompany,
				insuredMarriage: this.policy.insuredMarriage,
				insuredSex: this.policy.insuredSex,
				insuredBirthday: this.policy.insuredBirthday,
				clientNameEn: this.policy.clientNameEn,
				clientNameCn: this.policy.clientNameCn,
				clientIdType: this.policy.clientIdType,
				clientIdNumber: this.policy.clientIdNumber,
				clientExpireAt: this.policy.clientExpireAt,
				clientNationality: this.policy.clientNationality,
				clientCompany: this.policy.clientCompany,
				clientMarriage: this.policy.clientMarriage,
				clientSex: this.policy.clientSex,
				clientBirthday: this.policy.clientBirthday
			};
			if (idFiles) {
				for (let k in idFiles) {
					data[k] = idFiles[k];
				}
			}

			httpPost({ url: api.updatePolicyInfoV2, data: data, sid: true }).then(res => {
				if (this.isOwner) {
					let userInfo = JSON.parse(JSON.stringify(this.userInfo));
					userInfo.name = data.clientNameCn ? data.clientNameCn : data.clientNameEn;
					if (userInfo.name) {
						this.$store.commit("SET_USER_INFO", userInfo);
					}
				}
				this.loading = false;
				this.showModal(this.i18n.policyChangeInformation.success);
			}).catch(err => {
				this.loading = false;
				this.handleErrResponse(err);
			});

		},

		// 旧接口备份
		handleUpdatePolicyWithFileBak(data) {
joe committed
285 286 287 288 289 290
			this.idFront = data.front;
			this.idBack = data.back;
			this.updatePolicyIdPic().then(() => {
				this.updatePolicyInfo();
			});
		},
joe committed
291 292 293 294 295 296 297 298 299
		updatePolicyInfo() {
			if (this.loading) {
				return;
			}
			this.loading = true;
			let param = JSON.parse(JSON.stringify(this.data));
			delete param.birthday;
			delete param.sex;
			param.modifyObj = this.isOwner ? 1 : 2;
1  
joe committed
300 301 302 303 304
			let policies = [];

			this.selectedPolicies.forEach(element => {
				policies.push({ policyId: element.id, policyCode: element.code });
			});
joe committed
305

1  
joe committed
306
			param.policies = policies;
joe committed
307
			httpPost({ url: api.updatePolicyInfo, data: param, sid: true }).then(res => {
1  
joe committed
308 309 310 311 312
				if (this.isOwner && param.name) {
					let userInfo = JSON.parse(JSON.stringify(this.userInfo));
					userInfo.name = param.name;
					this.$store.commit("SET_USER_INFO", userInfo);
				}
joe committed
313 314 315 316
				this.loading = false;
				this.showModal(this.i18n.policyChangeInformation.success);
			}).catch(err => {
				this.loading = false;
joe committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
				this.handleErrResponse(err);
			});
		},
		updatePolicyIdPic() {
			return new Promise((resolve, reject) => {
				if (this.loading) {
					return;
				}
				this.loading = true;
				let param = {
					policyId: this.selectedPolicies[0].id,
					policyCode: this.selectedPolicies[0].code,
					modifyObj: this.isOwner ? 1 : 2,
					front: this.idFront,
					back: this.idBack
				};
				this.modalUploadCardVisiable = false;
				formdata({ url: api.idPicUpload, data: param, sid: true }).then(res => {
					this.loading = false;
					resolve();
				}).catch(err => {
					this.loading = false;
					this.handleErrResponse(err);
				});
			});
		},
1  
joe committed
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
		replaceData() {
			if (!this.isOwner) {
				// 需要缓存结果,注意取反,此处存在受保人信息
				this.policy.insuredNameEn = this.data.nameEn;
				this.policy.insuredNameCn = this.data.nameCn;
				this.policy.insuredIdType = this.data.idType;
				this.policy.insuredIdNumber = this.data.idNumber;
				this.policy.insuredExpireAt = this.data.idExpireAt;
				this.policy.insuredNationality = this.data.nature;
				this.policy.insuredCompany = this.data.company;
				this.policy.insuredMarriage = this.data.marriage;
				this.policy.insuredSex = this.data.sex;
				this.policy.insuredBirthday = this.data.birthday;
			} else {
				// 需要缓存结果,注意取反,此处存在投保人信息
				this.policy.clientNameEn = this.data.nameEn;
				this.policy.clientNameCn = this.data.nameCn;
				this.policy.clientIdType = this.data.idType;
				this.policy.clientIdNumber = this.data.idNumber;
				this.policy.clientExpireAt = this.data.idExpireAt;
				this.policy.clientNationality = this.data.nature;
				this.policy.clientCompany = this.data.company;
				this.policy.clientMarriage = this.data.marriage;
				this.policy.clientSex = this.data.sex;
				this.policy.clientBirthday = this.data.birthday;
			}
		},
joe committed
370 371 372 373 374 375 376
		switchPolicyRole(role) {
			if (this.isOwner && role == 1) {
				return;
			}
			if (!this.isOwner && role == 2) {
				return;
			}
1  
joe committed
377
			this.replaceData();
joe committed
378 379 380 381 382
			this.isOwner = role == 1 ? true : false;
			this.initData();
		},
		handleErrResponse(err) {
			if (err) {
joe committed
383 384 385
				if (err.code == 404) {
					this.$refs.auth.noAuth();
				}
joe committed
386 387 388 389
				if (err.errMsg) {
					this.showModal(errMsg, 'info');
				}
			}
joe committed
390
		},
1  
joe committed
391 392 393 394 395 396 397 398
		toContactUs() {
			this.$router.push({
				path: "/custom/service",
				query: {
					q: "m1"
				}
			});
		},
joe committed
399 400 401 402 403
		userLogout() {
			this.showForm = false;
		},
		userLogin(data) {
			this.showForm = true;
joe committed
404 405 406 407 408 409 410 411
		},
		initTitle() {
			try {
				let title = this.i18n.customService.menu43;
				setTitle(title);
			} catch (e) {

			}
joe committed
412 413 414
		}
	},
	mounted() {
joe committed
415
		this.isOwner = this.$route.query.u == 2 ? false : true;
joe committed
416
		this.initTitle();
simon committed
417
	},
joe committed
418
	created() { }
simon committed
419
}