//埋点
import axios from "axios";

let magnetLogAdd = {};

magnetLogAdd.setLog = (magnetName,callback) => {
    let isMobile = '';
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
        isMobile = '0';
    }else {
        isMobile = '1';
    }
    let userInfo = JSON.parse(window.localStorage.getItem("userInfoV1"));
    let agentFrom = window.localStorage.getItem('agentFrom');
    if (agentFrom != undefined){
        if (agentFrom == 'hbs'){
            magnetName = '好邦手' + magnetName;
        }
        if (agentFrom == 'ssb'){
            magnetName = '随身邦' + magnetName;
        }
        if (agentFrom == 'stoneLikePaint'){
            magnetName = '服务商随身邦' + magnetName;
        }
        if (agentFrom == 'goldShop'){
            magnetName = '金牌店随身邦' + magnetName;
        }
    }
    let obj = {
        userId: userInfo.userId,
        userName: userInfo.userName,
        orgCode: userInfo.sysUserExt.orgCode,
        orgName: userInfo.sysUserExt.orgName,
        level: userInfo.sysUserExt.salesLevel,
        whatEnd: isMobile,
        magnetName: magnetName
    };
    if(agentFrom == 'stoneLikePaint' || agentFrom == 'goldShop'){
        let loginTypeList = userInfo.loginTypeList?userInfo.loginTypeList:[];
        let shopList = [];
        loginTypeList.forEach(function (item) {
            if (item.shopType == agentFrom) {
                shopList = item.shopList;
                return
            }
        });
        obj.level = shopList.length>0?shopList[0].sales_level:''
    };
    axios.post(`${process.env.VUE_APP_BASE_API}/wxportal/magnetLogAdd`,obj,{timeout:5000}).finally(callback);
}

export default magnetLogAdd;