/*
 * @Author: cclu
 * @Date: 2021-12-13 11:01:23
 * @LastEditors: zzy
 * @LastEditTime: 2022-05-07 17:34:31
 * @FilePath: \cloud-platform\src\pages\Setting\Roles\service.ts
 * @Description: 系统角色相关接口
 *
 * Copyright (c) 2022 by cclu/杭州驿商科技, All Rights Reserved.
 */
import request from '@/utils/request';
import { wrapTreeNode, tableList } from '@/utils/format';
import type { SystemRoleModel } from './data';

// 获取列表数据
export async function getRoleList(params?: any) {
    const data = await request('/FrameWork/GetSystemRoleList', {
        method: 'GET',
        params,
    })

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

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

// 获取系统角色数量
export async function getSystemRoleCount(params?: any) {

    const data = await request('/FrameWork/GetSystemRoleCount', {
        method: 'GET',
        params,
    })

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

    return data.Result_Data;
}

/**
 * @description: 更新角色信息
 * @param {any} params
 * @return {*} 更新通知
 */
export async function updataRole(data?: SystemRoleModel) {

    return request('/Platform/SynchroSystemRole', {
        method: 'POST',
        data,
        // requestType: 'form',
    });
}
// 新的同步
export async function newUpdataRole(data?: SystemRoleModel) {

    return request('/Platform/SynchroSYSTEMROLE', {
        method: 'POST',
        data,
        // requestType: 'form',
    });
}
/* 删除角色 */
export async function deleteRole(systemRoleId: number) {

    return request(`/Platform/Deletesystemrole?systemRoleId=${systemRoleId}`, {
        method: 'POST',
        requestType: 'form',
    });
}

// 获取角色权限树
export async function getSystemMenuTree(SystemRoleId?: string) {

    const data = await request(`/FrameWork/GetSystemRoleModuleTree?SystemRoleId=${SystemRoleId || ''}`, {
        method: 'GET',
    });
    if (data.Result_Code !== 100) {
        return []
    }

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

// 获取角色数据详情
export async function getSystemRoleDetail(SystemRoleId: number) {
    const data = await request(`/Platform/GetSystemRoleDetail?SystemRoleId=${SystemRoleId}`, {
        method: 'GET',
    })

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

    return data.Result_Data
}

// 业主看板的权限
export async function handleAnalysisPermission(params?: any){
  const data = await request('/FrameWork/AuthorAnalysis', {
    method: 'GET',
    params,
  })

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

  return data.Result_Data;
}

// 获得供应商列表
export async function handleSupplierList(params?: any){
  const data = await request('/Seller/GetSupplierDDL', {
    method: 'GET',
    params,
  })

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


// 同步用户角色权限表
export async function handleSynchroUserSystemRoleDetailList(params?: any){
  const data = await request('/FrameWork/StorageUserSystemRoleList', {
    method: 'POST',
    data: params,
  })

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


// 获得用户列表
export async function handleGetUserList(params?: any){
  const data = await request('/Platform/GetUserList', {
    method: 'POST',
    data: params,
  })

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


// 获得角色详情
export async function handleGetSYSTEMROLEDetail(params?: any){
  const data = await request('/Platform/GetSYSTEMROLEDetail', {
    method: 'GET',
    params,
  })

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