/**
 扩展一个test模块
 **/

layui.define(function(exports){ //提示：模块也可以依赖其它模块，如：layui.define('layer', callback);
    var obj = {
        hello: function(str){
            console.log("123123123"+str)
        },
        ajaxPostRequest:function(url,data,id){
            var result;
            $.ajax({
                url:url,
                data:JSON.stringify(data),
                contentType:'application/json;charset=UTF-8',//关键是要加上这行
                traditional:true,//这使json格式的字符不会被转码
                type:"POST",
                async:false,
                dataType:"json",
                success:function (obj) {
                    result= obj;
                }
            });
            if (result.code=='01'){
                if (id!=undefined){
                    layui.table.reload(id);
                }
                return result.body;
            }else{
                layer.alert(result.message, {
                    icon: 2,
                    skin: 'layer-ext-moon'
                });
                return false;
            }
        },
        ajaxGetRequest:function(url,data,id){
            var result;
            $.ajax({
                url:url,
                data:data,
                type:"GET",
                async:false,
                dataType:"json",
                success:function (obj) {
                    result= obj;
                }
            });
            if (result.code=='01'){
                if (id!=undefined){
                    layui.table.reload(id);
                }
                return result.body;
            }else{
                layer.alert(result.message, {
                    icon: 2,
                    skin: 'layer-ext-moon'
                });
            }
        },
        ajaxNodeRequest:function(targetId,parentId){
            $.ajax({
                url:"/businessCategory/getByParentId",
                data:{parentId:parentId,state:1},
                dataType:"json",
                async:false,
                type:"GET",
                success:function (data) {
                    if (data.code=="01"){
                        $("#"+targetId).find("option").remove();
                        $("#"+targetId).append('<option value="">请选择</option>')
                        for (var i=0;i<data.body.length;i++){
                            $("#"+targetId).append('<option value="'+data.body[i].id+'" marketPrice="'+data.body[i].marketPrice+'" >'+data.body[i].name+'</option>');
                        }
                    }
                }
            })
        },
        ajaxRegionRequest:function(targetId,parentCode){
            $.ajax({
                url:"/lbs/getLbsMapList",
                data:{parentCode:parentCode},
                dataType:"json",
                async:false,
                type:"GET",
                success:function (data) {
                    if (data.code=="01"){
                        $("#"+targetId).find("option").remove();
                        $("#"+targetId).append('<option value="">请选择</option>')
                        for (var i=0;i<data.body.length;i++){
                            $("#"+targetId).append('<option value="'+data.body[i].adcode+'" >'+data.body[i].name+'</option>');
                        }
                    }
                }
            })
        },
        java8DateFormat:function (date) {
            return date.year+"-"+date.monthValue+"-"+date.dayOfMonth+" "+date.hour+":"+date.minute+":"+date.second
        },
        layuiOpen:function(id,width,height){
           var index= layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: [width, height], //宽高
                content: $("#"+id+"")
            });
           return index;
        }

    };
    //输出test接口
    exports('common', obj);
});