将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
var t = require("../../utils/login.js");
|
||
|
||
Page({
|
||
data: {
|
||
pic: "https://jm-static.v0750.com/image/dui.jpg",
|
||
tips: "温馨提示:\n1、请在30分钟内完成兑换,超时作废\n2、请在兑换完成后,在本页面点击\"确认兑换\"\n3、兑换成功后,将在3个工作日内发放奖品",
|
||
},
|
||
onLoad() {
|
||
t.request('/miniprogram/coupons', {}, !0).then((res) => {
|
||
if (res.code == 200) {
|
||
this.setData({
|
||
tips: res.data.tips,
|
||
pic: res.data.pic
|
||
})
|
||
}
|
||
})
|
||
},
|
||
|
||
onSubmitToGroup(e) {
|
||
const code = e.detail.value.code
|
||
if (!code) {
|
||
wx.showToast({
|
||
title: '请输入券码',
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
|
||
wx.showLoading({
|
||
title: '兑换中...'
|
||
})
|
||
t.request('/miniprogram/coupons/importDouyin', { code: code }, !0).then((res) => {
|
||
wx.hideLoading()
|
||
if (res.code == 200) {
|
||
wx.showToast({
|
||
title: '兑换成功',
|
||
icon: 'success'
|
||
});
|
||
setTimeout(() => {
|
||
wx.navigateTo({
|
||
url: '/pages/washCodeList/washCodeList'
|
||
})
|
||
})
|
||
} else {
|
||
wx.showToast({
|
||
title: res.message || '兑换失败',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
})
|
||
}
|
||
}) |