import fetch from './fetch'
import { api, physics } from './config'
import http from './httpUtil'
let dataForm = '/data-platform-3'
let arithmetic = '/arithmetic'
    // let dataForm = ''

var Comming = 'revit'
var ProjId = 'Pj1101080001'
var UserId = '25518428919955458'
    //获取打印标签模板test
export function getTest() {
    return fetch({ method: 'GET', url: `${api}/ScanBuilding/service/template/note_template` })
}

//查看扫楼日志接口

export function getBuildLog(
    param
) {
    let data = {
        "BeginTime": param.startTime,
        "Comming": Comming,
        "EndTime": param.endTime,
        "Filter": param.filter,
        "PageNum": param.pageNum,
        "PageSize": param.pageSize,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user_log/query`, data })
}

//下载扫楼日志接口

export function dowmloadLog(
    param
) {
    let data = {
        "BeginTime": param.startTime,
        "Comming": Comming,
        "EndTime": param.endTime,
        "Filter": param.filter,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user_log/export`, data })
}

//获取扫楼用户表格
export function getUser(
    param
) {
    let data = {
        "Comming": Comming,
        "Filter": param.filter,
        "PageNum": param.pageNum,
        "PageSize": param.pageSize,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user/query`, data })
}

//修改扫楼用户
export function loadUser(
    param
) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "UserList": param.UserList
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user/update`, data })
}

//删除扫楼用户
export function delUser(
    param
) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "UserList": param.UserList
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user/delete`, data })
}

//添加扫楼用户
export function addUser(
    param
) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "User": param.User
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/user/create`, data })
}

//根据项目ID获得建筑列表
export function getBuildSelect(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/building/query`, data })
}

//根据建筑ID获取楼层系信息
export function getFloor(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "BuildId": param.BuildId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/building/floor`, data })
}

//获取异常资产接口
export function getErrAssets(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "BuildId": param.BuildId,
        "PageNum": param.PageNum,
        "PageSize": param.PageSize,
        "Type": param.Type,
        "CodeType": param.CodeType
    }
    if (param.BuildId == 'all') {
        delete data.BuildId
    }

    if (!param.CodeType) {
        delete data.CodeType
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/exception`, data })
}

//删除资产接口
export function delErrAssets(param, paramList) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "FmList": paramList
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/delete`, data })
}

//根据选择的建筑楼层时间查询点位标签
export function getPT(param) {
    let data = {
        "Comming": Comming,
        "BeginTime": param.BeginTime,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "BeginTime": param.BeginTime,
        "EndTime": param.EndTime,
        "BuildId": param.BuildId,
        "FloorId": param.FloorId
    }
    if (data.FloorId == 'all') {
        delete data.FloorId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/point_group`, data })
}

//点位标签查看详情
export function getPoint(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "PointId": param.PointId,
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/point/query`, data })
}

//点位标签详情修改
export function updatePoint(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "PointList": [param.PointList],
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/point/update`, data })
}

//点击点位标签获取tab设备族列表 
export function getTabFamily(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId,
        "BeginTime": param.BeginTime,
        "EndTime": param.EndTime,
        "FloorId": param.FloorId,
        "Checked": param.Checked,
        "BuildId": param.BuildId,
        "PointId": param.PointId
    }
    if (data.PointId == 'all') {
        delete data.PointId
    }
    if (data.FloorId == 'all') {
        delete data.FloorId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/family_list`, data })
}

//获取表格数据的title
export function getTableHeader(param) {
    let data = {
        "AppType": Comming,
        "Code": param.code,
        "ProjId": param.ProjId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/dict/infocode_query`, data })
}

//获取表格主体内容
export function getTableMain(param) {
    let data = {
        "BeginTime": param.BeginTime,
        "BuildId": param.BuildId,
        "Checked": param.Checked,
        "Comming": Comming,
        "EndTime": param.EndTime,
        "Family": param.Family,
        "FloorId": param.FloorId,
        "PageNum": param.PageNum,
        "PageSize": param.PageSize,
        "PointId": param.PointId,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    if (data.PointId == 'all') {
        delete data.PointId
    }
    if (data.Checked === '') {
        delete data.Checked
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/query`, data })
}

