/**
 * 该文件定义 全局公共方法
 */
'use strict';
/**
 *全局加载遮罩
 */
(U instanceof Object) && (function(){
	Object.assign(U, {
		loadText: document.createElement('p'),
		iconImg: document.createElement('img'),
		loadElem: document.createElement('div'),
		//加载框
		loading: function(status) {
			var _this = this;
			this.css(this.loadText, {
				"color": "#fff",
				"font-size": "14px",
				'margin-top': '10px',
				"text-align": "center",
				"line-height": "2em"
			});
			let closeIcon = document.createElement('i');
			closeIcon.onclick = function() {
				_this.closeLoad();
			};
			this.css(closeIcon, {
				"height": "25px",
				"width": "25px",
				"position": "absolute",
				"top": "3%",
				"right": "5%",
				"border-radius": "50%",
				"box-shadow": "rgba(255, 255, 255, 0.8) 0px 0px 5px -2px,inset 0 0 0 1px rgba(255,255,255,.6)",
				"background": "no-repeat center center",
				"background-image": "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACcklEQVRYR82WPYsTURSG35Mi0SCSwC5oWNCQiMmdRgsbC1FQ7Gz8B2plIWgh+A9s/OgEQfwHogiLgiyursqCaJP5YjqLIFZZlEUymXvkQkZmx0zunclATJlhzvPc955z7xCW/KMl8/F/CTiOcxjAZ2Z+JoS4QURcVkK+7/eiKHpBRPf6/f7juO6eBIIgWA3D8BuAfcz8VAhxtQyJKfwdgFUAT4QQ12YKqD9d1z3LzK8A1MqQSMKZeater19ot9u/MwXKlEjDm83mxVartZvc1swmTCdhWdaVPP1gAlf15k7BVGIdwH4Aj4QQ100kBoNBt1KpfFR7rmKftfK5W5CEuK57mpnfmEooOBG9J6JDOrg2gVjEVCIv3Fhg2phzkygCzyUwT6IoPLdALCGlfE1EB1RjSinv59nzdBMXugt83z81mUw2ACiJXSKqmzTcrAkqJKAKeZ53KYqi50SkanxvNBqd9CFjMrKFBFzXPSqlVKO2BkAyc4WIHgohbppAjU7CrEIp+DaA2wBeAjgIILdErgTScGY+b1nWL9u2TxDRZhEJY4EseJxUUQkjAR18EQmtgCk8KQFgg4iaJj2huw2T3b4d77mu023btgCoKdFKZAoEQbA2Ho8/TUfNGJ5I4q8EM9+1LOuO8UGk4GEYbgE4AuArM59R3a5befp5MoksiX8SSMNrtdq5TqezkxeeTIKI3gJYmSWxR2A4HNZHo9EAQFutfFF4LOF53nEppUp0BcAtIcSDmV9Etm2fJKIvZcJTEh8AbAohLmd+kqmbjpm9Xq/3s2jsWe85jnOsWq3udLvdH5kCZUN19bQHka7Aos+XLvAHdne4MOpAobMAAAAASUVORK5CYII=')",
				"background-size": "70% 70%"
			});
			this.loadElem.appendChild(this.iconImg);
			this.loadElem.appendChild(this.loadText);
			this.loadElem.appendChild(closeIcon);
			this.css(this.loadElem, {
				'position': 'fixed',
				'z-index': 9999999,
				'background': 'rgba(0,0,0,.7)',
				'top': 0,
				'bottom': 0,
				'left': 0,
				'right': 0,
				"display": 'flex',
				"justify-content": 'center',
				"align-items": 'center',
				"flex-direction": "column"
			});
			let html = document.querySelector('html');
			let styLing = document.createElement('style');
			styLing.innerHTML = `@keyframes loading {
					0% {
						-webkit-transform: rotate(0deg);
						transform: rotate(0deg);
					}
			
					100% {
						-webkit-transform: rotate(1turn);
						transform: rotate(1turn);
					}
				}`;
			//载入动画scc
			html.appendChild(styLing);
			html.appendChild(this.loadElem);
			return this;
		},
		//启动加载框
		startLoad: function(str, src) {
			this.iconImg.src = src ||
				'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAApVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+4/eNVAAAANnRSTlMAwLr9+fQCDQepOEAEEYBqVtojn24U4NWuhe/rvnrNL7PJpJtyXUor5o+KZ3VPRh0ZlCcqYzNc7oRpAAAGEklEQVR42uza6XaaUBQF4K2MDqDiEGfrFIckZmi63//RujqYeHqBAgKWLr6/rqVu9GwuF1AqlUqlUqlUKjC73nqo2yi8B4MkjXcUm1njb0MTRTbihwMKrK/zg7ZDcfV4YYbiWvF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S1RbDsXpB9sxdo7FA6rr8MP+GAjNXn5scBbdbD6gvexZKpVKpVCqV/le7Xnda8TGcNZCPN/EN/Ey7vR3CNUcaAw0dZM90dUagHZsIYVYZZpB9EvMLI6qaCDZiuCqytmFkIwSydP5FA9kyJ4xMtyI/JaA6IlsnxnC64netIVs9xtBCkMebB/ne3t3oJA4FUQCetT8XCkGQImCDsojdxFUou+t5/0fbGLP0XgubmtYrh8z3Bg0/d9rOzFm3cyFDVPmdG8rxAb0T/rGbELVl8cee7ftd27BAbU8NDsSJHHR6B6L0H/9Xohg5xn+JMo/Po2j8LUoppZRSSimllHpl0u8hMKJv3HnI8GZJ3buT3J7FatViBVsunDqLCI6lUHq+xjuREPrxDVV8O+AnuwAA/ydyZALmQrjEMxzGdiYucNhUuJgIB11vhcufo0PHZO6xx92z3kWJumd9V12VwFn3PleXV3CK368TofUSOgOmxPKwnKHjtl+CpJRSSn2SotdLOItJh7kPAQQXhLcpjskUb8KhMOvc4p+QujNvjtJMeG1DlIJCaC1h2wirzYksGG+mutCa9l74qfWFSP18MRg89MWvSQRHKk2lGV6NXsSrMRyjuJX/cv+H6x1ceYsDMOEv8WfV9kLrKUpj8SaOWs4S2MKSiTcFHLvGIdob2Iz4UlQSkxqGaPe+6rXxDSzr5iHaJkBpJP6M3SyB5iHaS5Tm4s9VhL1NGyHad4H9TfUoD2pN76awzGu9RM4S8cONo70Z1j9vZrXiaK/Et2S96l6a9kK0zWV3tU7kNFFENuuFMDqboPnuuUT/D9xShpedCBOw9RU5Hu1ai5lT/XLbJ8LQ6yTpz4SvxVYppZRSSpX+AiWAskTProtGAAAAAElFTkSuQmCC';
			this.loadText.innerHTML = str?(typeof str == 'boolean'?'':str):"数据加载中…";
			this.css(this.iconImg, {
				"width": "50px",
				"height": "50px",
				'animation': 'loading 500ms infinite steps(12)'
			});
			this.css(this.loadElem, {
				'z-index': 9999999,
				'display': 'flex'
			});
			this.loadNum = this.loadNum?(this.loadNum < 0?0:this.loadNum):0;
			this.loadNum++;
			return this;
		}, //关闭加载框
		closeLoad: function() {
			this.loadNum = this.loadNum?(this.loadNum < 0?1:this.loadNum):1;
			this.loadNum--;
			if (!(this.loadNum > 0)) {
				this.css(this.loadElem, {
					'z-index': -9999999,
					'display': 'none'
				});
			}
			return this;
		},
		//加载失败
		errorLoad: function(str, cssObj) {
			var _this = this;
			this.closeLoad();
			let ysSrc ='data:image/png;base64,[encoded data, 5288 characters]';
			let src = (cssObj || {}).src || ysSrc;
			this.startLoad(str || "加载失败", src);
			this.iconImg.onload = function() {
				_this.css(_this.iconImg, Object.assign({
					'animation': 'none',
					"width": "150px",
					"height": "150px",
					"transition": "all 400ms"
				}, (cssObj || {})));
				this.onload = null;
			}
			this.iconImg.onerror = function() {
				cssObj = {};
				_this.closeLoad();
				_this.startLoad("图片加载失败", ysSrc);
				this.onerror = null;
			}
		},
		//样式
		css: function(elem, data) {
			if (elem && elem.style) {
				for (let i in data) {
					elem.style[i] = data[i];
				}
			}
			return this;
		},
		//打开窗口
		open:function(str,obj){
			var _this = this;
			obj = Object.assign({
				toolbar:"no",
				toolbar:"no",
				menubar:"no",
				scrollbars:"no",
				resizable:"no",
				location:"no",
				status:"no"
			},obj || {});
			let strArr = [];
			for(let i in obj){
				(i != 'url' && i != 'title') && strArr.push(i+'='+obj[i]);
			}
			this.startLoad(str||'正在打开……');
			let wopen = window.open(obj.url || "",obj.title || '',strArr.join(','));
			wopen.onload = function(){
				_this.closeLoad();
			}
			setTimeout(function(){
				wopen.opener.U.closeLoad();
			},1000);
		}
	});
	//判断客户端
	U.cT = function(obj){
		//obj传入判断对象
		let ua = navigator.userAgent.toLowerCase(); //获取浏览器标识并转换为小写
		return Object.assign({
			isiOS: !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //是否苹果
			isAndroid: ua.indexOf('android') > -1 || ua.indexOf('adr') > -1, //是否安卓
			isPC: (function() {
				var Agents = new Array("android", "iphone", "symbianOS", "windows phone", "ipad", "ipod");
				var flag = true;
				for (var v = 0; v < Agents.length; v++) {
					if (ua.indexOf(Agents[v]) > 0) {
						flag = false;
						break;
					}
				}
				return flag;
			})(), //是否PC
			isWeiXin: ua.match(/MicroMessenger/i) == "micromessenger", //是否微信
			isQQ: ua.indexOf(' qq/') > -1, //是否QQ
		},obj);
	}
	//别名设置
	U.L = U.startLoad;
	U.C = U.closeLoad;
	U.E = U.errorLoad;
})();
