const util = {
    setTitle: (title) => {
        document.title = title;

        (function (t) {
            document.title = t;
            var i = document.createElement('iframe');
            i.src = '/favicon.ico';
            i.style.display = 'none';
            i.onload = function () {
                setTimeout(function () {
                    i.remove();
                }, 9)
            }
            document.body.appendChild(i);
        })(title)
    },
     reformParam(methodName,para) {
    var parameter = {}
    parameter['merchantid'] = '1'
    parameter['version'] = '1'
    parameter['sign_type'] = 'RSA'
    parameter['sign'] = '123'
    parameter['charset'] = 'UTF-8'
    parameter['method'] = methodName
    var context = ''
    for(var key in para){
        context += '&'+key+'='+para[key]
    }
    parameter['context'] = context
    return parameter
},
    /**
     *
     * @param opt
     * view:页面名称
     * action:操作，如点击：click
     * label:事件描述
     * value：资源id
     */
    trackEvent: (opt) => {
      //  console.log('trackEvent')
        if (!opt) {
            return;
        }

        opt.view = opt.view || '';
        opt.action = opt.action || 'click';
        opt.label = opt.label || '';
        opt.value = opt.value || '';

        if (_czc && _czc.push) {
            _czc.push(['_trackEvent', opt.view, opt.action, opt.label, opt.value])
        }
    },
    trackPageview: (pathTo, pathFrom) => {
        if (_czc && _czc.push) {
            _czc.push(["_trackPageview", pathTo, pathFrom]);
        }
    },
    accountUrl:'skyforest.tencent.TencentController.signature',
    tokenUrl:'skyforest.mine.MineController.login.v093',
    adviserListUrl:'skyforest.dynatown.dynatownController.getDynatownList',
    chatUrl:'skyforest.dynatown.dynatownController.connect',
    formatDatetime(val,format){
        const year = val.getFullYear();
        const month = val.getMonth()+1;
        const day = val.getDate();
        const hour = val.getHours();
        const minute = val.getMinutes();
        const second = val.getSeconds();
        return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute)+':'+(second>9?second:'0'+second);

    },
    formatDayTime(val){
        const year = val.getFullYear();
        const month = val.getMonth()+1;
        const day = val.getDate();
        const hour = val.getHours();
        const minute = val.getMinutes();
        const second = val.getSeconds();
        return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute);
    },
    formatTodayTime(val){
        const year = val.getFullYear();
        const month = val.getMonth()+1;
        const day = val.getDate();
        const hour = val.getHours();
        const minute = val.getMinutes();

        if(month==new Date().getMonth()+1&&day+1==new Date().getDate()){
            return '昨天'+hour+':'+(minute>9?minute:'0'+minute);
        }
        else if(month==new Date().getMonth()+1&&day==new Date().getDate()){

            return hour+':'+(minute>9?minute:'0'+minute);
        }else{
            return year+'-'+(month>9?month:'0'+month)+'-'+day+' '+hour+':'+(minute>9?minute:'0'+minute);
        }
    }
};

export default util;
