Blame view

src/pages/custom-service/components/policy-head-list.js 6.07 KB
simon committed
1 2 3 4
/**
 * 组件描述:保单查询列表
 */

joe committed
5 6
import api from '@/api/api';
import {
simon committed
7 8
	httpPost,
	requestDomain
joe committed
9 10 11
} from '@/api/fetch-api.js';

import {
simon committed
12
	mapState
joe committed
13
} from 'vuex';
simon committed
14 15 16
import {
	formatMoney,
	getInsuredPeriod,
joe committed
17
	getInsuredState,
simon committed
18 19
	getPolicyName
} from "@/utils/biz.js";
joe committed
20
import Modal2Comp from '@/components/modal2-comp/modal2-comp.vue';
joe committed
21 22

export default {
simon committed
23
	props: {
simon committed
24 25 26 27 28 29 30 31 32
		type:{
			/**
			 * 1.保单查询
			 * 2.更改联系方式
			 *   不显示保单状态 和 生效日期 这两项
			 */
			type:Number,
			default:1, 
		},
simon committed
33 34 35 36 37 38 39
		multiSelectable: {
			type: Boolean,
			default: false
		},
		model: {
			type: String,
			default: "download"
simon committed
40
		},
simon committed
41
	},
simon committed
42
	name: "PolicyHeadList",
simon committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
	data() {
		return {
			myPolicyList: [],
			maxShow: 2,
			selectPolicyCode: "",
			selectPolicyCodes: {},
			hide: false,
			showDownloadError: false
		}
	},
	computed: {
		...mapState({
			policyList: state => state.policyList
		}),
		lan() {
			return this.$i18n.locale;
		},
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
	},
	methods: {
		onShowTipsOverHandler(event, item, index) {
			let child = event.currentTarget.childNodes[0];
			child.style.display = "block";
		},
		onShowTipsOutHandler(event, item, index) {
			let child = event.currentTarget.childNodes[0];
			child.style.display = "none";
		},
		toContactUs() {
			this.$router.push({
				path: "/custom/service",
				query: {
					q: "m1"
				}
			});
		},
		queryList() {
			if (this.policyList && this.policyList.length > 0) {
				this.myPolicyList = this.policyList;
				this.myPolicyList.forEach(element => {
					element.activity = false;
				})
				this.initSelected();
			} else {
				this.checkCustomer().then(() => {
					httpPost({
						url: api.policyList,
						sid: true
					}).then(res => {
						if (!res || res.length == 0) {
							this.myPolicyList = null;
						} else {
							res.forEach(element => {
								element.activity = false;
								// let len = element.policyCode.length;
								// element.policyCodeStr = element.policyCode && len > 5 ?
								//     element.policyCode.substring(0, 2) + "**********"
								//     + element.policyCode.substring(len - 4, len) : element.policyCode;
							});
							this.$store.commit("CACHE_POLICY_LIST", res);
							this.myPolicyList = res;
						}
						this.initSelected();
					}).catch(e => {
						this.myPolicyList = null;
						switch (e.code) {
							case "2002":
								// 不是客户,没有购买保单
								break;
						}
					});
				});
joe committed
117

simon committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
			}
		},
		initSelected() {
			let selectPolicy = null;
			try {
				let data = sessionStorage.getItem("_hklife_policy");
				if (data) {
					sessionStorage.removeItem("_hklife_policy");
					selectPolicy = JSON.parse(decodeURIComponent(data));
					if (selectPolicy) {
						if (this.multiSelectable) {
							this.selectPolicyCodes[selectPolicy.code] = selectPolicy;
						} else {
							this.selectPolicyCode = selectPolicy.code;
						}
						this.$emit("onSelect", [selectPolicy]);
joe committed
134

simon committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
						// 判断最大显示
						let index = -1;
						for (let i = 0; i < this.myPolicyList.length; i++) {
							if (selectPolicy.code == this.myPolicyList[i].policyCode) {
								this.myPolicyList[i].activity = true;
								index = i;
							}
						}
						this.$set(this, "myPolicyList", this.myPolicyList);
						if (index > 2) {
							this.maxShow = this.myPolicyList.length;
						}
					}
				}
			} catch (e) {
joe committed
150

simon committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
			}
			if (!selectPolicy) {
				let firstPolicy = this.myPolicyList[0];
				this.myPolicyList[0].activity = true;
				selectPolicy = {
					id: firstPolicy.policyId,
					code: firstPolicy.policyCode
				};
				if (this.multiSelectable) {
					this.selectPolicyCodes[selectPolicy.code] = selectPolicy;
				} else {
					this.selectPolicyCode = selectPolicy.code;
				}
				this.$emit("onSelect", [selectPolicy]);
			}
		},
		handlePolicySelect(item, index) {
			let code = item.policyCode;
			if (this.multiSelectable) {
				let c = this.selectPolicyCodes[code];
				if (!c || typeof c == "undefined") {
					item.activity = true;
					this.selectPolicyCodes[code] = {
						code: code,
						id: item.policyId
					};
				} else {
					item.activity = false;
					delete this.selectPolicyCodes[code];
				}
181
				this.$set(this.myPolicyList, index, item);
simon committed
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
				let data = [];
				for (let key in this.selectPolicyCodes) {
					data.push(this.selectPolicyCodes[key]);
				}
				this.$emit("onSelect", data);
			} else {
				if (code != this.selectPolicyCode) {
					this.selectPolicyCode = code;
					this.$emit("onSelect", [{
						code: code,
						id: item.policyId
					}]);
				}
			}
		},
		isPolicySelect(item, index) {
			let code = item.policyCode;
			if (this.multiSelectable) {
				let c = this.selectPolicyCodes[code];
				if (!c || typeof c == "undefined") {
					return false;
				} else {
					return true;
				}
			}
			return false;
		},
		checkCustomer() {
			return new Promise(resolve => {
				resolve();
				// httpPost({ url: api.profile, sid: true }).then(res => {
				//     if (res.isCustomer == 1) {
				//         resolve();
				//     } else {
				//         this.gotoCustomerAuthPage();
				//     }
				// }).catch(res => {
joe committed
219

simon committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
				// });
			});
		},
		gotoCustomerAuthPage() {
			let c = this.$route.fullPath;
			this.$router.push({
				name: "customerAuth",
				query: {
					c: c
				}
			});
		},
		formatMoney(s, t) {
			if (typeof t == "undefined") {
				t = 1;
			}
			return formatMoney(s, t);
		},
		// 保障年限,保n年
		formatInsuredPeriod(t, v) {
			return getInsuredPeriod(this.$i18n.locale, t, v);
		},
joe committed
242 243 244
		formatInsuredState(c) {
			return getInsuredState(this.$i18n.locale, c);
		},
simon committed
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
		formatPolicyName(c, n) {
			return getPolicyName(this.$i18n.locale, c, n);
		},
		downloadPolicy(policy) {
			if (policy) {
				httpPost({
					url: api.getDownloadPath,
					sid: true,
					data: {
						policyCode: policy.policyCode
					}
				}).then(res => {
					if (res) {
						let url = requestDomain() + api.downloadPolicy + "/" + res;
						window.open(url);
					} else {
						this.showDownloadError = true;
					}
				});
			}
		}
	},
	components: {
		Modal2Comp
	},
	mounted() {
		this.queryList();
	},
joe committed
273
}