/*
 * @Author: zzy 411037547@qq.com
 * @Date: 2022-04-28 10:47:35
 * @LastEditors: cclu 1106109051@qq.com
 * @LastEditTime: 2024-09-04 11:57:48
 * @FilePath: \cloud-platform\src\pages\basicManage\Serverpart\service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { tableList, wrapTreeNode } from '@/utils/format';
import request from '@/utils/request';
import type { ServerpartModel } from './data'; // 引用接口数据对象
// 获取列表【服务区站点】
export async function getList(params?: any) {
    const search = params ? { ...params, SortStr: params?.SortStr, keyWord: params?.keyWord, PageIndex: params?.PageIndex } : {};
    const data = await request(`/BaseInfo/GetSERVERPARTList`, {
        method: 'POST',
        data: search,
    });
    if (data.Result_Code !== 100) {
        return {
            data: [],
            current: 1,
            pageSize: 10,
            total: 0,
            success: false
        }
    }
    return tableList(data.Result_Data);
}
// 获取明细【服务区站点】
export async function getDetail(serverpartId: number) {
    const data = await request(`/BaseInfo/GetSERVERPARTDetail?serverpartId=${serverpartId}`, {
        method: 'GET',
    });
    if (data.Result_Code !== 100) {
        return {}
    }
    return data.Result_Data;
}
// 删除数据【服务区站点】
export async function delserverpart(serverpartid: number) {
    return request(`/BaseInfo/DeleteSERVERPART?serverpartid=${serverpartid}`, {
        method: 'POST',
        requestType: 'form',
    });
}
// 同步数据【服务区站点】
export async function updateserverpart(serverpart: ServerpartModel) {
    return request(`/BaseInfo/SynchroSERVERPART`, {
        method: 'POST',
        data: serverpart,
        requestType: 'form',
    });
}


// 拿到全部省份的服务区
export async function handleGetFieldEnumTree(params: any) {
    const data = await request(`/FrameWork/GetFieldEnumTree`, {
        method: 'GET',
        params
    });

    if (data.Result_Code !== 100) {
        return data
    }

    return wrapTreeNode(data.Result_Data.List)
}

// 拿到服务区详情
export async function handleGetSERVERPARTDetail(params: any) {
    const data = await request(`/BaseInfo/GetSERVERPARTDetail`, {
        method: 'GET',
        params
    });

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data
}

// 区域名称的选择列表
export async function handleGetSERVERPARTTYPEList(params: any) {
    const data = await request(`/BasicConfig/GetSERVERPARTTYPEList`, {
        method: 'POST',
        data: params
    });

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data.List
}


// 拿到省份编码
export async function handleGetFieEnumList(params: any) {
    const data = await request(`/Dictionary/GetFieEnumList`, {
        method: 'GET',
        params
    });

    if (data.Result_Code !== 100) {
        return data
    }

    return data.Result_Data.List
}
