JMApp/pages/voucher/voucher.js
XiaoMo 1af84dc1ee refactor: 统一API请求路径并优化请求逻辑
将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
2025-04-10 19:01:02 +08:00

175 lines
5.2 KiB
JavaScript

var t = getApp(), e = require("../../utils/login.js");
Page({
data: {
showLoding: !0,
list: [],
user: {},
page: {
next_page: 1
},
servicetel: "",
edition: 1,
selectItemID: null,
loading: !1,
provision: {},
tips: [],
showTips: !1,
approve: !0
},
onLoad: function (a) {
var i = this;
e.pageStart(t).then(function (e) {
i.getList(), i.setData({
servicetel: t.globalData.servicetel
});
});
},
onShow: function (e) {
t.globalData.isneedUpload && (this.getList(), t.globalData.isneedUpload = !1);
},
onPullDownRefresh: function () {
this.setData({
list: []
}), this.getList();
},
onReachBottom: function () {
this.getList();
},
onShareAppMessage: function () { },
getList: function () {
var a = this;
if (this.data.loading) return !1;
this.setData({
loading: !0
}), wx.showLoading({
title: ""
}), e.request('/miniprogram/recharge', {
page: this.data.page.next_page
}, !0).then(function (t) {
if (wx.hideLoading(), a.setData({
loading: !1
}), 200 != t.code) return wx.showModal({
title: "提示",
content: t.message
}), !1;
a.setData({
showLoding: !1,
list: t.data.list,
user: t.data.user,
protocol: t.data.protocol,
tips: t.data.tips.split("\n")
}, function () { });
}).catch(function (t) {
wx.hideLoading();
});
},
tobuy: function (a) {
var i = a.currentTarget.dataset.id;
wx.showLoading({
title: ""
}), e.request('/miniprogram/recharge/create', {
id: i
}, !0).then(function (t) {
if (wx.hideLoading(), 200 != t.code) return wx.showModal({
title: "提示",
content: t.message
}), !1;
var e = t.data.result;
console.log('tobuy', e, t);
wx.requestPayment({
timeStamp: e.timeStamp,
nonceStr: e.nonceStr,
package: e.package,
signType: e.signType,
paySign: e.paySign,
success: function (t) {
// 加载回调接口
e.request(t.data.notify_url, {
orderid: t.data.orderid
}, !0).then(function (t) {
console.log('pay_success', t);
}).catch(function (t) {
console.log('pay_success', t);
});
getCurrentPages().length > 1 ? wx.navigateBack({}) : wx.redirectTo({
url: "/pages/index/index"
});
}
});
}).catch(function (t) {
wx.hideLoading();
});
},
selectItem: function (t) {
var e = t.currentTarget.dataset.id;
this.setData({
selectItemID: e
});
},
isSubmit: !1,
tobuyNow: function (a) {
if (!this.data.approve) return wx.showToast({
title: "请勾选同意相关条款",
icon: "none"
}), !1;
if (!this.data.selectItemID || this.isSubmit) return wx.showToast({
title: "请选择充值金额~",
icon: "none"
}), !1;
this.isSubmit = !0, wx.showLoading({
title: ""
});
var i = this;
e.request('/miniprogram/recharge/create', {
id: i.data.selectItemID
}, !0).then(function (t) {
if (wx.hideLoading(), i.isSubmit = !1, 200 != t.code) return wx.showModal({
title: "提示",
content: t.message
}), !1;
var r = t.data.result;
wx.requestPayment({
timeStamp: r.timeStamp,
nonceStr: r.nonceStr,
package: r.package,
signType: r.signType,
paySign: r.paySign,
success: function (o) {
if (t.data.notify_url) {
// 加载回调接口
e.request(t.data.notify_url, {
orderid: t.data.orderid
}, !0).then(function (t) {
console.log('pay_success', t);
}).catch(function (t) {
console.log('pay_success', t);
});
}
getCurrentPages().length > 1 ? wx.navigateBack({}) : wx.redirectTo({
url: "/pages/index/index"
});
}
});
}).catch(function (t) {
wx.hideLoading(), i.isSubmit = !1;
});
},
showprovision: function () {
this.setData({
showTips: !this.data.showTips
});
},
change: function (t) {
var e = t.detail.value.length;
this.setData({
approve: 1 == e
});
}
});