function UserLogin(body, success, fail) {
    var url = base_server_url + USER_LOGIN

    ajaxPost(url, body, function(response) {
        var data = response;
        if (data.result_code == 0) {
            //存储token
            $.zui.store.set("user", data.result_data);
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function GetUserInfo(success, fail) {

    var url = base_server_url + "/user/getUserInfo"
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            //存储token
            var user = $.zui.store.get("user");
            data.result_data.token = user.token;
            $.zui.store.set("user", data.result_data);
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });

}


function UserLoginOUT(success, fail) {
    var url = base_server_url + USER_LOGOUT
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            //存储token
            $.zui.store.set("user", "");
            success()
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}



function UserGetList(data, success, fail) {
    var url = base_server_url + USER_GET_LIST
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function UserAdd(data, success, fail) {
    var url = base_server_url + USER_ADD
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function UserUpdate(data, success, fail) {
    var url = base_server_url + USER_UPDATE + data.id
    ajaxPut(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function UserDelete(data, success, fail) {
    var url = base_server_url + USER_DELETE + data.id
    ajaxDelete(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}


function MenuGetAll(success, fail, body) {
    //alert(body);
    var url = base_server_url + MENU_GET_ALL
    ajaxPost(url, body, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function PermisionGetAll(success, fail) {
    var url = base_server_url + PERMISION_GET_ALL
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function PermisionRoleAdd(data, success, fail) {
    var url = base_server_url + PERMISION_ROLE_ADD
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function PermisionRoleEDIT(data, success, fail) {
    var url = base_server_url + PERMISION_ROLE_EDIT
    ajaxPut(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}


function PermisionRoleDELETE(data, success, fail) {
    var url = base_server_url + PERMISION_ROLE_DELETE
    ajaxDelete(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}




function PermisionAdd(data, success, fail) {
    var url = base_server_url + PERMISION_ADD
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function PermisionEdit(data, success, fail) {
    var url = base_server_url + PermisionEdit + data.id
    ajaxPut(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function PermisionDelete(id, success, fail) {
    var url = base_server_url + PERMISION_DELETE + id;
    ajaxDelete(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}





function DeptGetAll(success, fail) {
    var url = base_server_url + DEPT_GET_ALL
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function DeptAdd(data, success, fail) {
    var url = base_server_url + DEPT_ADD
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function DeptEdit(data, success, fail) {
    var url = base_server_url + DEPT_EDIT + data.id
    ajaxPut(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function DeptDelete(id, success, fail) {
    var url = base_server_url + DEPT_DELETE + id
    ajaxDelete(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function getConstantList(url, param, success, fail) {
    var url = base_server_url + url;
    ajaxPost(url, param, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}


function VideoGetById(id, success, fail) {
    var url = base_server_url + VIDEO_GET_ID + id;
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function VideoGetByIds(ids, success, fail) {
    var url = base_server_url + VIDEO_GET_IDs + ids;
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}


function no_return_common_service(url, param, success, fail) {
    var url = base_server_url + url;
    ajaxPost(url, param, function(response) {
        var data = response;
        if (data.result_code == 0) {
            if (success)
                success(data.result_desc)
        } else {
            layer.msg(data.result_desc, {
                time: 2000 //20s后自动关闭
            });
        }
    }, function(error) {
        fail("网络错误");
    });
}

function post_common_service(url, param, success, fail) {
    var url = base_server_url + url;
    ajaxPost(url, param, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            if (fail)
                fail(data.result_desc);
            else
                console.log(data.result_desc);
        }
    }, function(error) {
        if (fail)
            fail("网络错误");
        else
            console.log("网络错误");
    });
}

function get_common_service(url, param, success, fail) {
    var url = base_server_url + url;
    ajaxGet(url, param, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function get_common_service_nohead(url, param, success, fail) {
    var url = url;
    ajaxGet(url, param, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}



// 上传文件
function uploadFile(file, name, successfunc, errorfunc, parentPath) {
    var dataurl = base_image_server_url + "/fileServer" + FILE_UPLOAD
    var form = new FormData();
    form.append(name, file);
    if (parentPath)
        form.append('parentPath', parentPath);
    else
        form.append('parentPath', 'head');
    $.ajax({
        url: dataurl,
        type: "POST",
        cache: false,
        contentType: false,
        processData: false,
        dataType: "json",
        data: form,
        success: function(response) {
            var data = response;
            if (data.result_code == 0) {
                successfunc(data.result_data)
            } else {
                errorfunc(data.result_desc);
            }
        },
        error: function(error) {
            errorfunc("网络错误");
        }
    });
}

function RoleGetALLNoData(success, fail) {
    var url = base_server_url + ROLE_GET_ALL;
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function RoleAdd(data, success, fail) {
    var url = base_server_url + ROLE_ADD;
    ajaxPost(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function RoleUpdate(data, success, fail) {
    var url = base_server_url + ROLE_EDIT + data.id;
    ajaxPut(url, data, function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function RoleDelete(roleid, success, fail) {
    var url = base_server_url + ROLE_DELETE + roleid;
    ajaxDelete(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}






function RoleGetByPermision(permisionid, success, fail) {
    var url = base_server_url + ROLE_GET_BY_PERMISION + permisionid;
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}


function RoleGetALL(page, size, success, fail) {
    var url = base_server_url + ROLE_GET_ALL_DATA + "/" + page + "/" + size;
    ajaxGet(url, "", function(response) {
        var data = response;
        if (data.result_code == 0) {
            success(data.result_data)
        } else {
            fail(data.result_desc);
        }
    }, function(error) {
        fail("网络错误");
    });
}

function gohome(){
    window.location.href = base_ui_url + "view/new.html?time=" + (Date.parse(new Date()));
}