import { request } from '@/service/request';

/**
 * 统一上传文件
 * @param data
 * @returns
 */
export function fetchUpload(data: File, config?: any) {
  const formData = new FormData();
  formData.append('file', data);
  return request({
    url: '/smqjh-system/api/v1/files',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    ...config
  });
}

/**
 * 下载模板
 * @returns
 */
export function downloadTemplate() {
  return request({
    url: '/smqjh-pms/api/v1/channelProd/template/download',
    method: 'get'
  });
}

/**
 *新增或更新运费模板
 * @param data
 * @returns
 */
export function fetchGetAddOrEditTransport(data: any) {
  return request({
    url: '/smqjh-system/api/v1/transport2/addOrEdit',
    method: 'post',
    data
  });
}

/**
 * 获取验证码
 * @returns
 */
export function fetchGetCaptcha() {
  return request<{ captchaBase64: string; captchaId: string }>({
    url: '/smqjh-auth/api/v1/auth/captcha',
    method: 'get'
  });
}

export function fetchGetLoginUserList() {
  return request({
    url: '/smqjh-system/api/v1/channel/list/LoginUserEnterprise',
    method: 'get'
  });
}

/**
 * 企业ID查询运费模板
 * @param channelId
 * @returns
 */
export function fetchGetTransport(channelId: number) {
  return request<Api.delivery.Transport2>({
    url: `/smqjh-system/api/v1/transport2/queryTransport2ByChannelId/${channelId}`,
    method: 'get'
  });
}

/**
 * 后管端-企业运费列表
 * @returns
 */

export function fetchChannelList(data: any) {
  return request<{ records: Api.delivery.Transport2[] }>({
    url: '/smqjh-system/api/v1/transport2/transport2List',
    method: 'get',
    params: data
  });
}
