import http from '../utils/http';

/**
 * 上传文件
 * @author [你的名字]
 * @data [当前日期]
 * @param {File} file - 要上传的文件
 * @param {Object} [params] - 其他可选参数
 * @returns {Promise}
 * @see https://mall.gpxscs.cn/mobile/shop/oss/upload
 */
export function uploadFile(file, params = {}) {
  params.isFilter = true;
  const formData = new FormData();
  formData.append('upfile', file);
  // 如果有其他参数，可以添加到 formData 中
  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      formData.append(key, params[key]);
    }
  }
  return new Promise((resolve, reject) => {
    http({
      url: '/api/mobile/shop/oss/upload',
      method: 'post',
      data: formData,
    })
   .then(res => {
      resolve(res);
    })
   .catch(e => reject(console.warn(e)));
  });
}

export function batchNoApi (file, type){
  const formData = new FormData();
  formData.append('upfile', file);
  formData.append('imgType', type);
  return new Promise((resolve, reject) => {
    http({
      url:'/api/mobile/shop/lakala/tk/uploadOcrImg',
      method: 'post',
      data: formData,
    })
   .then(res => {
      resolve(res);
    })
   .catch(e => reject(console.warn(e)));
  });
}

export function imgOcrResultApi (data){
  return  http({
    url:'/api/mobile/shop/lakala/tk/imgOcrResult',
    method:'POST',
    data,
  })
}
