139 lines
2.8 KiB
JavaScript
139 lines
2.8 KiB
JavaScript
// user/couponExchange/couponExchange.js
|
|
const app = getApp();
|
|
const regeneratorRuntime = app.loadAsync()
|
|
const util = app.loadUtils("util")
|
|
const model = app.loadModel("index")
|
|
const http = app.loadHttp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
system: app.globalData.system, //设备相关信息
|
|
pageTitle: "使用优惠券", //头部标题
|
|
isBack: true,//显示返回
|
|
isLoading: true,//加载显示关闭
|
|
page: 1,//当前页
|
|
isPage: false,//数据不足10条时变为true
|
|
couponList: [],//优惠券列表
|
|
isTips: false,//领取优惠券弹窗
|
|
changeCoupon: {},//当前选择并换的优惠券信息
|
|
userInfo: {},//个人信息
|
|
},
|
|
// 获取用户信息
|
|
userInfo() {
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo
|
|
})
|
|
},
|
|
// 积分兑换卡券列表
|
|
async exchangeCList() {
|
|
let data = {
|
|
page: this.data.page,
|
|
limit: 10
|
|
}
|
|
let res = await http.http.request1({ url: `${http.api.exchangeCList}`, method: 'POST', data: data })
|
|
let rel = res.data.data.list
|
|
let couponList = this.data.couponList
|
|
if (rel.length < 10) {
|
|
this.setData({
|
|
isPage: true
|
|
})
|
|
}
|
|
this.setData({
|
|
couponList: [...couponList, ...rel],
|
|
isLoading: false
|
|
})
|
|
},
|
|
// 兑换
|
|
async confirmSub() {
|
|
let res = await http.http.request2({ url: `${http.api.jfExchange}`, method: 'POST', data: { card_id: this.data.changeCoupon.id } })
|
|
if (res.data.status == 1) {
|
|
this.closeTips1()
|
|
wx.showToast({
|
|
title: '兑换成功',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
}
|
|
},
|
|
// 打开弹窗
|
|
openTips1(e) {
|
|
let item = e.currentTarget.dataset.item
|
|
this.setData({
|
|
isTips: true,
|
|
changeCoupon: item
|
|
})
|
|
},
|
|
// 关闭弹窗
|
|
closeTips1() {
|
|
this.setData({
|
|
isTips: false
|
|
})
|
|
},
|
|
goUrl(e) {
|
|
let url = e.currentTarget.dataset.url
|
|
wx.navigateTo({
|
|
url: url
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.exchangeCList()
|
|
this.userInfo()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
if (!this.data.isPage) {
|
|
this.exchangeCList()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |