Files
kuaiying_wx/pages/vip_recharge/vip_recharge.js
2025-08-15 10:49:43 +08:00

177 lines
5.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var e = getApp();
Page({
data: {
isVip: false,
startTime: "--",
endTime: "--",
selectedType: null,
cards: [],
isQuota: false,
show: true, // 默认显示,前端判断
isIOS: false, // 是否为 iOS 系统
showQrcodePopup: false, // 新增:二维码弹窗显示状态
},
onLoad: function (e) {
const that = this;
// 前端判断系统类型
const systemInfo = wx.getSystemInfoSync();
const isIOS = systemInfo.system.toLowerCase().indexOf('ios') !== -1;
this.setData({ isIOS });
if (isIOS) {
// iOS弹二维码弹窗
this.setData({ showQrcodePopup: true, show: false });
return;
}
// 非 iOS 系统,继续加载页面逻辑
var t = wx.getStorageSync("cards").filter(function (t) {
return t.is_quota === JSON.parse(e.isQuota || "false");
});
console.log("renderCards", t);
this.setData({
cards: t,
isQuota: JSON.parse(e.isQuota || "false"),
});
},
onRecharge: function (e) {
this.setData({
selectedType: e.currentTarget.dataset.type,
});
},
// open_button: function (e) {
// // 如果是 iOS弹出提示框备用逻辑
// if (this.data.isIOS) {
// wx.showModal({
// title: "提示",
// content: "iOS 暂时无法使用此功能,请稍后再试。",
// showCancel: false,
// confirmText: "知道了",
// });
// return;
// }
// // 非 iOS 正常跳转到支付小程序
// var t = e.currentTarget.dataset.type,
// n = e.currentTarget.dataset.price;
// this.setData({
// selectedType: t,
// }),
// console.log(t, n),
// wx.navigateToMiniProgram({
// appId: "wxbe54dfa3311e0443",
// path: "pages/payment/payment?type="
// .concat(t, "&externalOpenid=")
// .concat(wx.getStorageSync("openid"), "&total_fee=")
// .concat(n, "&transaction_type=member&isDebug=false"),
// envVersion: "release",
// success: function (e) {
// console.log("跳转到支付小程序成功", e);
// },
// fail: function (e) {
// console.error("跳转到支付小程序失败", e);
// },
// });
// },
open_button: function(t) {
var n = t.currentTarget.dataset.type, o = t.currentTarget.dataset.price;
this.setData({
selectedType: n
}), console.log(t), e.apiRequest({
url: "/myapp/wx_pay/",
method: "POST",
data: {
type: n,
openid: wx.getStorageSync("openid"),
total_fee: o,
transaction_type: "member"
},
success: function(t) {
console.log(t), t.data && t.data.paySign ? wx.requestPayment({
timeStamp: t.data.timeStamp,
nonceStr: t.data.nonceStr,
package: t.data.package,
signType: "RSA",
paySign: t.data.paySign,
success: function(t) {
e.getinfo().then(function() {
console.log(wx.getStorageSync("cards")), wx.navigateBack({
delta: 1,
success: function(e) {
console.log("返回上一页成功");
}
});
}).catch(function(e) {
console.error("An error occurred:", e);
}), console.log(t), wx.showToast({
title: "支付成功",
icon: "success"
});
},
fail: function(e) {
wx.showToast({
title: "支付失败",
icon: "error"
});
}
}) : wx.showToast({
title: "创建订单失败",
icon: "error"
});
}
});
},
onReady: function () {},
onShow: function () {
var t = this;
e.getUserInfo()
.then(function () {
t.setData({
isVip: wx.getStorageSync("isMember"),
startTime: t.formatEndTime(wx.getStorageSync("startTime")),
endTime: t.formatEndTime(wx.getStorageSync("endTime")),
});
})
.catch(function (e) {
console.error("获取用户信息失败:", e);
})
.finally(function () {
console.log("getUserInfo调用完成");
});
//
},
formatEndTime: function(e) {
// 将秒时间戳转换为毫秒时间戳
var date = new Date(e * 1000);
// 格式化为"YYYY年MM月DD日"
var year = date.getFullYear();
var month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从 0 开始,需要 +1
var day = String(date.getDate()).padStart(2, "0");
var formattedDate = `${year}-${month}-${day}`;
return formattedDate
},
onHide: function () {},
onUnload: function () {},
onPullDownRefresh: function () {},
onReachBottom: function () {},
onShareAppMessage: function () {},
// 关闭二维码弹窗
closeQrcodePopup: function() {
this.setData({ showQrcodePopup: false });
wx.navigateBack(); // 返回上一页
},
// 阻止事件冒泡
preventDefault: function(e) {
// 阻止点击弹窗内容时触发关闭
}
});