import { http,getToken } from '../utils/request'
import config from '../config'
import { $waiting } from '@/components/shared/loading'


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

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

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

const CLIENT_CODE =  config.client_code


/**
 * 检测登陆状态
 */
export function checkLogin() {
    return http.get('/fcb/pano/common/checkToken')
}


/**
 * 上传封面
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function uploadCover(data, ok, no) {
    return http.uploadBlobFile('/fcb/pano/scene/upload', data, ok, no)
}

/**
 * 上传初始画面
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function uploadIndexImg(data, ok, no) {
    return http.uploadBlobFile(`/fcb/pano/init/uploadIndexImg/${data.sceneCode}`, data, ok, no)
}



/**
 * 获取全景图基本信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function getPanoInfo(data, ok, no) {
    return http.get(`/fcb/pano/scene/house/detail/${number()}`, {}, ok, no)
}


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


/**
 * 删除初始场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delInit(data, ok, no) {
    return http.get(`/fcb/pano/init/remove/${data}`, {}, ok, no)
}




/**
 * 保存初始场景（list）
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveInitScene(data, ok, no) {
    data.houseId = number()
    return http.postJson(`/fcb/pano/init/save`, data, ok, no)
}

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

/**
 * 保存初始场景
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
export function saveIndexInfo(data, ok, no) {
    data.houseId = number()
    return http.postJson(`/fcb/pano/init/save`, 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)=>{
        setTimeout(() => {
            $waiting.show()
        });
        let tmp = {
            ...data,
            authcode:res.data.authcode,
            req_time:res.data.timeStamp,
            client_code:CLIENT_CODE
        }
        return http.postJson(`/vr/prodvr/prod/v1/details/queryHouseByProdId`, tmp, ok, no)
    })
}



/**
 * vr户型是否绑定的操作
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function isBindVr(data, ok, no) {
    data.prodId = HDNumber()
    getAuthCode(data,(res)=>{
        setTimeout(() => {
            $waiting.show()
        });
        let tmp = {
            ...data,
            authcode:res.data.authcode,
            req_time:res.data.timeStamp,
            client_code:CLIENT_CODE
        }
        return http.postJson(`/vr/prodvr/prod/v1/bind`, tmp, ok, no)
    })
}

/**
 * 获取经纪人列表
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function getAgentSelectList(data, ok, no) {
    data.prodId = HDNumber()
    getAuthCode(data,(res)=>{
        setTimeout(() => {
            $waiting.show()
        });
        let tmp = {
            ...data,
            authcode:res.data.authcode,
            req_time:res.data.timeStamp,
            client_code:CLIENT_CODE
        }
        return http.postJson(`/vr/prodvr/prod/v1/getZygwList`, tmp, ok, no)
    })
}


/**
 * 保存经纪人
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveAgent(data, ok, no) {
    return http.postJson(`/fcb/pano/scene/editAgent`, 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 savePanoHouse(data, ok, no) {
    data.houseId = number()
    data.hengdaId = HDNumber()
    data.byType = data.byType ||'garden'

    return http.postJson(`/fcb/pano/scene/saveGardenVrModel`, 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 getShowSceneInfo(data, ok, no) {
    return http.get(`/fcb/pano/common/detail/${scene()}`, {}, ok, no)
}


//二手房



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


/**
 * 上传全景图
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function uploadPano(data, type, ok, no) {
    return http.uploadFile(`/fcb/pano/secondHand/uploadPano/${number()}/${HDNumber()}`, data, ok, no)
}


/**
 * 保存全景图配置信息
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveSomeData(data, ok, no) {
    return http.postJson('/fcb/pano/secondHand/editSomeData', data, ok, no)
}

/**
 * 删除全景图
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function delPano(data, ok, no) {
    return http.get(`/fcb/pano/secondHand/remove/${data}`, {}, ok, no)
}



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


/**
 * 保存初始画面
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveInitScreen(data, ok, no) {
    return http.post('/fcb/pano/secondHand/updateInitIcon', data, ok, no)
}


/**
 * 保存全景图初始视角
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function savePosition(data, ok, no) {
    return http.postJson('/fcb/pano/secondHand/editXml', data, 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/secondHand/fdkk/findVrModel`, data, ok, no)
}

/**
 * 保存已使用的热点
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function saveUseHots(data, ok, no) {
    return http.postJson(`/fcb/pano/secondHand/save/useHots`, data, ok, no)
}

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

/**
 * 判断二手房小区是否可编辑
 * @param {*} data 
 * @param {*} ok 
 * @param {*} no 
 */
 export function canEdit(data, ok, no) {
    return http.get(`/fcb/pano/secondHand/house/canEdit/${number()}`, {}, ok, no)
}
