vhis-modal.js 5.77 KB

import { mapState } from "vuex";
import api from '@/api/api'
import {
    httpGet,
    httpPost
} from '@/api/fetch-api.js'

export default {
    data() {
        return {
            showPolicy: true,
            key: 'value',
            hadLoadPolicy: false,
            ignorePolicyCodes: [],
            // 显示
            policyDetail: null
        }
    },
    components: {},
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            policyList: state => state.policyList
        })
    },
    methods: {
        initData() {
            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) {

                    }
                }
                httpPost({ url: api.policyList, sid: true }).then(res => {
                    this.hadLoadPolicy = true;
                    if (!res || res.length == 0) {
                    } else {
                        this.$store.commit("CACHE_POLICY_LIST", res);
                        this.checkIfShowPolicy();
                    }
                }).catch(e => {
                });
            } 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];
                    if (policy.checkFlag == "Y") {
                        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;
                this.policyDetail.ymd1 = "";
                this.policyDetail.ymd2 = "";
                this.policyDetail.ymd3 = "";

                let now = new Date();
                let y = now.getFullYear();
                let m = now.getMonth() + 1;
                let d = now.getDate();

                if (this.$i18n.locale == 'en') {
                    this.policyDetail.nowYmd1 = m > 10 ? m : "0" + m;
                    this.policyDetail.nowYmd2 = d > 10 ? d : "0" + d;
                    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;
                }

                if (this.policyDetail.activeDate) {
                    let ymds = this.policyDetail.activeDate.split(" ")[0].split("-");
                    if (this.$i18n.locale == 'en') {
                        this.policyDetail.ymd1 = ymds[1];
                        this.policyDetail.ymd2 = ymds[2];
                        this.policyDetail.ymd3 = ymds[0];
                    } else {
                        this.policyDetail.ymd1 = ymds[0];
                        this.policyDetail.ymd2 = ymds[1];
                        this.policyDetail.ymd3 = ymds[2];
                    }
                }
            }).catch(err => {

            });
        },
        // 确认保单按钮
        handleConfirmPolicy() {
            if (this.policyDetail) {
                let policyCode = this.policyDetail.policyCode;
                this.ignorePolicyCodes.push(policyCode);
                sessionStorage.setItem("ignorePolicyCodes", JSON.stringify(this.ignorePolicyCodes));
                this.checkIfShowPolicy();

                let params = {
                    policyCode: policyCode
                };
                // 回销
                httpPost({ url: api.policyReceipt, sid: true, data: params }).then(res => {

                }).catch(e => {

                });

            }
        },
        // 忽略保单按钮
        handleIgnorePolicy() {
            console.log(this.policyDetail);
            if (this.policyDetail) {
                this.ignorePolicyCodes.push(this.policyDetail.policyCode);
                sessionStorage.setItem("ignorePolicyCodes", JSON.stringify(this.ignorePolicyCodes));
                this.checkIfShowPolicy();
            }
        },
        onOverLayHandler() {
            this.showPolicy = false;
        },
        toContact() {
            this.showPolicy = false;
            this.$router.push({
                path: "/custom/service?q=m1"
            });
        },
        loginAction() {
            this.showPolicy = true;
            this.initData();
        },
        logoutAction() {
            this.showPolicy = false;
            this.hadLoadPolicy = false;
            this.policyDetail = null;
            this.ignorePolicyCodes = [];
            sessionStorage.removeItem("ignorePolicyCodes");
        },
        isLogin() {
            return this.userInfo && this.userInfo.sid;
        }
    },
    mounted() {

    },
    created() {
        this.initData();
    },
    watch: {
        userInfo(val) {
            if (val && val.name) {
                this.loginAction();
            } else {
                this.logoutAction();
            }
        }
    },
}