/*
 * @Author: cclu
 * @Date: 2022-04-28 10:47:35
 * @LastEditors: cclu 1106109051@qq.com
 * @LastEditTime: 2024-11-08 17:37:00
 * @FilePath: \cloud-platform\src\pages\basicManage\BusinessTrade\service.ts
 * @Description: 经营业态相关接口
 */
import { tableList, wrapTreeNode } from '@/utils/format';
import request from '@/utils/request';
import type { BusinessTradeModel } from './data';

// 获取列表数据
export async function getList(params?: any) {

  const data = await request(`/BaseInfo/GetBusinessTradeTree`, {
    method: 'GET',
    params: { ...params, PageIndex: params?.current||1 },
  });

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

  return tableList({ ...data.Result_Data, List: treeTable });
}

// 获取列表数据
export async function getTradeList(params?: any) {
  const search = params ? {
    SearchParameter: { ...params }, keyWord: params.keyWord,
    PageIndex: params.current, pagesize: params.pageSize, SortStr: params.sortstr
  } : {};
  const data = await request(`/BaseInfo/GetBusinessTradeList`, {
    method: 'POST',
    data: search,
  });

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

  return tableList(data.Result_Data);
}

export async function delBusinessTrade(businessTradeId: number) {
  return request(`/BaseInfo/DeleteBusinessTrade?businessTradeId=${businessTradeId}`, {
    method: 'POST',

    requestType: 'form',
  });
}

export async function updateBusinessTrade(businessTrade: any) {
  return request(`/BaseInfo/SynchroBusinessTrade`, {
    method: 'POST',
    data: businessTrade,
    requestType: 'form',
  });
}
