/*
 * @Author: zzy 411037547@qq.com
 * @Date: 2022-04-28 10:47:35
 * @LastEditors: cclu 1106109051@qq.com
 * @LastEditTime: 2024-09-14 17:30:59
 * @FilePath: \cloud-platform\src\pages\basicManage\Brand\service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { tableList } from '@/utils/format';
import request from '@/utils/request';
// import requestCode from "@/utils/requestCode";
import type { BrandModel, paramsModel } from './data';

// 获取列表数据
export async function getList(params?: any) {
  const search = params ? {
    SearchParameter: { ...params }, keyWord: params.keyWord,
    PageIndex: params.current, pagesize: params.pageSize, SortStr: params.sortstr
  } : {};
  const data = await request(`/BaseInfo/GetBrandList`, {
    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 getCombineList(params?: any) {
  const data = await request(`/BaseInfo/GetCombineBrandList`, {
    method: 'GET',
    params,
  });

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

  return tableList(data.Result_Data);
}

// 获取详细数据
export async function getBrandDetail(BrandId: any) {
  const data = await request(
    `/BaseInfo/GetBrandDetail?BrandId=${BrandId}`, {
    method: 'GET',
  },
  );

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

  return data.Result_Data;
}

export async function delBrand(Brandid: number) {
  return request(`/BaseInfo/DeleteBrand?Brandid=${Brandid}`, {
    method: 'POST',

    requestType: 'form',
  });
}

export async function updateBrand(Brand: BrandModel) {
  return request(`/BaseInfo/SynchroBrand`, {
    method: 'POST',
    data: Brand,
    requestType: 'form',
  });
}



// 获取商家商品表列表
export async function getCommodityList(params: paramsModel) {
  const data = await request('/Commodity/GetCOMMODITYList', {
    method: 'GET',
    params,
  })

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

// 解析业态名字
export async function getFieldNum(params: any) {
  const data = await request('/BaseInfo/GetBusinessTradeDetail', {
    method: 'GET',
    params,
  })
  if (data.Result_Code !== 100) {
    return {
      data: [],
      current: 1,
      pageSize: 10,
      total: 0,
      success: false
    }
  }
  return data.Result_Data;
}

