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

70 lines
2.4 KiB
JavaScript

var e = getApp(), i = require("../../utils/login.js"), t = require("../../utils/common.js");
Page({
data: {
showLoding: !0,
info: {},
id: ""
},
onLoad: function (t) {
var o = this;
wx.showLoading({
title: ""
}), this.setData({
id: t.id || 1
}), i.pageStart(e).then(function (e) {
o.getList();
});
},
getList: function () {
var o = this;
wx.showLoading({
title: ""
}), i.request('/miniprogram/carwashcoupon/details', {
id: this.data.id
}, !0).then(function (e) {
if (wx.hideLoading(), 200 != e.code) return wx.showModal({
title: "提示",
content: e.message
}), !1;
e.data.starttime = t.changeTimeyear(new Date(1e3 * e.data.starttime)), e.data.deadline = t.changeTimeyear(new Date(1e3 * e.data.deadline)),
o.setData({
info: e.data,
showLoding: !1
}, function () { });
}).catch(function (e) {
wx.hideLoading();
});
},
isSubmit: !1,
received: function () {
if (this.isSubmit) return !1;
var t = this;
this.isSubmit = !0, wx.showLoading(), console.log("received"), i.request('/miniprogram/carwashcoupon/receive', {
id: t.data.id,
token: t.data.info.token
}, !0).then(function (e) {
console.log("receiveddqta", e), wx.hideLoading(), t.isSubmit = !1, console.log("recief"),
wx.showModal({
title: "提示",
content: e.message,
success: function (e) {
e.confirm && wx.redirectTo({
url: "/pages/index/index"
});
}
});
}).catch(function (e) {
wx.hideLoading(), t.isSubmit = !1, console.log("提示提示提示提示", e), 201 == e.code && wx.showModal({
title: "提示",
content: e.message,
success: function (e) {
if (!e.confirm) return console.log("弹窗取消"), !1;
wx.redirectTo({
url: "/pages/index/index"
});
}
});
});
}
});