export function getPointList(param, success) {
    let url = `${api}/ScanBuilding/service/point/queryByIdList`
    let data = param
    data.Comming = Comming
    http.postJson(url, data, success)
}

export function getdelMain(param) {
    let data = {
        "BeginTime": param.BeginTime,
        "BuildId": param.BuildId,
        "Checked": param.Checked,
        "CodeType": param.CodeType,
        "Comming": Comming,
        "EndTime": param.EndTime,
        "Family": param.Family,
        "FloorId": param.FloorId,
        "PageNum": param.PageNum,
        "PageSize": param.PageSize,
        "PointId": param.PointId,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    if (data.PointId == 'all') {
        delete data.PointId
    }
    if (data.Checked === '') {
        delete data.Checked
    }
    if (data.FloorId == 'all') {
        delete data.FloorId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/queryRevit`, data })
}

export function getTestEquire() {
    let data = {
        "Comming": "revit",
        "FloorId": "Fl110108000327d8f006c39f49feb40e24a7ef223232",
        "ProjId": "Pj1101080003",
        "UserId": "string"
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/query`, data })
}

//批量更新表格数据
export function upDateTableMain(param, paramList) {
    let data = {
        "Comming": Comming,
        "FmList": paramList,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/update`, data })
}

//获取所有设备族/service/dict/equipment_family
export function getAllFamily() {
    return fetch({ method: 'GET', url: `${api}/ScanBuilding/service/dict/equipment_family` })
}

//获取当前默认楼层/service/fm/default_floor
export function defaultFloor(param) {
    let data = {
        "Comming": Comming,
        "ProjId": param.ProjId,
        "UserId": param.UserId
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/fm/default_floor`, data })
}

//物理世界新建岗位（设备系统）
export function createPost(param) {
    let data = {
        "building_id": param.BuildId,
        "floor_id": param.BIMID,
        "equipment_category": param.category,
        "infos": {
            "BIMID": [
                { "value": param.BIMID }
            ],
            "BIMLocation": [
                { "value": param.BIMLocation }
            ]
        }
    }
    return fetch({ method: 'POST', url: `${physics}/godhand/equipment/create?projectId=${param.perjectId}&secret=${param.secret}`, data })
}


//物理世界新建岗位（部件）
export function createComponent(param) {
    let data = {
        "building_id": param.BuildId,
        "component_category": param.category,
        "floor_id": param.BIMID,
        "infos": {
            "BIMID": [
                { "value": param.BIMID }
            ],
            "BIMLocation": [
                { "value": param.BIMLocation }
            ]
        }
    }
    return fetch({ method: 'POST', url: `${physics}${dataForm}/component/create?projectId=${param.perjectId}&secret=${param.secret}`, data })
}

//通过岗位id查询元空间id
export function getSpaceId(param) {
    let data = {
        "criterias": param.list
    }
    return fetch({ method: 'POST', url: `${physics}${dataForm}/relation/query?projectId=${param.perjectId}&secret=${param.secret}`, data })
}

//通过元空间id查询元空间名称
export function getSpaceName(param) {
    let data = {
        "criterias": param.list
    }
    return fetch({ method: 'POST', url: `${physics}${dataForm}/object/batch_query?projectId=${param.perjectId}&secret=${param.secret}`, data })
}


//设备族修改显示接口
export function setHeader(param) {
    let data = {
        "Comming": Comming,
        "InfoType": param.FamilyId,
        "InfopointCode": param.code,
        "ProjId": param.perjectId,
        "UserId": param.UserId,
        "Visible": param.Visible
    }
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/dict/infopoint_visible`, data })
}

//获取头部接口
export function getHeader(param) {
    let data = {
            "AppType": Comming,
            "Code": param.code,
            "ProjId": param.perjectId
        }
        // return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/dict/equipment_family_info_header`, data })
    return fetch({ method: 'POST', url: `${api}/ScanBuilding/service/dict/infocode_query_header`, data })
}


/** 业务空间相关 */

