126 lines
2.4 KiB
JavaScript
126 lines
2.4 KiB
JavaScript
// user/couponCard/couponCard.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,//显示返回
|
|
isEnv: true,//红包选中状态
|
|
couponList: [],//数据列表
|
|
total_price: 101,//订单金额
|
|
},
|
|
|
|
// 不使用红包
|
|
async noEnv() {
|
|
this.setData({
|
|
isEnv: !this.data.isEnv
|
|
})
|
|
let coupon = {}
|
|
await model.storage.setStorage("coupon", coupon)
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
},
|
|
// 选中红包
|
|
async selectEnv(e) {
|
|
let item = e.currentTarget.dataset.item
|
|
let coupon = {
|
|
id: item.id,
|
|
price: item.coupon_price
|
|
}
|
|
await model.storage.setStorage("coupon", coupon)
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
},
|
|
// 显示隐藏内容
|
|
isShow(e) {
|
|
let index = e.currentTarget.dataset.index
|
|
let list = this.data.couponList
|
|
list[index].show = !list[index].show
|
|
this.setData({
|
|
couponList: list
|
|
})
|
|
},
|
|
// 获取可用优惠券
|
|
async getCoupon() {
|
|
let res = await http.http.request2({ url: `${http.api.userCoupon}`, method: "POST", data: { total_price: this.data.total_price, status: 1 } })
|
|
let cou = res.data.data
|
|
if (cou.length <= 0) {
|
|
return
|
|
}
|
|
cou.map((v, i) => {
|
|
cou[i].show = true
|
|
cou[i].end_time = util.formatTime(v.end_time, 'Y-M-D h:m:s')
|
|
})
|
|
this.setData({
|
|
couponList: cou
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
total_price:options.total
|
|
})
|
|
this.getCoupon()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |