/*
 * @Author: cclu
 * @Date: 2021-12-13 11:01:23
 * @LastEditors: cclu 1106109051@qq.com
 * @LastEditTime: 2024-09-12 17:34:02
 * @FilePath: \cloud-platform\src\pages\Setting\Users\service.ts
 * @Description:
 *
 * Copyright (c) 2022 by cclu/杭州驿商科技, All Rights Reserved.
 */
import request from '@/utils/request';
import { tableList, wrapTreeNode } from '@/utils/format';
import type { UserModel } from './data';
// import type { ModuleItem } from './data';

// 获取列表数据
export async function getUserList(params?: any) {
    const data = await request('/Platform/GetUserList', {
        method: 'POST',
        data: { SearchParameter: { ...params }, SortStr: params.SortStr, keyWord: params?.keyWord, pageindex: params.current, pagesize: params.pageSize },
    })

    if (data.Result_Code !== 100) {
        return {
            data: [],
            current: 1,
            pageSize: 10,
            total: 0,
            success: false
        }
    }

    return tableList(data.Result_Data)
}
// 获取服务区树
export async function getServerpartTree(params?: any) {
    const data = await request('/FrameWork/GetServerpartTree', {
        method: 'GET',
        params
    })

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

    const treeTable = wrapTreeNode(data.Result_Data.List);
    return [...treeTable];
}


// 获取账号分类树
export async function getUserTypeTree(params?: any) {
    const data = await request('/FrameWork/GetUserTypeTree', {
        method: 'GET',
        params
    })

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

    const treeTable = wrapTreeNode(data.Result_Data.List);
    console.log('treeTable', treeTable)
    return [...treeTable];
}

// 获取账号详情数据
export async function getUserDetail(detailId?: any, ShowPush?: any) {
    const data = await request(`/Platform/GetUserDetail?userId=${detailId}&ShowPush=${ShowPush}`, {
        method: 'GET'
    })

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

    return data.Result_Data;
}

// 获取账号角色模块权限
export async function getUserSystemRole(detailId?: any) {
    const data = await request(`/FrameWork/GetUserSystemRoleTree?userId=${detailId}`, {
        method: 'GET'
    })

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

    const treeTable = wrapTreeNode(data.Result_Data.List);
    return [...treeTable];
}
// 更新用户信息
export async function updataUser(data?: UserModel) {

    return request('/Platform/SynchroUser', {
        method: 'POST',
        data,
        // requestType: 'form',
    });
}

// 重置账号密码
export async function modifyUserPassword(data: { UserId: number, Password: string }) {

    return request(`/FrameWork/ModifyUserPassword?userId=${data.UserId}&Password=${data.Password}`, {
        method: 'POST',
        data,
        requestType: 'form',
    });
}

// 获取商户账号服务区门店模块权限
export async function getMerchantShopTree(params: { BusinessManId?: any, provinceCode?: number }) {
    const data = await request(`/FrameWork/GetMerchantShopTree`, {
        method: 'GET',
        params
    })

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

    const treeTable = wrapTreeNode(data.Result_Data.List);
    return [...treeTable];
}

// 微信推送权限
export async function getWeiChatPush(params: any) {
    const data = await request(`/FrameWork/AuthorPush`, {
        method: 'GET',
        params
    })

    // if (data.Result_Code !== 100) {
    //   return []
    // }
    // Result_Data
    return data;
}
// 获取服务区列表
export async function handleGetServiceList(params: any) {
    const data = await request(`/BaseInfo/GetServerpartTree`, {
        method: 'GET',
        params
    })

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

    return data.Result_Data;
}




// 删除账户
export async function handleDeleteUSER(params: any) {
    const data = await request(`/Platform/DeleteUSER`, {
        method: 'GET',
        params
    })

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

    return data;
}


//   用户行为记录
export async function handleSynchroBEHAVIORRECORD(params: any) {
    const data = await request(`/Platform/SynchroBEHAVIORRECORD`, {
        method: 'POST',
        data: params
    })

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

    return data;
}