Blame view

src/components/vhis-modal/vhis-modal.js 7.76 KB
simon committed
1 2 3 4 5
/**
 * 组件描述:网销弹窗组件
 * 该组件挂载在app.vue内跟导航header,页脚footer,主要内容main同级
 */

simon committed
6 7 8
import {
	mapState
} from "vuex";
joe committed
9 10
import api from '@/api/api'
import {
simon committed
11 12 13
	httpGet,
	httpPost,
	requestDomain
joe committed
14 15
} from '@/api/fetch-api.js'

joe committed
16
import Modal2Comp from '@/components/modal2-comp/modal2-comp.vue';
simon committed
17

simon committed
18 19 20
import {
	getPolicyName
} from "@/utils/biz.js";
joe committed
21

simon committed
22 23 24
import {
	Loading
} from 'vant';
simon committed
25

joe committed
26
export default {
simon committed
27 28
	data() {
		return {
joe committed
29
			loading: false,
simon committed
30 31 32 33 34
			showPolicy: true,
			key: 'value',
			hadLoadPolicy: false,
			ignorePolicyCodes: [],
			// 显示
joe committed
35
			policyDetail: null,
simon committed
36
			showSuccessTip: false,
simon committed
37
			showDownloadError: false,
simon committed
38

simon committed
39
			checked: false, // 是否同意协议
simon committed
40 41 42
			agree1: false, // 同意文档1
			agree2: false, // 同意文档2
			errtipsVisible: false,
simon committed
43 44
		}
	},
joe committed
45 46 47
	components: {
		Modal2Comp
	},
simon committed
48 49 50 51
	computed: {
		...mapState({
			userInfo: state => state.userInfo,
			policyList: state => state.policyList
simon committed
52 53 54 55
		}),
		locale() {
			return this.$i18n.locale || 'tc';
		},
simon committed
56 57 58
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
simon committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	},
	methods: {
		initData() {
			if (this.showPolicy) {
				let hidePolicy = sessionStorage.getItem("hidePolicy");
				if (hidePolicy) {
					this.showPolicy = false;
				}
			}
			if (!this.showPolicy) {
				return;
			}
			if (this.isLogin() && !this.hadLoadPolicy) {
				this.ignorePolicyCodes = [];
				let temp = sessionStorage.getItem("ignorePolicyCodes");
				if (temp) {
					try {
						JSON.parse(temp).forEach(element => {
							this.ignorePolicyCodes.push(element);
						});
					} catch (e) {
joe committed
80

simon committed
81 82 83 84 85 86 87
					}
				}
				httpPost({
					url: api.policyList,
					sid: true
				}).then(res => {
					this.hadLoadPolicy = true;
88
					if (!res || res.length == 0) { } else {
simon committed
89 90 91
						this.$store.commit("CACHE_POLICY_LIST", res);
						this.checkIfShowPolicy();
					}
92
				}).catch(e => { });
simon committed
93 94 95 96 97 98 99 100 101 102
			} else {
				this.checkIfShowPolicy();
			}
		},
		// 检查是否需要显示policyModal
		checkIfShowPolicy() {
			this.policyDetail = null;
			if (this.policyList) {
				for (let index = 0; index < this.policyList.length; index++) {
					let policy = this.policyList[index];
joe committed
103 104 105 106 107 108 109 110
					let flag = null;
					try {
						flag = process.env.VUE_APP_HIDE_VHIS_MODAL_FLAG;
					} catch (e) {

					}
					flag = flag ? flag : "Y";
					if (policy.checkFlag == flag) {
joe committed
111
						// if (policy.checkFlag == "N") { // 体验弹窗
simon committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
						continue;
					}
					if (this.ignorePolicyCodes.indexOf(policy.policyCode) >= 0) {
						continue;
					}
					this.initPolicyForShow(policy);
					break;
				}
			}
		},
		initPolicyForShow(policy) {
			let params = {
				policyId: policy.policyId,
				policyCode: policy.policyCode
			};
			httpPost({
				url: api.policyDetail,
				sid: true,
				data: params
			}).then(res => {
				this.policyDetail = res;
133 134 135 136 137 138 139 140
				// 两份电子函的ID
				this.policyDetail.agree1 = false;
				this.policyDetail.agree2 = false;
				this.policyDetail.letterNo1Id = "";
				this.policyDetail.letterNo2Id = "";

				for (let index = 0; index < this.policyDetail.policyAcknowledges.length; index++) {
					let policyAcknowledge = this.policyDetail.policyAcknowledges[index];
joe committed
141
					switch (policyAcknowledge.letterType) {
142 143 144 145 146 147 148 149 150
						case "1":
							this.policyDetail.letterNo1Id = policyAcknowledge.recordId;
							break;
						case "2":
							this.policyDetail.letterNo2Id = policyAcknowledge.recordId;
							break;
					}
				}

simon committed
151 152 153
				this.policyDetail.ymd1 = "";
				this.policyDetail.ymd2 = "";
				this.policyDetail.ymd3 = "";
joe committed
154

simon committed
155 156 157 158
				let now = new Date();
				let y = now.getFullYear();
				let m = now.getMonth() + 1;
				let d = now.getDate();
joe committed
159

simon committed
160
				if (this.$i18n.locale == 'en') {
simon committed
161 162
					this.policyDetail.nowYmd2 = m > 10 ? m : "0" + m;
					this.policyDetail.nowYmd1 = d > 10 ? d : "0" + d;
simon committed
163 164 165 166 167 168
					this.policyDetail.nowYmd3 = y;
				} else {
					this.policyDetail.nowYmd1 = y;
					this.policyDetail.nowYmd2 = m > 10 ? m : "0" + m;
					this.policyDetail.nowYmd3 = d > 10 ? d : "0" + d;
				}
joe committed
169

simon committed
170 171 172
				if (this.policyDetail.activeDate) {
					let ymds = this.policyDetail.activeDate.split(" ")[0].split("-");
					if (this.$i18n.locale == 'en') {
simon committed
173 174
						this.policyDetail.ymd1 = ymds[2];
						this.policyDetail.ymd2 = ymds[1];
simon committed
175 176 177 178 179 180 181 182
						this.policyDetail.ymd3 = ymds[0];
					} else {
						this.policyDetail.ymd1 = ymds[0];
						this.policyDetail.ymd2 = ymds[1];
						this.policyDetail.ymd3 = ymds[2];
					}
				}
			}).catch(err => {
joe committed
183

simon committed
184 185 186 187 188
			});
		},
		// 确认保单按钮
		handleConfirmPolicy() {
			if (this.policyDetail) {
joe committed
189 190 191 192
				if (this.loading) {
					return;
				}
				this.loading = true;
simon committed
193 194 195
				let policyCode = this.policyDetail.policyCode;
				this.ignorePolicyCodes.push(policyCode);
				sessionStorage.setItem("ignorePolicyCodes", JSON.stringify(this.ignorePolicyCodes));
joe committed
196
				// this.checkIfShowPolicy();
joe committed
197

simon committed
198
				let params = {
199 200
					policyCode: policyCode,
					recordIds: [this.policyDetail.letterNo1Id, this.policyDetail.letterNo2Id]
simon committed
201 202 203 204 205 206
				};
				// 回销
				httpPost({
					url: api.policyReceipt,
					sid: true,
					data: params
joe committed
207 208 209 210 211 212 213 214
				}).then(res => {
					this.loading = false;
					this.showSuccessTip = true;
					this.checkIfShowPolicy();
				}).catch(e => {
					this.loading = false;
					this.showDownloadError = true;
					this.checkIfShowPolicy();
simon committed
215
				});
joe committed
216

simon committed
217 218 219 220 221 222 223 224 225 226
			}
		},
		// 忽略保单按钮
		handleIgnorePolicy() {
			if (this.policyDetail) {
				this.ignorePolicyCodes.push(this.policyDetail.policyCode);
				sessionStorage.setItem("ignorePolicyCodes", JSON.stringify(this.ignorePolicyCodes));
				this.checkIfShowPolicy();
			}
		},
simon committed
227 228
		// 下载冷静期通知书
		downloadPolicy2() {
229
			this.policyDetail.agree2 = true;
simon committed
230 231 232 233 234
			if (this.policyDetail) {
				httpPost({
					url: api.getDownloadPath,
					sid: true,
					data: {
235 236
						policyCode: this.policyDetail.policyCode,
						recordId: this.policyDetail.letterNo2Id
simon committed
237 238 239 240 241 242 243 244 245 246 247
					}
				}).then(res => {
					if (res) {
						let url = requestDomain() + api.downloadPolicy + "/" + res;
						window.open(url);
					} else {
						this.showDownloadError = true;
					}
				});
			}
		},
248
		// 下载保险合约
simon committed
249
		downloadPolicy() {
250
			this.policyDetail.agree1 = true;
simon committed
251 252 253 254 255
			if (this.policyDetail) {
				httpPost({
					url: api.getDownloadPath,
					sid: true,
					data: {
256 257
						policyCode: this.policyDetail.policyCode,
						recordId: this.policyDetail.letterNo1Id
simon committed
258 259 260 261 262
					}
				}).then(res => {
					if (res) {
						let url = requestDomain() + api.downloadPolicy + "/" + res;
						window.open(url);
joe committed
263 264
					} else {
						this.showDownloadError = true;
simon committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
					}
				});
			}
		},
		onOverLayHandler() {
			this.showPolicy = false;
			sessionStorage.setItem("hidePolicy", "true");
		},
		toContact() {
			this.showPolicy = false;
			sessionStorage.setItem("hidePolicy", "true");
			this.$router.push({
				path: "/custom/service?q=m1"
			});
		},
simon committed
280
		toTarget() {
joe committed
281
			this.showPolicy = false;
joe committed
282
			this.showSuccessTip = false;
joe committed
283 284
			sessionStorage.setItem("hidePolicy", "true");
			this.$router.push({
simon committed
285
				path: "/custom/service?q=m3"
joe committed
286 287
			})
		},
simon committed
288 289 290
		formatPolicyName(c, n) {
			return getPolicyName(this.$i18n.locale, c, n);
		},
simon committed
291 292 293 294 295 296 297 298 299
		loginAction() {
			this.showPolicy = true;
			this.initData();
		},
		logoutAction() {
			this.showPolicy = false;
			this.hadLoadPolicy = false;
			this.policyDetail = null;
			this.ignorePolicyCodes = [];
joe committed
300 301 302
			this.showDownloadError = false;
			this.showSuccessTip = false;
			this.loading = false;
simon committed
303 304 305 306 307
			sessionStorage.removeItem("ignorePolicyCodes");
			sessionStorage.removeItem("hidePolicy");
		},
		isLogin() {
			return this.userInfo && this.userInfo.sid;
simon committed
308
		},
simon committed
309
		onCheckHandler() {
310
			if (this.policyDetail.agree1 && this.policyDetail.agree2) {
simon committed
311 312 313 314 315 316
				this.checked = !this.checked;
				this.errtipsVisible = false;
			} else {
				this.errtipsVisible = true;
			}

simon committed
317 318 319
		}
	},
	mounted() {
joe committed
320

simon committed
321 322 323 324 325 326 327 328 329 330 331 332 333
	},
	created() {
		this.initData();
	},
	watch: {
		userInfo(val) {
			if (val && val.name) {
				this.loginAction();
			} else {
				this.logoutAction();
			}
		}
	},
joe committed
334
}