import { http,getToken } from '../utils/request'
import config from '../config'


const number = function() {
    return config.projectNum
}

const scene = function() {
    return config.sceneNum
}

const HDNumber = function() {
    return config.hengdaNum
}

const CLIENT_CODE =  config.client_code
const URL_FILL =  config.urlFill





/**
 * 获取全景作品基本信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getPanoInfo(data, ok, no) {
    let ossUrl = `https://ossxiaoan.4dage.com/720yun_fd_manage`
    return http.get(`${ossUrl}/${data||number()}/someData.json?_=${Math.random()}`, {}, ok, no)
}


/**
 * 获取场景分组列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getTabList(data, ok, no) {
    return http.get(`${URL_FILL}/manage/catalog/getCatalog/${number()}`, data, ok, no)
}



/**
 * 根据分组ID获取场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getTabSceneList(data, ok, no) {
    return http.get(`${URL_FILL}/manage/catalog/getScene/${data.catalogId}`, {}, ok, no)
}

/**
 * 修改场景分组名称
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function editTabName(data, ok, no) {
    data.workId = number()
    return http.postJson(`${URL_FILL}/manage/catalog/save`, data, ok, no)
}


/**
 * 新增/保存全景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function savePanoToWorks(data, ok, no) {
    data.workId = number()
    return http.postJson(`${URL_FILL}/manage/scene/saves`, data, ok, no)
}


/**
 * 删除标签
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delTab(data, ok, no) {
    return http.get(`${URL_FILL}/manage/catalog/remove/${data}`, {}, ok, no)
}

/**
 * 删除场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delPano(data, ok, no) {
    return http.get(`${URL_FILL}/manage/scene/remove/${data}`, {}, ok, no)
}


/**
 * 获取四维看看场景列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getSceneList(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/work/select/4dkk/${number()}`, data, ok, no)
}


/**
 * 获取初始场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getIndex(data, ok, no) {
    return http.get(`${URL_FILL}/manage/scene/getIndex/${number()}`, data, ok, no)
}


/**
 * 保存初始场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveIndexInfo(data, ok, no) {
    return http.post(`${URL_FILL}/manage/scene/setIndex/${data.id}/${number()}`, '', ok, no)
}



/**
 * 上传封面
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function uploadCover(data, ok, no) {
    return http.uploadBlobFile(`${URL_FILL}/manage/work/upload`, data, ok, no)
}



/**
 * 保存全景图初始视角
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function savePosition(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/scene/editXml`, data, ok, no)
}


/**
 * 重命名全景图
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function editPanoName(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/scene/edit`, data, ok, no)
}


/**
 * 重命名分组名称
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function editCatalogName(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/catalog/edit`, data, ok, no)
}




/**
 * 保存初始画面
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function saveInitScreen(data, ok, no) {
    return http.post(`${URL_FILL}/manage/scene/saveIndex`, data, ok, no)
}

/**
 * 保存全景图配置信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveSomeData(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/scene/editSomeData`, data, ok, no)
}


/**
 * 保存使用的热点
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveUseHots(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/scene/save/useHots`, data, ok, no)
}



/**
 * 保存初始场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function deleteIndexInfo(data, ok, no) {
    return http.get(`${URL_FILL}/manage/scene/removeIndex/${number()}`, data, ok, no)
}




/**
 * 获取场景基本信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getSceneInfo(data, ok, no) {
    return http.get(`${URL_FILL}/manage/scene/detail/${scene()}`, {}, ok, no)
}


/**
 * 获取场景分组列表(展示端)
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getWebTabList(data, ok, no) {
    return http.get(`${URL_FILL}/web/common/getCatalog/${number()}`, data, ok, no)
}

/**
 * 检查作品是否可用
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function checkWork(data, ok, no) {
     let visit = ''
    if (window.location.pathname.indexOf('showMobile.html')>-1 || window.location.pathname.indexOf('show.html')>-1) {
        visit = 1111
    }

    return http.get(`${URL_FILL}/web/common/checkWork/${number()}${visit?('?visit='+visit):''}`, data, ok, no)
}


/**
 * 根据分组ID获取场景(展示端)
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getWebTabSceneList(data, ok, no) {
    return http.get(`${URL_FILL}/web/common/getScene/${data.catalogId}`, {}, ok, no)
}



/**
 * 检测登陆状态
 */
export function checkLogin() {
    if (window.location.pathname.indexOf('material.html')>-1) {
        return http.get(`${URL_FILL}/web/common/checkToken/?_=${Math.random()}`)
    }else{
        return http.get(`${URL_FILL}/manage/work/checkToken/${number()}`)
    }
}





