/** 
    @ Name : Careff Javascript Library 
    @ Author : 
    @ Date : 2017-5-1
    @ Email : 
    @ Version : 1.0 
    @ Update : 
    功能： 开始建立自己的JS类库，需要按照功能进行分类；
     */
(function () {
    if (!window.usbasic) {
        window.usbasic = {};
    };
    window.usbasic = {
        NAME: "usbasic",
        VERSION: '1.0',
        DATE: '2017-12-16',
        INDEX: 10,
        /** 
       @ Name :获取URL参数
       @ Update : 
       */
        UsGetUrlParam: function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            //alert(r);
            if (r != null) return unescape(r[2]); return null;
        }
        /** 
       @ Name :在URL中增加时间字符串
       @ Update : 
       */
        ,
        UsURLAddDate: function (url) {
            var timestamp = Date.parse(new Date());
            timestamp = timestamp / 1000;
            if (url.indexOf("?") > 0) {
                url += "&";
            }
            else {
                url += "?";
            }
            url += "jsdate=" + timestamp;

            return url;
        }
        , UsURLAdd: function (url, add) {
            if (url.indexOf("?") > 0) {
                url += "&";
            }
            else {
                url += "?";
            }
            url += add;
            return url;
        }
        ,
        //关闭Loading
        UsCloseLoad: function () {
            //alert();
            //layer.closeAll('loading');
            layer.close(usbasic.INDEX);
        },
        //关闭Loading
        UsOpenLoad: function () {
            usbasic.INDEX = layer.msg('玩命加载中', {
                icon: 16, shade: 0.01, time: 5000000
            });
            //usbasic.INDEX = layer.load(1, {
            //    shade: [0.1, '#fff'] //0.1透明度的白色背景
            //});
        }
        ,
        /** 
       @ Name :字符转JSON
       @ Update : 
       */
        UsStrToJSON: function (sJson) {
            var isjson = typeof (sJson) == "object" && Object.prototype.toString.call(sJson).toLowerCase() == "[object object]" && !sJson.length;
            //console.debug(isjson);
            if (isjson) {
                return sJson;
            }
            else {
                //sJson = JSON.stringify(sJson);
                return $.parseJSON(sJson);
            }
        }
        , UsJSON: function (usdata) {
            var data1 = eval("(" + usdata + ")");
            return data1;
        }
        ,
        /** 
      @ Name :JSON转字符
      @ Update : 
      */
        UsJSONToStr: function (sJson) {
            
            sJson = JSON.stringify(sJson);
            return sJson;
        }
        ,
        errorMsg:function (text) {
    	    top.layer.msg(text, { icon: 2, time: 5000 });
        },
        /**成功 msg提示 */
        successMsg:function (text) {
            top.layer.msg(text, { icon: 1, time: 2000 });
        },
        /**警告弹出提示*/
        warnMsg:function (text) {
            top.layer.msg(text, { icon: 0, time: 2000 });
        },
        /**警告弹出提示*/
        tipsMsg: function (text,id) {
            top.layer.tips(text, id, {
                tips: [1, '#3595CC'],
                time: 4000
            });
        },
        setCloseIframeData: function (state) {
            layui.data('IframeData', { key: 'key', value: state });
        },
        getCloseIframeData: function () {
            var data = layui.data('IframeData').key;
            if (data == '' || data == null) {
                data = "";
            }
            else {
                layui.data('IframeData', { key: 'key', value: '' });
            }
            return data;
        }
        ,
        ussetreturndata: function (key, state) {
            layui.data(key, { key: 'key', value: state });
        },
        usgetreturndata: function (key) {
            var data = layui.data(key).key;
            if (data == '' || data == null) {
                data = "";
            }
            else {
                layui.data(key, { key: 'key', value: '' });
            }
            return data;
        }
        ,
        setCacheData: function (key, value) {
            layui.data(key, { key: 'key', value: value });
        },
        //不清楚缓存获取数据
        getCacheData: function (key) {
            var data = layui.data(key).key;
            if (data == '' || data == null) {
                data = "";
            }
            return data;
        }
    };

})();