clarms.js 3.43 KB
import {
	mapGetters,
	mapActions,
	mapState
} from "vuex";

import api from '@/api/api'
import {
	httpGet,
	httpPost
} from '@/api/fetch-api.js'

import ClarmsModalOne from '@/components/clarms/clarms-plugins-modal1.vue';
import ClarmsModalTwo from '@/components/clarms/clarms-plugins-modal2.vue';
import ClarmsVerifyForm from '@/components/clarms/clarms-plugins-verifyform.vue';
import ClarmsMaterial from '@/components/clarms/clarms-plugins-material.vue';

// 用户没有登录
// 		校验成功
// 		校验失败
// 用户已经登录
// 	    没有保单
// 		    校验成功
// 		    校验失败
// 	    有保单

export default {
	data() {
		return {
			step: 0, // 1是表单;2是报案页面;3=信息不完整
			showModal1: false,
			showModal2: false,
			agress: false,
			reservationTypes: [],
			cid: "",
			// 可以理赔的客户信息
			customerList: [],
			modelType: "1"
		}
	},
	components: {
		ClarmsVerifyForm,
		ClarmsMaterial,
		ClarmsModalOne,
		ClarmsModalTwo
	},
	computed: {
		...mapState({
			userInfo: state => state.userInfo
		}),
		i18n() {
			return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
		},
	},
	methods: {
		initData() {
			// this.step = 2;
			// return;
			if (this.userInfo && this.userInfo.name) {
				this.loadCidIfLogin();
				sessionStorage.removeItem("clarmsRequestCid")
			} else {
				let cid = sessionStorage.getItem("clarmsRequestCid");
				if (cid) {
					this.cid = cid;
					this.checkCid();
				} else {
					this.step = 1;
				}
			}
		},
		loadCidIfLogin() {
			let param = {
				sid: this.userInfo.sid
			};
			httpPost({
				url: api.getCidByLogin,
				sid: true,
				data: param
			}).then(res => {
				if (res) {
					if (res == -1) {
						this.customerList = [];
						this.step = 2;
					} else {
						this.cid = res;
						this.checkCid();
					}
				} else {
					this.step = 3;
				}
			}).catch(e => {
				this.step = 1;
			});
		},
		checkCid() {
			let param = {
				cid: this.cid
			}
			httpPost({
				url: api.clarmsCustomerList,
				data: param
			}).then(res => {
				sessionStorage.removeItem("clarmsRequestCid");
				if (res) {
					this.customerList = res.insuredInfoList;
					this.step = 2;
				}
				// if (res && res.insuredInfoList && res.insuredInfoList.length > 0) {
				//     this.customerList = res.insuredInfoList;
				//     this.step = 2;
				// } else {
				//     sessionStorage.removeItem("clarmsRequestCid");
				//     this.step = 1;
				// }
			}).catch(e => {
				sessionStorage.removeItem("clarmsRequestCid");
				this.step = 1;
			});
		},
		handleInsuredInfo(data) {
			this.cid = data.cid;
			this.customerList = data.list;
			this.step = 2;
		},
		handleShowModal(model) {
			// console.log(model);
			if (model.action == 1) {
				this.modelType = model.type;
				this.showModal1 = true;
			} else if (model.action == 2) {
				this.showModal2 = true;
			}
		},
		gotoInformationPage() {
			let c = this.$route.fullPath;
			this.$router.push({
				path: "/infomation/improve",
				query: {
					c: c,
					a: 1
				}
			});
		},
		logoutAction() {
			this.sid = false;
			this.hadQueryCustomerList = false;
			this.customerList = [];
			this.step = 1;
		},
		loginAction() {
			this.sid = false;
			this.hadQueryCustomerList = false;
			this.customerList = [];
		}
	},
	watch: {
		userInfo(val) {
			if (val && val.name) {
				this.loginAction();
			} else {
				this.logoutAction();
			}
		}
	},
	mounted() {
		this.initData();

	},
	created() { }
}