//动态获取url
//const BASEURL = getRequestPrefix();

// 动态获取用户名密码
// const LOGIN_NAME = sessionStorage.getItem('V_LOGINNAME');
// const LOGIN_PASSWORD = sessionStorage.getItem('V_PASSWORD');


//服务端url
// const BASEURL = "http://101.133.214.75:8080/Device_Manager/";

//本地调试url
// const BASEURL = "http://127.0.0.1:8080/Device_Manager/";

//最新测试url
const BASEURL = "http://121.40.217.77:8080/Device_Manager/";

//用户名、密码 
const LOGIN_NAME = "admin";
const LOGIN_PASSWORD = "e10adc3949ba59abbe56e057f20f883e";



const UPLOAD_FILE = 'sys/uploadSysIcon'; //logo上传



const COMPANY_LIST_ORG = "companyManagement/queryCompanyList"; //单位查询（组织机构）
const COMPANY_ADD = "companyManagement/addCompany"; //单位新增（组织机构）
const COMPANY_UPDATE = "companyManagement/updateCompany"; //单位更新（组织机构）
const COMPANY_DELETE = "companyManagement/delCompany"; //单位删除（组织机构）

const DEPARTMENT_LIST = "companyManagement/queryDepartment"; //部门查询（组织机构）
const DEPARTMENT_ADD = "companyManagement/addDepartment"; //部门新增（组织机构）
const DEPARTMENT_UPDATE = "companyManagement/updateDepartment"; //部门更新（组织机构）
const DEPARTMENT_DELETE = "companyManagement/delDepartment"; //部门删除（组织机构）


const COMPANY_LIST = "companyManagement/queryCompany"; //公司列表
const USER_LIT = "user/queryUser"; //用户列表
const USER_ROLE = "user/queryRole"; //角色查询
const USER_ADD = "user/addUser"; //增加用户
const USER_UPDATE = "user/updateUser"; //修改用户
const USER_DELETE = "user/delUser"; //删除用户
const USER_EXPORT = "user/exeportUser"; //用户导出


const MENU_LIST = "menu/queryMenu"; //菜单查询
const MENU_ADD = "menu/addMenu"; //菜单新增
const MENU_UPDATE = "menu/updateMenu"; //菜单编辑          
const ROLE_AUTH_UPDATA = "user/updateRoleMenu"; //角色权限编辑



const SECURITY_LIST = "user/querySecurityMechanism"; //安全机制列表
const SECURITY_UPDATE = "user/updateSecurityMechanism"; //安全机制更新

const UNIT_LIST = "sys/querySys"; //系统信息查询
const SYSTEM_ADD = "sys/addSys"; //系统信息新增
const SYSTEM_UPDATE = "sys/updateSys"; //系统信息更新  


const BUILDING_LIST = 'building/queryBuilds' //建筑管理列表查询  
const BUILDING_MANAGE_ADD = "building/addBuild"; //建筑管理新增 
const BUILD_MANAGE_UPDATE = "building/updateBuild"; //建筑信息更新  
const BUILD_MANAGE_DELETE = "building/delBuild"; //建筑删除  


const BUILDING_FLOOR_LIST = 'building/queryFloor' //楼层管理列表查询  
const BUILDING_FLOOR_ADD = "building/addFloor"; //楼层管理新增 
const BUILD_FLOOR_UPDATE = "building/updateFloor"; //楼层信息更新 
const BUILD_FLOOR_DELETE = "building/delFloor"; //楼层删除 

const BUILDING_ROOM_LIST = 'building/queryRoom' //房间管理列表查询  
const BUILDING_ROMM_ADD = "building/addRoom"; //房间管理新增 
const BUILD_ROOM_UPDATE = "building/updateRoom"; //房间信息更新 
const BUILD_ROOM_DELETE = "building/delRoom"; //房间删除 


const PROPERTY_LIST = 'facility/queryFacility' //资产管理列表查询  
const PROPERTY_ADD = "facility/addFacility"; //资产管理新增 
const PROPERTY_UPDATE = "facility/updateFacility"; //资产更新 
const PROPERTY_DELETE = "facility/delFacility"; //资产删除 
const PROPERTY_EXPORT = "facility/downloadFacilityExcl"; //资产导出 
const FACILITY_TYPE_LIST = 'facility/queryFacilityType' //类别查询  




const INDEX_LIST = 'iot/alarm/view/getFirstCount' //首页数据查询


const DEVICE_TYPE_COMPANYLIST = 'iot/dropdownbox/getNameList' //单位下拉框(设备管理模块)


const DEVICE_LIST_SEARCH = 'device/queryDeviceList' //设备列表查询
const DEVICE_LIST_ADD = "device/deviceRegister"; //设备列表新增  (本地设备注册)
const DEVICE_LIST_UPDATE = "device/deviceUpdate"; //设备列表修改   
const DEVICE_LIST_DELETE = "device/delDevice"; //设备列表删除



const DEVICE_TYPE_LIST = 'iot/devicetype/getDeviceTypeList' //设备类型查询
const TYPE_LIST = "iot/devicetype/getDeviceTypeList1"; //设备类型下拉

