"use strict";
const common_vendor = require("../../../common/vendor.js");
const config_user = require("../../../config/user.js");
const _sfc_main = {
  data() {
    return {};
  },
  async onLoad(option) {
    common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:29", "bagCheck onLoad option:", option);
    try {
      common_vendor.index.showLoading({
        title: "处理中...",
        mask: true
      });
      if (!option || !option.deviceNo) {
        throw new Error("未识别到设备编号");
      }
      const deviceNo = option.deviceNo;
      const statusesToCheck = ["in_used", "waiting_for_payment"];
      const res = await config_user.checkOrdersByStatus(deviceNo, statusesToCheck);
      if (res.code === 200 && res.data && res.data.length > 0) {
        const latestOrder = res.data[0];
        if (latestOrder.orderStatus === "in_used") {
          common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:53", "检测到使用中订单，跳转归还页:", latestOrder.orderId);
          common_vendor.index.redirectTo({
            url: `/pages/device/return?orderId=${latestOrder.orderId}`
          });
        } else if (latestOrder.orderStatus === "waiting_for_payment") {
          common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:59", "检测到待支付订单，跳转支付页:", latestOrder.orderId);
          const packageTimeMinutes = latestOrder.packageTime || 60;
          const packageTimeHours = (packageTimeMinutes / 60).toFixed(1);
          const packagePrice = latestOrder.packagePrice || "0.00";
          const hourlyRate = (parseFloat(packagePrice) / (packageTimeMinutes / 60)).toFixed(2);
          const depositAmount = latestOrder.depositAmount || "99.00";
          const totalAmount = (parseFloat(depositAmount) + parseFloat(packagePrice)).toFixed(2);
          common_vendor.index.redirectTo({
            url: `/pages/order/payment?orderId=${latestOrder.orderId}&packageTimeHours=${packageTimeHours}&packagePrice=${packagePrice}&hourlyRate=${hourlyRate}&totalAmount=${totalAmount}&depositAmount=${depositAmount}`
          });
        } else {
          common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:84", "检测到其他状态订单，跳转详情页:", latestOrder.orderId);
          common_vendor.index.redirectTo({
            url: `/pages/device/detail?deviceNo=${deviceNo}`
          });
        }
      } else {
        common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:91", "未检测到相关订单，跳转详情页");
        common_vendor.index.redirectTo({
          url: `/pages/device/detail?deviceNo=${deviceNo}`
        });
      }
    } catch (error) {
      if (error.message && (error.message.includes("未识别到设备编号") || error.message.includes("网络请求失败") || error.message.includes("服务器错误"))) {
        common_vendor.index.__f__("error", "at pages/serve/bagCheck/index.vue:103", "扫码检查订单失败:", error);
        common_vendor.index.showToast({
          title: error.message || "处理失败，请稍后重试",
          icon: "none",
          duration: 2e3
        });
      } else {
        common_vendor.index.__f__("log", "at pages/serve/bagCheck/index.vue:111", "没有找到符合条件的订单或发生其他错误，直接跳转详情页");
      }
      setTimeout(() => {
        if (option && option.deviceNo) {
          common_vendor.index.redirectTo({
            url: `/pages/device/detail?deviceNo=${option.deviceNo}`
          });
        } else {
          common_vendor.index.switchTab({ url: "/pages/index/index" });
        }
      }, 2e3);
    } finally {
      common_vendor.index.hideLoading();
    }
  },
  methods: {}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/serve/bagCheck/index.js.map
