import { tableList, wrapTreeNode } from '@/utils/format';
import request from '@/utils/request';
import type { CommodityType } from '../data';

// 获取列表数据
export async function getList(params?: any) {
  const search = params ? { ...params, PageIndex: params.current } : {};
  const data = await request(`/BasicInfo/GetNestingCommodityTypeLsit`, {
    method: 'GET',
    params: search,
  });

  if (data.Result_Code === 500) {
    return [];
  }
  const treeTable = wrapTreeNode(data.Result_Data.List);
  return tableList({ ...data.Result_Data, List: treeTable });
}

export async function delCommdityType(commoditytypeid: number) {
  return request(`/BasicInfo/DeleteCommodityType?commoditytypeid=${commoditytypeid}`, {
    method: 'POST',

    requestType: 'form',
  });
}

export async function updateCommodityType(commodityType: CommodityType) {
  return request(`/BasicInfo/SynchroCommodityType`, {
    method: 'POST',
    data: commodityType,
    requestType: 'form',
  });
}