// 业务空间
export function getSpaceHeader(param) {
    return fetch({ method: 'GET', url: `${physics}${dataForm}/infocode/query_property?projectId=${param.ProjId}&type=${param.code ? param.code : 'space'}&enrich=true` })
}


//获取某个业务空间下的
export function getAllbusiness(param) {
    let data = null
    if (!!param.id) {
        data = {
            "criteria": {
                "id": param.id,
                "type": param.type
            }
        }
    } else {
        data = param.data
    }
    return fetch({ method: "POST", url: `${physics}${dataForm}/object/subset_query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//通过BIMID获取物理世界id
export function formBIMToPri(param) {
    let data = {
        "criteria": {
            "type": param.type,
            "BIMID": param.ids
        }
    }
    return fetch({ method: "POST", url: `${physics}${dataForm}/fast/object/in_query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//获取业务空间楼层的关系
export function getSpaceFloor(param) {
    return fetch({ method: "POST", url: `${physics}/business-space/floor/tree?projectId=${param.ProjId}&secret=${param.secret}` })
}

//创建业务空间
export function createBusiness(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/space/create?projectId=${param.ProjId}&secret=${param.secret}`, data })
        // return fetch({ method: "POST", url: `/test/space/create?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//批量创建业务空间
export function createBusinessList(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/space/batch/create?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//更新业务空间
export function updateBusiness(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/object/batch_update?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//模糊搜索设备类型
export function searchCode(param) {
    let data = param
    return fetch({ method: "POST", url: `${physics}${dataForm}/dict/query/equipment_all`, data })
}

//获取所有设备类型
export function getEqCode() {
    return fetch({ method: "GET", url: `${physics}${dataForm}/dict/query/equipment_all` })
}

//批量删除业务空间
export function delManySpace(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/space/batch/delete?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//添加关系
export function createRelation(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/relation/create?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//获取图实例关系
export function getGraphyId(param) {
    let data = {
        "graph_type": param.type
    }
    return fetch({ method: "POST", url: `${physics}${dataForm}/relation/graph_instance/get?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//查询业务空间
export function getBussines(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/object/outside_query?projectId=${param.ProjId}&secret=${param.secret}`, data })
        // return fetch({ method: "POST", url: `/test/object/outside_query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//替代前一个接口
export function getBussines2(param) {
    let data = param.data
    return fetch({ method: "POST", url: `${physics}${dataForm}/fast/object/in_query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//查询业务空间下的元空间
export function getRelation(param) {
    let data = param.criterias
    return fetch({ method: 'POST', url: `${physics}${dataForm}/relation/query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//查询业务空间下的设备
export function getSpaceEquip(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}/business-space/space/equip/query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//删除关系实例
export function deleteRelation(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}${dataForm}/relation/delete?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//查询是否关联元空间的业务空间
export function isSpaceBuss(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}/business-space/floor/space/query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//查询所有提示
export function getAllMess(param) {
    let data = {}
    return fetch({ method: 'POST', url: `${physics}${dataForm}/space/affected/query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//删除提示
export function deleteNotice(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}${dataForm}/space/affected/delete_notice?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

//模糊查询楼层下的设备
export function getEquipSearch(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}/business-space/floor/equip/query?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

export function getBussTypes(success) {
    http.getJson(`${physics}${dataForm}/infocode/business_space_type/query`, {}, success)
}

export function getBussTypes2() {
    return fetch({ method: 'GET', url: `${physics}${dataForm}/infocode/business_space_type/query` })
}




//验证元空间是否相邻
export function isAbut(param) {
    let data = param.data
    return fetch({ method: 'POST', url: `${physics}/business-space/space/abut?projectId=${param.ProjId}&secret=${param.secret}`, data })
}

/**算法接口 */
export function strDiff(param) {
    let data = param
    return fetch({ method: 'POST', url: `${arithmetic}/str_diff`, data })
}


/********* 台账部分  厂商库接口 */
//获取供应商列表
export function getManuLib(param, success) {
    let data = param
    http.postJson(`${physics}venders/supplier/query`, data, success)
}

//查询所有供应商信息
export function getLib(param) {
    let data = param
    return fetch({ method: 'POST', url: `${physics}/venders/auxiliary/query/all`, data })
}

//查询资产的list
export function getPropertyList(param, success) {
    let data = param.data
    let url = `${physics}/data-platform-3/property/relation_query?projectId=${param.ProjId}&secret=${param.secret}`
    http.postJson(url, data, success)
}

//获取资产种族编码query/equipment_family
export function getEquipmentFamily(success) {
    let url = `${physics}/data-platform-3/dict/query/equipment_family`
    http.getJson(url, {}, success)
}

//删除资产
export function delProperty(param, success) {
    let url = `${physics}/data-platform-3/property/delete?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取制定供应商下的供应合同编号
export function getListForSupplier(param, success) {
    let url = `${physics}/venders-dp/supplier/contract/query?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取保单列表
export function getListForGuarantee(param, success) {
    let url = `${physics}/venders-dp/insurance/contract/query`
    let data = param.data
    http.postJson(url, data, success)
}

//新建保单
export function createGuarantee(param, success) {
    let url = `${physics}/venders/insurance/contract/create `
    let data = param.data
    http.postJson(url, data, success)
}

//创建资产
export function createProperty(param, success) {
    let url = `${physics}${dataForm}/property/create?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取项目内[岗位]和[绑定岗位的资产]的数量
export function getNumber(param, success) {
    let url = `${physics}/business-space/equip/count?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取项目内有实例的所有种族
export function getFamilyList(param, success) {
    let url = `${physics}/business-space/equip/type/list?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//删除系统、设备
export function delSystem(param, success) {
    let url = `${physics}${dataForm}/equipment/delete?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}


//创建系统设备
export function createSystem(param, success) {
    let url = `${physics}${dataForm}/equipment/create?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}


//获取台账资产列表
export function getBillPropList(param, success) {
    let url = `${physics}/business-space/property/list?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//台账修改资产信息
export function updateProperty(param, success) {
    let url = `${physics}${dataForm}/property/update?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//台账获取设备列表
export function getBillEquipList(param, success) {
    let url = `${physics}/business-space/equip/list?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//台账获取系统列表
export function getBillSystemList(param, success) {
    let url = `${physics}/business-space/system/list?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//台账获取系统关联的设备
export function getSysToEq(param, success) {
    let url = `${physics}${dataForm}/object/rel_query?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//台账查询型号
export function getSpecList(param, success) {
    let url = `${physics}/venders/manufacturer/specification/query_spec`
    let data = param
    http.postJson(url, data, success)
}

//台账根据设备id创建岗位
export function EqToAssets(param, success) {
    let url = `${physics}${dataForm}/property/create_by_equip?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取设定参数和动态参数
export function BeatchQueryParam(param, success) {
    let url = `${physics}${dataForm}/parameter/batch_query_param?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

export function BatchCreateSome(param, success) {
    let url = `${physics}${dataForm}/equipment/batch/create?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

export function delBatchList(param, success) {
    let url = `${physics}${dataForm}/equipment/batch/delete?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}


//扫楼创建资产
export function createFmList(param, success) {
    let url = `${api}/ScanBuilding/service/fm/create`
    param.Comming = Comming
    let data = param
    http.postJson(url, data, success)
}

export function createAssetsList(param, success) {
    let url = `${api}/ScanBuilding/service/fm/create_list`
    param.Comming = Comming
    let data = param
    http.postJson(url, data, success)
}

export function getListForBuss(param, success) {
    let url = `${physics}/business-space/space/ispace/equip/query?projectId=${param.ProjId}&secret=${param.secret}`
    let data = param.data
    http.postJson(url, data, success)
}

//获取产品list
export function getProductList(param, success) {
    let url = `${physics}/venders/manufacturer/product/queryByType`
    http.postJson(url, param, success)
}

//完全匹配的厂商信息
export function getBasicMatch(param) {
    console.log(param, "param")
    let data = param
    return fetch({ method: 'POST', url: `${physics}/venders/basic/autoFillId`, data })
}