/*
 * @Author: tengmingxue 1473375109@qq.com
 * @Date: 2023-08-15 11:20:48
 * @LastEditors: tengmingxue 1473375109@qq.com
 * @LastEditTime: 2023-08-21 17:19:02
 * @FilePath: \xld-gis-admin\src\api\resource\scene.ts
 * @Description: 场景资源接口
 */
import { defHttp } from '/@/utils/http/axios';
enum Api {
    getMapService = '/base-center/SupermapProxy/getMapService',
    proxyDel = '/base-center/SupermapProxy/del',
    proxySave = '/base-center/SupermapProxy/edit',
}
const interfaceType = { apiUrl: true };

/**
 * @description:代理资源列表
 */
export function getProxyList(params) {
    params.page = params.page;
    params.rows = params.pageSize;
    console.log("代理中心数据:", params);
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.getMapService, params, ...interfaceType })
            .then((r) => {
                if (r.resp_code == 0) {
                    console.log("代理中心数据:", r.datas);
                    r.datas[params.serviceType].items = r.datas[params.serviceType].pageData
                    var list = r.datas[params.serviceType];
                    list.items.forEach(i => i.id = i.SERVICEID);
                    resolve(list);
                }
            })
    })
}


/**
 * @description:删除代理中心
 */
export function proxyDel(params) {
    return new Promise<void>((resolve, reject) => {
        defHttp.post({ url: Api.proxyDel, params: { mapServerProxy: [params] }, ...interfaceType })
            .then((r) => {
                if (r.resp_code == 0) {
                    resolve(r);
                }
            }).catch((r) => {
                reject(false);
            })
    })
}

/**
 * @description:保存修改代理中心
 */
export function proxySave(params) {
    var list = null;
    if (params.serviceid.indexOf(",") > -1) {
        list = params.serviceid.split(',').map(i => { return { serviceid: i, ipaddress: params.ipaddress } });
    } else {
        list = [params]
    }
    return defHttp.post({ url: Api.proxySave, params: { mapServerProxy: list }, ...interfaceType })
}

