export default {
	screenSize() {
		if (!document.body) return;
		let creenWidth = document.body.clientWidth || 750;
		if (creenWidth < 750) return;
		if (creenWidth > 1300) creenWidth = 1300;
		let rFontSize = creenWidth / 30;
		rFontSize < 40 ? rFontSize = 40 : "";
		document.documentElement.style.fontSize = rFontSize + 'px';
	},
	getTime(date) {
		const T = date ? new Date(date) : new Date();
		let year = T.getFullYear() + '';
		let month = T.getMonth() + 1;
		let day = T.getDate();
		let hour = T.getHours();
		let min = T.getMinutes();
		let sec = T.getSeconds();

		month = month > 9 ? month + '' : '0' + month;
		day = day > 9 ? day + '' : '0' + day;
		hour = hour > 9 ? hour + '' : '0' + hour;
		min = min > 9 ? min + '' : '0' + min;
		sec = sec > 9 ? sec + '' : '0' + sec;

		return {
			year,
			month,
			day,
			hour,
			min,
			sec
		}
	},
    formatNumber(num, d){
        if(isNaN(num)) return '0';
        let dw = "";
        if (num >= 100000000) {
            dw = "亿";
            num = (num / 100000000).toFixed(d || 2) - 0;
        } else if (num >= 10000) {
            dw = "万";
            num = (num / 10000).toFixed(d || 2) - 0;
        }
        num = num.toString().split(".")
        if(num.length > 1) {
            return [(num[0] || "").replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') , (num[1] || "")].join(".") + dw;
        }else{
            return (num[0] || "").replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + dw;
        }
    },
    decodeURL(url,obj){
        let Keys = Object.keys(obj), urlData = "?";
        for (let i = 0; i < Keys.length; i++) {
            const v = Keys[i];
            if(i!==0) urlData += '&' + v + '=' + obj[v];
            else urlData += v + '=' + obj[v];
        }
        return url + urlData
    }
}