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

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

import ClarmsVerifyForm from './clarms-plugins-verifyform.vue';
import ClarmsMaterial from './clarms-plugins-material.vue';

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

export default {
    data() {
        return {
            step: 0, // 1是表单;2是报案页面
            agress: false,
            reservationTypes: [],
            cid: false,
            // 可以理赔的客户信息
            customerList: []
        }
    },
    components: {
        ClarmsVerifyForm,
        ClarmsMaterial
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo
        }),
        i18n() {
            return this.$i18n.messages && this.$i18n.locale ? this.$i18n.messages[this.$i18n.locale] : {};
        },
    },
    methods: {
        initData() {
            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) {
                    this.cid = res;
                    this.checkCid();
                } else {
                    this.step = 1;
                }
            }).catch(e => {
                this.step = 1;
            });
        },
        checkCid() {
            let param = {
                cid: this.cid
            }
            httpPost({ url: api.clarmsCustomerList, data: param }).then(res => {
                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;
            });
        },
        logoutAction() {
            console.log("logoutAction");
            this.sid = false;
            this.hadQueryCustomerList = false;
            this.customerList = [];
            this.step = 1;
        },
        loginAction() {
            console.log("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() { }
}