/*
 * @Author: cclu
 * @Date: 2022-04-28 10:47:35
 * @LastEditTime: 2024-09-03 09:53:08
 * @LastEditors: cclu 1106109051@qq.com
 * @Description: 门店管理模块调用的接口
 * @FilePath: \cloud-platform\src\pages\basicManage\ServerpartShop\service.ts
 */
import { tableList } from '@/utils/format';
import request from '@/utils/request';
// import requestCode from '@/utils/requestCode'
import type { ServerpartShopModel } from './data';

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

  const data = await request(`/BaseInfo/GetServerpartShopList`, {
    method: 'POST',
    data: {
      SearchParameter: { ...params }, keyWord: params?.keyWord,
      PageIndex: params?.current, pagesize: params?.pageSize,
      SortStr: params?.SortStr, ShowWholePower: params?.ShowWholePower
    },
  });

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

  return tableList(data.Result_Data);
}
// 获取明细【门店】
export async function getDetail(serverpartshopId: number) {
  const data = await request(`/BaseInfo/GetSERVERPARTSHOPDetail?serverpartshopId=${serverpartshopId}`, {
    method: 'GET',
  });
  if (data.Result_Code !== 100) {
    return data.Result_Desc
  }
  return data.Result_Data;
}

// 获取门店的图片
export async function getShopImg(params: any) {
  const data = await request(`/BaseInfo/GetBusinessBrandList`, {
    method: 'GET',
    params
  });
  if (data.Result_Code !== 100) {
    return data.Result_Desc
  }
  return data.Result_Data;
}


/* 删除门店 */
export async function delServerpartShop(serverpartShopId: string) {
  return request(
    `/BaseInfo/DeleteServerpartShop?serverpartShopId=${serverpartShopId}`,
    {
      method: 'POST',
      requestType: 'form',
    },
  );
}

/* 更新门店 */
export async function updateServerpartShop(serverpartShop: ServerpartShopModel) {
  return request(`/BaseInfo/SynchroServerpartShop`, {
    method: 'POST',
    data: serverpartShop,
  });
}


// 获取经营门店关联合同项目信息
export async function getShopReceivablesList(params?: any) {
  const data = await request(`/BaseInfo/GetShopReceivables`, {
    method: 'GET',
    params: { ...params, pageindex: params.current }
  });

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

  return tableList(data.Result_Data);
}


// 同步门店
export async function handleSynchroServerpartShop(params?: any) {
  const data = await request(`/BaseInfo/SynchroServerpartShop`, {
    method: 'POST',
    data: params
  });

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

  return data
}

// 获取门店明细
export async function handleGetServerpartShopDetail(params?: any) {
  const data = await request(`/BaseInfo/GetServerpartShopDetail`, {
    method: 'GET',
    params
  });

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

  return data.Result_Data
}

// 删除门店
export async function handleDeleteServerpartShop(params?: any) {
  const data = await request(`/BaseInfo/DeleteServerpartShop`, {
    method: 'GET',
    params
  });

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

  return data
}


// 获取门店经营时间表列表
export async function handleGetRTSERVERPARTSHOPList(params?: any) {
  const data = await request(`/BaseInfo/GetRTSERVERPARTSHOPList`, {
    method: 'POST',
    data: params
  });

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

  return data.Result_Data.List
}




// 同步门店经营时间表
export async function handleSynchroRTSERVERPARTSHOP(params?: any) {
  const data = await request(`/BaseInfo/SynchroRTSERVERPARTSHOP`, {
    method: 'POST',
    data: params
  });

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

  return data
}