import request from '@/utils/request';
import requestEncryption from '@/utils/requestEncryption';
import { wrapTreeNode } from "@/utils/format";

// 获取销售同环比
export async function handleGetCommodityTypeSummary(params: any) {
  const data = await request('/Sales/GetCommodityTypeSummary', {
    method: 'GET',
    params
  })

  if (data.Result_Code !== 100) {
    return {
      data: [],
      otherData: '',
      current: 1,
      pageSize: 20,
      total: 0,
      success: true,
    };
  }

  return data.Result_Data.List
}


// 获取商品类别嵌套树
export async function handleGetNestingCOMMODITYTYPETree(params: any) {
  const data = await request('/BaseInfo/GetNestingCOMMODITYTYPETree', {
    method: 'GET',
    params
  })

  if (data.Result_Code !== 100) {
    return {
      data: [],
      otherData: '',
      current: 1,
      pageSize: 20,
      total: 0,
      success: true,
    };
  }

  return wrapTreeNode(data.Result_Data.List)
}

// 获取商品业态
export async function handleGetBusinessTrades(params: any) {
  const data = await request('/BaseInfo/GetBusinessTrades', {
    method: 'POST',
    params
  })

  return data.Result_Data.List
}


// 拿到建工的全部商品业态
// 获取商品业态
export async function handleGetServerpartShopTrade(params: any) {
  const data = await requestEncryption('/Commodity/GetServerpartShopTrade', {
    method: 'POST',
    data: {
      ...params,
      requestEncryption: true
    }
  })

  return data.Result_Data.List
}