"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const config_user = require("../../config/user.js");
const _sfc_main = {
  __name: "details",
  setup(__props) {
    const orderId = common_vendor.ref("");
    const orderInfo = common_vendor.ref({});
    const orderStatusText = common_vendor.computed(() => {
      const status = orderInfo.value.orderStatus;
      switch (status) {
        case "waiting_for_payment":
          return "待支付";
        case "in_used":
          return "使用中";
        case "used_done":
          return "已完成";
        case "order_cancelled":
          return "已取消";
        default:
          return "使用中";
      }
    });
    common_vendor.onLoad(async (options) => {
      if (options && options.orderId) {
        orderId.value = options.orderId;
        await loadOrderDetails();
      } else {
        common_vendor.index.showToast({
          title: "订单信息不存在",
          icon: "none"
        });
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1500);
      }
    });
    const loadOrderDetails = async () => {
      try {
        common_vendor.index.showLoading({ title: "加载中" });
        const res = await config_user.queryById(orderId.value);
        if (res.code === 200 && res.data) {
          orderInfo.value = res.data;
          if (orderInfo.value.createTime) {
            orderInfo.value.createTime = formatDateTime(new Date(orderInfo.value.createTime));
          }
          if (orderInfo.value.startTime) {
            orderInfo.value.startTime = formatDateTime(new Date(orderInfo.value.startTime));
          }
          if (orderInfo.value.endTime) {
            orderInfo.value.endTime = formatDateTime(new Date(orderInfo.value.endTime));
          }
        } else {
          throw new Error("获取订单详情失败");
        }
        common_vendor.index.hideLoading();
      } catch (error) {
        common_vendor.index.hideLoading();
        common_vendor.index.showToast({
          title: error.message || "获取订单详情失败",
          icon: "none"
        });
      }
    };
    const formatDateTime = (date) => {
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, "0");
      const day = date.getDate().toString().padStart(2, "0");
      const hour = date.getHours().toString().padStart(2, "0");
      const minute = date.getMinutes().toString().padStart(2, "0");
      return `${year}-${month}-${day} ${hour}:${minute}`;
    };
    const formatTime = (minutes) => {
      if (!minutes)
        return "";
      const mins = parseInt(minutes);
      if (mins < 60) {
        return `${mins}分钟`;
      } else {
        const hours = Math.floor(mins / 60);
        const remainingMins = mins % 60;
        return remainingMins > 0 ? `${hours}小时${remainingMins}分钟` : `${hours}小时`;
      }
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(orderStatusText.value),
        b: common_vendor.t(orderInfo.value.orderNo || "-"),
        c: common_vendor.t(orderInfo.value.deviceNo || "-"),
        d: orderInfo.value.payWay === "wx_score_pay"
      }, orderInfo.value.payWay === "wx_score_pay" ? {
        e: common_assets._imports_0$3
      } : {}, {
        f: common_vendor.t(orderInfo.value.startTime || "-"),
        g: orderInfo.value.endTime
      }, orderInfo.value.endTime ? {
        h: common_vendor.t(orderInfo.value.endTime)
      } : {}, {
        i: orderInfo.value.phone
      }, orderInfo.value.phone ? {
        j: common_vendor.t(orderInfo.value.phone)
      } : {}, {
        k: orderInfo.value.depositAmount
      }, orderInfo.value.depositAmount ? {
        l: common_vendor.t(orderInfo.value.depositAmount)
      } : {}, {
        m: orderInfo.value.packageTime && orderInfo.value.packagePrice
      }, orderInfo.value.packageTime && orderInfo.value.packagePrice ? {
        n: common_vendor.t(orderInfo.value.packagePrice),
        o: common_vendor.t(formatTime(orderInfo.value.packageTime))
      } : {}, {
        p: common_vendor.t(orderInfo.value.payAmount || 0)
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2b5cbeae"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/details.js.map
