"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_icon2 = common_vendor.resolveComponent("wd-icon");
  const _easycom_wd_popup2 = common_vendor.resolveComponent("wd-popup");
  (_easycom_wd_icon2 + _easycom_wd_popup2)();
}
const _easycom_wd_icon = () => "../../uni_modules/wot-design-uni/components/wd-icon/wd-icon.js";
const _easycom_wd_popup = () => "../../uni_modules/wot-design-uni/components/wd-popup/wd-popup.js";
if (!Math) {
  (_easycom_wd_icon + _easycom_wd_popup)();
}
const _sfc_main = {
  __name: "pay",
  setup(__props) {
    utils_tabParams.useTabParamStore();
    const userInfo = common_vendor.index.getStorageSync("carUserInfo");
    const paddingTop = common_vendor.ref(0);
    common_vendor.ref(0);
    const popShow_pay = common_vendor.ref(false);
    const chongList = common_vendor.ref([]);
    const pageSize = common_vendor.ref(10);
    const currentPage = common_vendor.ref(1);
    const total = common_vendor.ref(0);
    const totalAmount = common_vendor.ref(0);
    const zengAmount = common_vendor.ref(0);
    const payList = common_vendor.ref([
      {
        text: "微信支付",
        icon: "/static/images/pay/wx.png",
        isCheck: true
      }
      // {
      // 	text: '电子交通卡支付',
      // 	icon: '/static/images/pay/card.png',
      // 	isCheck: false
      // }
    ]);
    const payParams = common_vendor.ref({
      timeStamp: "",
      nonceStr: "",
      signType: "",
      paySign: "",
      appId: "",
      // prepay_id:'',
      package: ""
    });
    const selectedPay = common_vendor.ref(null);
    common_vendor.onMounted(() => {
      console.log(common_vendor.index.getStorageSync("cardTypeNum"), "身份");
      paddingTop.value = common_vendor.index.getMenuButtonBoundingClientRect().top;
      getChongcommon();
    });
    const hadnleChange = (item) => {
      chongList.value.forEach((item2) => {
        item2.isChecked = false;
      });
      item.isChecked = true;
      totalAmount.value = item.account3;
      zengAmount.value = item.account4;
    };
    const jiaotong = async () => {
      const res = await utils_api.myRequest({
        url: "/cardrecharge.action",
        method: "POST",
        // 明确指定请求方法为POST
        data: {
          mobile: userInfo.mobile,
          type: common_vendor.index.getStorageSync("cardTypeNum"),
          account4: totalAmount.value,
          account5: zengAmount.value
        }
      });
      if (res.code == 200) {
        payParams.value = {
          timeStamp: res.data.timeStamp,
          nonceStr: res.data.nonceStr,
          package: "prepay_id=" + res.data.prepay_id,
          signType: res.data.signType,
          paySign: res.data.paySign
        };
        invokeWechatPay();
      }
    };
    const invokeWechatPay = () => {
      console.log(payParams.value, "支付");
      common_vendor.index.requestPayment({
        ...payParams.value,
        success: (res) => {
          common_vendor.index.showToast({ title: "支付成功" });
          popShow_pay.value = false;
          setTimeout(function() {
            common_vendor.index.navigateTo({
              url: "/pages/transportation/transportation"
            });
          }, 1e3);
        },
        fail: (err) => {
          common_vendor.index.showToast({ title: "支付失败", icon: "none" });
          console.error("支付失败", err);
        }
      });
    };
    const getChongcommon = async () => {
      let data = {
        page: currentPage.value,
        rows: pageSize.value
      };
      try {
        const res = await utils_api.myRequest({
          url: "/reBenefitlist.action",
          data
        });
        if (res.code === 200) {
          const formattedRows = res.rows.map((item) => ({
            ...item,
            // 保留原有数据
            isCheck: false
            // 新增 isCheck 参数，默认 false
          }));
          if (currentPage.value === 1) {
            chongList.value = formattedRows;
          } else {
            chongList.value.push(...formattedRows);
          }
          total.value = res.total;
        } else {
          common_vendor.index.showToast({ title: "数据获取失败", icon: "none" });
        }
      } catch (err) {
        console.error("请求异常", err);
        common_vendor.index.showToast({ title: "网络异常", icon: "none" });
      } finally {
      }
    };
    const scrolltolower = () => {
      if (chongList.value.length < total.value) {
        currentPage.value++;
        getChongcommon();
      } else {
        common_vendor.index.showToast({
          title: "没有更多数据了",
          icon: "none"
        });
      }
    };
    const handlePay = () => {
      popShow_pay.value = true;
    };
    const handleClose = () => {
      popShow_pay.value = false;
    };
    const handleBack = () => {
      common_vendor.index.navigateBack();
    };
    const togglePay = (item) => {
      selectedPay.value = true;
    };
    const payTime = () => {
      console.log(123222);
      jiaotong();
    };
    return (_ctx, _cache) => {
      return {
        a: common_assets._imports_0$1,
        b: common_vendor.p({
          name: "thin-arrow-left",
          color: "#001713",
          size: "18"
        }),
        c: common_vendor.o(handleBack),
        d: `${paddingTop.value * 2}rpx`,
        e: common_vendor.f(chongList.value, (item, index, i0) => {
          return common_vendor.e({
            a: common_vendor.t(item.account3),
            b: item.isChecked
          }, item.isChecked ? {
            c: "3a7adb9e-1-" + i0,
            d: common_vendor.p({
              name: "check-bold",
              color: "#fff",
              size: "20"
            }),
            e: common_vendor.o(($event) => item.isChecked != item.isChecked, index)
          } : {}, {
            f: item.isChecked ? 1 : "",
            g: index,
            h: common_vendor.o(($event) => hadnleChange(item), index)
          });
        }),
        f: common_vendor.o(scrolltolower),
        g: common_vendor.t(totalAmount.value),
        h: common_vendor.o(handlePay),
        i: common_vendor.p({
          name: "close-bold",
          color: "#ABA6A6",
          size: "22"
        }),
        j: common_vendor.o(handleClose),
        k: 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(), index),
            e: index
          };
        }),
        l: common_vendor.o(payTime),
        m: common_vendor.o(($event) => popShow_pay.value = $event),
        n: 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-3a7adb9e"], ["__file", "D:/创海项目/CH2025/约车小程序/yueche_app/pages/pay/pay.vue"]]);
wx.createPage(MiniProgramPage);
