"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const utils_api = require("../../utils/api.js");
const utils_tabParams = require("../../utils/tabParams.js");
if (!Array) {
  const _easycom_wd_status_tip2 = common_vendor.resolveComponent("wd-status-tip");
  const _easycom_wd_tab2 = common_vendor.resolveComponent("wd-tab");
  const _easycom_wd_tabs2 = common_vendor.resolveComponent("wd-tabs");
  const _easycom_uv_qrcode2 = common_vendor.resolveComponent("uv-qrcode");
  const _easycom_wd_popup2 = common_vendor.resolveComponent("wd-popup");
  const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
  (_easycom_wd_status_tip2 + _easycom_wd_tab2 + _easycom_wd_tabs2 + _easycom_uv_qrcode2 + _easycom_wd_popup2 + _easycom_wd_icon2)();
}
const _easycom_wd_status_tip = () => "../../uni_modules/wot-design-uni/components/wd-status-tip/wd-status-tip.js";
const _easycom_wd_tab = () => "../../uni_modules/wot-design-uni/components/wd-tab/wd-tab.js";
const _easycom_wd_tabs = () => "../../uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.js";
const _easycom_uv_qrcode = () => "../../uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.js";
const _easycom_wd_popup = () => "../../uni_modules/wot-design-uni/components/wd-popup/wd-popup.js";
const _easycom_wd_icon = () => "../../uni_modules/wot-design-uni/components/wd-icon/wd-icon.js";
if (!Math) {
  (_easycom_wd_status_tip + _easycom_wd_tab + _easycom_wd_tabs + _easycom_uv_qrcode + _easycom_wd_popup + _easycom_wd_icon)();
}
const _sfc_main = {
  __name: "order",
  setup(__props) {
    const tabParamStore = utils_tabParams.useTabParamStore();
    const userInfo = common_vendor.index.getStorageSync("carUserInfo");
    const paddingTop = common_vendor.ref(0);
    const tabIndex = common_vendor.ref(0);
    const isDialogShow = common_vendor.ref(false);
    const result_state = common_vendor.ref(0);
    const date_state = common_vendor.ref(1);
    const pageSize = common_vendor.ref(6);
    const currentPage = common_vendor.ref(1);
    const total = common_vendor.ref(0);
    const listData = common_vendor.ref([]);
    const ErorderNo = common_vendor.ref("");
    const tabs = common_vendor.ref(["全部", "预约成功", "已乘车", "未乘车", "已取消", "预约失败", "待支付"]);
    const popShow_pay = common_vendor.ref(false);
    const payList = common_vendor.ref([
      {
        text: "微信支付",
        icon: "/static/images/pay/wx.png",
        isCheck: false
      },
      {
        text: "电子交通卡支付",
        icon: "/static/images/pay/card.png",
        isCheck: false
      }
    ]);
    const selectedPay = common_vendor.ref(null);
    const orderNo = common_vendor.ref("");
    const payParams = common_vendor.ref({
      timeStamp: "",
      nonceStr: "",
      signType: "",
      paySign: "",
      appId: "",
      prepay_id: "",
      package: ""
    });
    const getRouteParts = (str) => {
      if (typeof str === "string" && str.length > 0) {
        return str.split("→");
      }
      return [];
    };
    async function getMyData() {
      const res = await utils_api.myRequest({
        url: "/tAppqueryUserBuy.action",
        data: {
          result_state: result_state.value,
          date_state: date_state.value,
          id: userInfo.id,
          rows: pageSize.value,
          page: currentPage.value
        }
      });
      const result = JSON.parse(res.data.data);
      total.value = result.totalCount;
      result.list.forEach((ele) => {
        if (ele.state === 1 && ele.payState === 0) {
          const temLockTime = 5;
          const createTime = ele.createTime.slice(0, 19).replace(/-/g, "/");
          ele.countDownTime = new Date(createTime).getTime() + temLockTime * 60 * 1e3 - (/* @__PURE__ */ new Date()).getTime();
        }
      });
      listData.value = [...listData.value, ...result.list];
      console.log(listData, "ls");
    }
    common_vendor.onMounted(() => {
      console.log(userInfo);
      paddingTop.value = common_vendor.index.getMenuButtonBoundingClientRect().top;
      console.log(paddingTop.value);
      getMyData();
    });
    common_vendor.onShow(() => {
      const type = tabParamStore.type;
      if (type) {
        console.log("接收到type参数11 ：", type);
        tabIndex.value = type;
        result_state.value = type;
        listData.value = [];
        getMyData();
      }
    });
    function scrolltolower() {
      if (listData.value.length < total.value) {
        currentPage.value++;
        getMyData();
      } else {
        common_vendor.index.showToast({
          title: "没有更多数据了",
          icon: "none"
        });
      }
    }
    function handleChange(e) {
      console.log(e);
      result_state.value = e.index;
      listData.value = [];
      currentPage.value = 1;
      total.value = 0;
      getMyData();
    }
    function handleDetail(item) {
      const info = encodeURIComponent(JSON.stringify(item));
      common_vendor.index.navigateTo({
        url: `/pages/orderDetail/orderDetail?info=${info}`
      });
    }
    const handlePay = (item) => {
      popShow_pay.value = true;
      orderNo.value = item.orderNo;
    };
    const handleClose = () => {
      popShow_pay.value = false;
    };
    const togglePay = (item) => {
      payList.value.forEach((pay) => {
        pay.isCheck = false;
      });
      item.isCheck = true;
      selectedPay.value = item;
    };
    const payTime = () => {
      if (!selectedPay.value) {
        common_vendor.index.showModal({
          content: "请选择支付方式"
        });
        return;
      }
      if (selectedPay.value.text == "微信支付") {
        payWei();
      } else if (selectedPay.value.text == "电子交通卡支付")
        ;
    };
    const payWei = async () => {
      const res = await utils_api.myRequest({
        url: "/tAppcontinuePay.action",
        // method: 'POST', // 明确指定请求方法为POST
        data: {
          order_num: orderNo.value
        }
      });
      if (res.code == 200) {
        payParams.value = res.data;
        invokeWechatPay();
      } else {
        common_vendor.index.showToast({ title: res.message });
      }
    };
    const invokeWechatPay = () => {
      common_vendor.index.requestPayment({
        ...payParams.value,
        success: (res) => {
          common_vendor.index.showToast({ title: "支付成功" });
          setTimeout(function() {
            getMyData();
          }, 1e3);
        },
        fail: (err) => {
          common_vendor.index.showToast({ title: "支付失败", icon: "none" });
          console.error("支付失败", err);
        }
      });
    };
    const showQrCodeDialog = (item) => {
      isDialogShow.value = true;
      ErorderNo.value = item.id;
    };
    const tuiPay = async (item) => {
      const res = await utils_api.myRequest({
        url: "/tApprefund.action",
        // method: 'POST', // 明确指定请求方法为POST
        data: {
          order_num: item.orderNo,
          id: item.id
        }
      });
      if (res.code == 200) {
        common_vendor.index.showToast({ title: "退款成功" });
        setTimeout(function() {
          getMyData();
        }, 1e3);
      } else {
        common_vendor.index.showToast({ title: res.message });
      }
    };
    return (_ctx, _cache) => {
      return {
        a: `${paddingTop.value * 2}rpx`,
        b: common_vendor.f(tabs.value, (tab, k0, i0) => {
          return common_vendor.e({
            a: common_vendor.f(listData.value, (item, k1, i1) => {
              return common_vendor.e({
                a: item.payState == 0
              }, item.payState == 0 ? {} : {}, {
                b: item.payState == 2
              }, item.payState == 2 ? {} : {}, {
                c: item.payState == 3
              }, item.payState == 3 ? {} : {}, {
                d: item.payState == 1
              }, item.payState == 1 ? common_vendor.e({
                e: item.byState == 1
              }, item.byState == 1 ? {} : {}, {
                f: item.byState == 2
              }, item.byState == 2 ? {} : {}, {
                g: item.byState == 3
              }, item.byState == 3 ? {} : {}) : {}, {
                h: common_vendor.f(getRouteParts(item.route_end), (item2, index2, i2) => {
                  return {
                    a: common_vendor.t(item2),
                    b: index2 > 0 ? 1 : "",
                    c: index2
                  };
                }),
                i: common_vendor.t(item.payAmount),
                j: common_vendor.t(item.ciDate),
                k: item.payState == 0
              }, item.payState == 0 ? {
                l: common_vendor.o(($event) => handleDetail(item), item.id),
                m: common_vendor.o(($event) => handlePay(item), item.id)
              } : {}, {
                n: item.payState == 3
              }, item.payState == 3 ? {
                o: common_vendor.o(($event) => handleDetail(item), item.id)
              } : {}, {
                p: item.payState == 1
              }, item.payState == 1 ? common_vendor.e({
                q: item.byState == 1
              }, item.byState == 1 ? {
                r: common_vendor.o(($event) => handleDetail(item), item.id)
              } : {}, {
                s: item.byState == 2
              }, item.byState == 2 ? {
                t: common_vendor.o(($event) => handleDetail(item), item.id)
              } : {}, {
                v: item.byState == 3
              }, item.byState == 3 ? {
                w: common_vendor.o(($event) => handleDetail(item), item.id),
                x: common_vendor.o(($event) => showQrCodeDialog(item), item.id)
              } : {}) : {}, {
                y: item.payState == 1 && item.state != 4
              }, item.payState == 1 && item.state != 4 ? common_vendor.e({
                z: item.byState == 3 || item.byState == 1
              }, item.byState == 3 || item.byState == 1 ? {
                A: common_vendor.o(($event) => tuiPay(item), item.id)
              } : {}) : {}, {
                B: item.id
              });
            })
          }, !listData.value.length ? {
            b: "93207a4f-2-" + i0 + "," + ("93207a4f-1-" + i0),
            c: common_vendor.p({
              image: "content",
              tip: "暂无数据"
            })
          } : {}, {
            d: common_vendor.o(scrolltolower, tab),
            e: "93207a4f-1-" + i0 + ",93207a4f-0",
            f: common_vendor.p({
              title: `${tab}`,
              name: tab
            }),
            g: tab
          });
        }),
        c: common_assets._imports_0,
        d: common_assets._imports_1,
        e: !listData.value.length,
        f: common_vendor.o(handleChange),
        g: common_vendor.o(($event) => tabIndex.value = $event),
        h: common_vendor.p({
          ["auto-line-width"]: true,
          ["custom-class"]: "custom_class_tab",
          modelValue: tabIndex.value
        }),
        i: common_vendor.sr("qrcode", "93207a4f-4,93207a4f-3"),
        j: common_vendor.p({
          size: "180",
          value: ErorderNo.value
        }),
        k: common_vendor.o(($event) => isDialogShow.value = false),
        l: common_vendor.o(($event) => isDialogShow.value = $event),
        m: common_vendor.p({
          ["safe-area-inset-bottom"]: true,
          ["close-on-click-modal"]: false,
          modelValue: isDialogShow.value
        }),
        n: common_vendor.p({
          name: "close-bold",
          color: "#ABA6A6",
          size: "22"
        }),
        o: common_vendor.o(handleClose),
        p: common_vendor.f(payList.value, (item, index, i0) => {
          return {
            a: item.icon,
            b: common_vendor.t(item.text),
            c: item.isCheck,
            d: common_vendor.o(($event) => togglePay(item), index),
            e: index
          };
        }),
        q: common_vendor.o(payTime),
        r: common_vendor.o(($event) => popShow_pay.value = $event),
        s: common_vendor.p({
          position: "bottom",
          ["safe-area-inset-bottom"]: true,
          ["close-on-click-modal"]: false,
          modelValue: popShow_pay.value
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-93207a4f"], ["__file", "D:/创海项目/CH2025/约车小程序/yueche_app/pages/order/order.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);
