"use strict";
const common_vendor = require("../common/vendor.js");
const BASE_URL = "https://car.meiyishuoo.com/ride-sharing/carBuy";
function myRequest(options) {
  common_vendor.index.showLoading({
    title: "加载中",
    mask: true
  });
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
  options.url += `${options.url.includes("?") ? "&" : "?"}timestamp=${timestamp}`;
  return new Promise((resolve, reject) => {
    common_vendor.index.request({
      url: BASE_URL + options.url,
      method: options.method || "GET",
      data: options.data || {},
      header: options.header || {
        // token: uni.getStorageSync('auth').token || '',
      },
      success: (res) => {
        console.log(res);
        common_vendor.index.hideLoading();
        if (res.data.code === 200) {
          resolve(res.data);
        } else {
          const silentMessages = ["未查询到认证信息"];
          if (!silentMessages.includes(res.data.message) && res.data.code) {
            common_vendor.index.showToast({
              title: res.data.message || "接口报错",
              icon: "none"
            });
            if (res.data.message == "未查到用户信息") {
              common_vendor.index.removeStorageSync("carUserInfo");
            }
          }
        }
      },
      fail: (err) => {
        console.log(err);
        common_vendor.index.hideLoading();
        common_vendor.index.showToast({
          title: "请求数据失败",
          icon: "none"
        });
        reject(err);
      }
    });
  });
}
function myUploadFile(options) {
  common_vendor.index.showLoading({ title: "上传中", mask: true });
  return new Promise((resolve, reject) => {
    common_vendor.index.uploadFile({
      url: BASE_URL + options.url,
      filePath: options.filePath,
      name: options.name,
      formData: options.formData || {},
      header: options.header || {
        // 可添加全局请求头，如 token
        // 'Authorization': uni.getStorageSync('auth').token || ''
      },
      success: (res) => {
        common_vendor.index.hideLoading();
        const data = JSON.parse(res.data);
        if (data.code === 200) {
          resolve(data);
        } else {
          common_vendor.index.showToast({ title: data.message || "上传失败", icon: "none" });
          reject(data);
        }
      },
      fail: (err) => {
        console.log(err);
        common_vendor.index.hideLoading();
        common_vendor.index.showToast({ title: "网络异常", icon: "none" });
        reject(err);
      }
    });
  });
}
exports.myRequest = myRequest;
exports.myUploadFile = myUploadFile;