const DEVICE_TYPE_ADD = "iot/devicetype/appendDeviceType"; //设备类型新增
const DEVICE_TYPE_UPDATE = "iot/devicetype/updateDeviceType"; //设备类型修改
const DEVICE_TYPE_DELETE = "iot/devicetype/deleteDeviceType"; //设备类型删除

const DEVICE_COMMUNICATE_LIST = 'iot/interface/getInterfaceList' //通信列表查询
const DEVICE_COMMUNICATE_ADD = "iot/interface/appentInterface"; //通信新增
const DEVICE_COMMUNICATE_UPDATE = "iot/interface/updateInterface"; //通信修改
const DEVICE_COMMUNICATE_DELETE = "iot/interface/delInterface"; //通信删除

const DEVICE_CHECK_LIST = 'iot/monitorobject/getMonitorObjectsList' //监测对象列表查询
const DEVICE_CHECK_ADD = "iot/monitorobject/appendMonitorObjects"; //监测对象新增
const DEVICE_CHECK_UPDATE = "iot/monitorobject/updateMonitorObjects"; //监测对象修改
const DEVICE_CHECK_DELETE = "iot/monitorobject/deleteMonitorObjects"; //监测对象删除

const BUILD_TREE_LIST = "building/queryBuild"; //建筑 楼层 房间 树结构
const DEVICE_CHECK_DEVICE_LIST = "device/queryDeviceList"; //检测对象新增设备列表查询


const DEVICE_CHECKCHANNEL_LIST = 'iot/device_object_passageway/getDeviceObjectPassagewayList' //设备检测对象通道表列表查询
const DEVICE_CHECKCHANNEL_ADD = "iot/device_object_passageway/appendDeviceObjectPassageway"; //设备检测对象通道表新增
const DEVICE_CHECKCHANNEL_UPDATE = "iot/device_object_passageway/updateDeviceObjectPassageway"; //设备检测对象通道表修改
const DEVICE_CHECKCHANNEL_DELETE = "iot/device_object_passageway/deleteDeviceObjectPassageway"; //设备检测对象通道表删除

const WORK_MANAGE_LIST = 'iot/work_order/getWorkOrderList' //工单管理列表查询
const WORK_MANAGE_ADD = "iot/work_order/appendWorkOrder"; //工单管理新增
const WORK_MANAGE_HANDLE = "iot/work_order/updateWorkOrder"; //工单管理处置

const EVENT_MANAGE_LIST = 'iot/event_manage/getEventManageList' //事件管理列表查询
const EVENT_MANAGE_ADD = "iot/event_manage/appendEventManage"; //事件管理新增
const EVENT_MANAGE_HANDLE = "iot/event_manage/updateEventManage"; //事件管理处置

const EVENT_DANGER_MANAGE_LIST = 'iot/alarm/view/getYHList1' //隐患管理列表查询
const EVENT_DANGER_MANAGE_HANDLE = "iot/alarm/view/updateYh1"; //隐患管理处置

const EVENT_WARNING_MANAGE_LIST = 'iot/alarm/view/getGJList1' //告警管理列表查询
const EVENT_WARNING_MANAGE_HANDLE = "iot/alarm/view/updateGJ1"; //告警管理处置

const LOG_MANAGE_LIST = 'iot/log/getLogList' //日志管理列表查询  
const LOG_EXPORT = 'iot/log/getLogListExecl' //日志导出

function ajaxRequest(path, method, data, success, error, type = 1) {

    let url = path;

    if (url.indexOf("http") == -1) {
        url = BASEURL + path;
    }

    let loginUser = {
        "V_LOGINNAME": LOGIN_NAME,
        "V_PASSWORD": LOGIN_PASSWORD,
    }

    if (type == 1) {
        data.queryJson = JSON.stringify(loginUser);
    } else {

        let paramJson = {};

        for (key in loginUser) {
            paramJson[key] = loginUser[key];
        }

        for (key in data) {
            paramJson[key] = data[key];
        }

        data = {}
        data.queryJson = JSON.stringify(paramJson);
    }


    $.ajax({
        async: false, //同步
        data: data,
        url: url,
        type: method, //请求方式 post get delete put
        dataType: "json",
        beforeSend: function(XMLHttpRequest) {
            // $("#loading").html("<img src='images/loading.gif' />")
            // handlePreloader();
            // $(".loadingdata").append('<div class="preloader"></div>');

        },
        success: success,
        error: error
    });

}


function getUrl() {
    return window.location.protocol + '//' + window.location.host
}

function getRequestPrefix() {
    // 获取网络协议
    var protocol = window.location.protocol;
    // 获取主机名+端口号
    var domainPort = window.location.host;
    // 获取发布项目的名称
    // 获取路径
    var url = window.location.pathname;
    var webApp = url.split('/')[1];
    // http://127.0.0.1/demo
    var urlPrefix = protocol + "//" + domainPort + "/" + webApp + "/";
    return urlPrefix;
}