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

// 自定义商品类别列表
export async function handleGetServerpartUDTypeTree(params?: any) {

  const data = await request(`/BaseInfo/GetServerpartUDTypeTree`, {
    method: 'GET',
    params
  });

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

export async function handleGetCommodityList(params?: any) {

  const data = await request(`/Commodity/GetCommodityList`, {
    method: 'GET',
    params
  });

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

// 添加或者编辑商品
export async function handleSynchroCOMMODITY(params?: any) {

  const data = await request(`/Commodity/SynchroCOMMODITY`, {
    method: 'POST',
    data: params
  });

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


// 删除关联
export async function handleDeleteRTUDType(params?: any) {

  const data = await request(`/Commodity/DeleteRTUDType`, {
    method: 'POST',
    data: params
  });

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

// 关联自定义类别
export async function handleRelateUDType(params?: any) {

  const data = await request(`/Commodity/RelateUDType`, {
    method: 'POST',
    data: params
  });

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


