"use strict";
const common_vendor = require("../../common/vendor.js");
const config_user = require("../../config/user.js");
const config_url = require("../../config/url.js");
const _sfc_main = {
  data() {
    return {
      orderId: "",
      orderInfo: {
        orderNo: "",
        deviceNo: "",
        usedTime: "",
        currentFee: "0.00",
        deposit: "99.00",
        refundAmount: "99.00",
        endTime: "",
        withdrawStatus: "waiting",
        isWithdrawn: false
      }
    };
  },
  onLoad(options) {
    if (options && options.orderId) {
      this.orderId = options.orderId;
      this.loadOrderInfo();
    } else {
      common_vendor.index.showToast({
        title: "订单ID不能为空",
        icon: "none"
      });
      setTimeout(() => {
        this.goToHome();
      }, 1500);
    }
  },
  methods: {
    // 获取退款状态文本
    getWithdrawStatusText() {
      const statusMap = {
        "waiting": "待申请",
        "processing": "处理中",
        "success": "已退款",
        "failed": "退款失败"
      };
      return statusMap[this.orderInfo.withdrawStatus] || "待申请";
    },
    // 加载订单信息
    async loadOrderInfo() {
      try {
        common_vendor.index.showLoading({ title: "加载中" });
        const result = await config_user.queryById(this.orderId);
        if (result.code === 200 && result.data) {
          const orderData = result.data;
          let packageMinutes = 60;
          let extraMinutes = 0;
          let usedMinutes = 0;
          let packagePrice = "0.00";
          let extraFee = "0.00";
          if (orderData.remark) {
            try {
              const remarkInfo = orderData.remark;
              const usedTimeMatch = remarkInfo.match(/使用时长:(\d+)分钟/);
              if (usedTimeMatch && usedTimeMatch[1]) {
                usedMinutes = parseInt(usedTimeMatch[1]);
              }
              const packageTimeMatch = remarkInfo.match(/套餐时长:(\d+)分钟/);
              if (packageTimeMatch && packageTimeMatch[1]) {
                packageMinutes = parseInt(packageTimeMatch[1]);
              }
              const extraTimeMatch = remarkInfo.match(/超出时长:(\d+)分钟/);
              if (extraTimeMatch && extraTimeMatch[1]) {
                extraMinutes = parseInt(extraTimeMatch[1]);
              }
              const packagePriceMatch = remarkInfo.match(/套餐费用:([\d.]+)元/);
              if (packagePriceMatch && packagePriceMatch[1]) {
                packagePrice = packagePriceMatch[1];
              }
              const extraFeeMatch = remarkInfo.match(/超时费用:([\d.]+)元/);
              if (extraFeeMatch && extraFeeMatch[1]) {
                extraFee = extraFeeMatch[1];
              }
              common_vendor.index.__f__("log", "at pages/order/return-success.vue:186", "从remark解析到的信息:", {
                usedMinutes,
                packageMinutes,
                extraMinutes,
                packagePrice,
                extraFee
              });
            } catch (e) {
              common_vendor.index.__f__("error", "at pages/order/return-success.vue:194", "解析remark字段失败:", e);
            }
          }
          this.orderInfo = {
            orderNo: orderData.orderNo || "",
            deviceNo: orderData.deviceNo || "",
            usedTime: usedMinutes + "分钟",
            packageTime: packageMinutes + "分钟",
            extraTime: extraMinutes + "分钟",
            packagePrice,
            extraFee,
            currentFee: orderData.actualDeviceAmount || "0.00",
            deposit: orderData.depositAmount || "99.00",
            refundAmount: orderData.residueAmount || "99.00",
            endTime: orderData.endTime || "",
            withdrawStatus: orderData.withdrawStatus || "waiting",
            isWithdrawn: orderData.withdrawStatus === "success"
          };
        } else {
          throw new Error(result.msg || "获取订单信息失败");
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/order/return-success.vue:217", "加载订单信息错误:", error);
        common_vendor.index.showToast({
          title: error.message || "获取订单信息失败",
          icon: "none"
        });
      } finally {
        common_vendor.index.hideLoading();
      }
    },
    // 申请退款
    async handleWithdraw() {
      try {
        common_vendor.index.showLoading({ title: "处理中" });
        const res = await common_vendor.index.request({
          url: `${config_url.URL || "http://127.0.0.1:8080"}/app/withdraw/add/${this.orderInfo.orderNo}`,
          method: "GET",
          header: {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + common_vendor.index.getStorageSync("token"),
            "Clientid": common_vendor.index.getStorageSync("client_id")
          }
        });
        if (res.statusCode === 200 && res.data.code === 200) {
          common_vendor.index.showToast({
            title: "退款申请成功",
            icon: "success"
          });
          this.orderInfo.withdrawStatus = "processing";
          this.orderInfo.isWithdrawn = true;
          setTimeout(() => {
            this.loadOrderInfo();
          }, 1500);
        } else {
          throw new Error(res.data.msg || "退款申请失败");
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/order/return-success.vue:260", "退款申请错误:", error);
        common_vendor.index.showToast({
          title: error.message || "退款申请失败",
          icon: "none"
        });
      } finally {
        common_vendor.index.hideLoading();
      }
    },
    // 返回首页
    goToHome() {
      common_vendor.index.reLaunch({
        url: "/pages/index/index"
      });
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: common_vendor.t($data.orderInfo.orderNo || "-"),
    b: common_vendor.t($data.orderInfo.deviceNo || "-"),
    c: common_vendor.t($data.orderInfo.usedTime || "-"),
    d: common_vendor.t($data.orderInfo.packageTime || "1小时"),
    e: common_vendor.t($data.orderInfo.extraTime || "0分钟"),
    f: common_vendor.t($data.orderInfo.endTime || "-"),
    g: common_vendor.t($data.orderInfo.packagePrice || "0.00"),
    h: common_vendor.t($data.orderInfo.extraFee || "0.00"),
    i: common_vendor.t($data.orderInfo.currentFee || "0.00"),
    j: common_vendor.t($data.orderInfo.deposit || "99.00"),
    k: common_vendor.t($data.orderInfo.refundAmount || "99.00"),
    l: common_vendor.t($options.getWithdrawStatusText()),
    m: common_vendor.n($data.orderInfo.withdrawStatus || "waiting"),
    n: !$data.orderInfo.isWithdrawn && $data.orderInfo.refundAmount > 0
  }, !$data.orderInfo.isWithdrawn && $data.orderInfo.refundAmount > 0 ? {
    o: common_vendor.o((...args) => $options.handleWithdraw && $options.handleWithdraw(...args))
  } : {}, {
    p: common_vendor.o((...args) => $options.goToHome && $options.goToHome(...args))
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-eb1f1ee2"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/return-success.js.map