/**
 * 检测素材状态
 */
 export function checkMStatus(data, ok, no) {
    return http.get(`${URL_FILL}/manage/fodder/checkStatus/${data.ids.join(',')}`, {islongpolling:data.islongpolling}, ok, no)
}




/**
 * 获取作品基本信息（展示端）
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getWebWorksInfo(data, ok, no) {
    return http.get(`${URL_FILL}/web/common/detail/${number()}`, {}, ok, no)
}



/**
 * 校验密码（展示端）
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function checkPassword(data, ok, no) {
    data.workId = number()
    return http.post(`${URL_FILL}/web/common/checkPwd`, data, ok, no)
}



/**
 * 获取初始场景（展示端）
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getWebIndex(data, ok, no) {
    return http.get(`${URL_FILL}/web/common/getIndex/${number()}`, {}, ok, no)
}



/**
 * 查询该作品是否存在场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getAllVrList(data, ok, no) {
    return http.get(`${URL_FILL}/manage/scene/findByWork/${number()}`, data, ok, no)
}





/**
 * 保存全景图基本信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function savePanoInfo(data, ok, no) {
    data.houseId = number()
    return http.postJson('/fcb/pano/scene/house/edit', data, ok, no)
}




/**
 * 获取房车宝签名
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getAuthCode(data, ok, no) {
    return http.postJson(`/fcb/project/api/query/authCode`, data, ok, no)
}

/**
 * 获取户型名称列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getHouseNameList(data, ok, no) {
    data.prodId = HDNumber()
    getAuthCode(data,(res)=>{
        let tmp = {
            ...data,
            authcode:res.data.authcode,
            req_time:res.data.timeStamp,
            client_code:CLIENT_CODE
        }
        return http.postJson(`/vr/prodvr/prod/v1/details/queryHouseNamesByProdId`, tmp, ok, no)
    })
}

/**
 * 获取户型列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getHouseList(data, ok, no) {
    data.token = getToken()
    data.houseId = number()
    return http.postJson(`/fcb/pano/scene/findVrModel`, data, ok, no)
}



/**
 * 保存户型
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function saveHouse(data, ok, no) {
    data.houseId = number()
    data.hengdaId = HDNumber()
    return http.postJson(`/fcb/pano/scene/saveVrModel`, data, ok, no)
}




/**
 * 获取全景图列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getPanoList(data, ok, no) {
    data.houseId = number()
    return http.postJson('/fcb/pano/scene/list', data, ok, no)
}

/**
 * 获取全景图列表（搜索）
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getSearchPanoList(data, ok, no) {
    data.houseId = number()
    return http.postJson('/fcb/pano/scene/searchUnion', data, ok, no)
}




/**
 * 获取楼盘详情
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getHouseDetail(data, ok, no) {
    data.houseId = number()
    return http.postJson(`/fcb/pano/scene/findRoom/${data.houseId}`, {}, ok, no)
}


/**
 * 调整顺序
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function setListSort(data, ok, no) {
    return http.postJson(`/fcb/pano/scene/setSort`, data, ok, no)
}





// 素材库

/**
 * 获取素材列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getMaterialList(data, ok, no) {
    let url = `${URL_FILL}/manage/fodder/list`
    // if (data.urlSelect) {
    //     url = `${URL_FILL}/manage/fodder/select/${data.type}/${number()}`
    // }
    return http.postJson(url, data, ok, no)
}

/**
 * 上传素材
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function uploadMaterial(data, subdata, ok, no, onProgress) {
    return http.uploadFile(`${URL_FILL}/manage/fodder/upload/${subdata.type}/${subdata.uid}`, data, ok, no, onProgress)
}

/**
 * 删除素材
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delMaterial(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/fodder/remove/${data}`, {}, ok, no)
}

/**
 * 修改素材
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function editMaterial(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/fodder/update`, data, ok, no)
}


/**
 * 添加我的作品
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function addWorks(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/work/add`, data, ok, no)
}

/**
 * 获取我的作品列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getWorksList(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/work/list`, data, ok, no)
}

/**
 * 保存我的作品
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveWorks(data, ok, no) {
    data.id = number()
    return http.postJson(`${URL_FILL}/manage/work/edit`, data, ok, no)
}


/**
 * 删除我的作品
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delWorks(data, ok, no) {
    return http.postJson(`${URL_FILL}/manage/work/remove/${data}`, {}, ok, no)
}


