/**
 * 上传接口
 * @author Seven
 * @data 2025-3-1
 * @param {
 *    filePath:'文件路径'
 *    formData：二进制
 * }
 * @returns {  }
 * @seehttps://mall.gpxscs.cn/mobile/shop/oss/upload
 */

import http from "../utils/http";
import config from "../config/config";

export function UploadFilePromise(filePath, formData) {
  let ukey = uni.getStorageSync("ukey");
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      // 完整上传路径 H5端需要解决跨域问题
      url: "https://mall.gpxscs.cn/mobile/shop/oss/upload",
      method: "POST",
      filePath: filePath,
      name: "upfile",
      formData: { perm_key: ukey, ...formData },
      success: (res) => {
        const result = JSON.parse(res.data);
        resolve(result);
      },
      fail: (res) => {
        reject(res);
      },
    });
  });
}

export function batchNoApi(filePath, file, type) {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: "https://mall.gpxscs.cn/mobile/shop/lakala/tk/uploadOcrImg",
      method: "POST",
      filePath,
      name: "upfile",
      formData: {
        imgType: type,
      },
      success: (res) => {
        if (res?.data) {
          resolve(JSON.parse(res?.data)?.data);
        }
      },
      fail: (res) => {
        reject(res);
      },
    });
  });
}

export function imgOcrResultApi(data) {
  return http({
    url: "/shop/lakala/tk/imgOcrResult",
    method: "POST",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
    },
    data,
  });
}
