You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.5 KiB

5 years ago
// pages/order/coupon/index.js
import commonApi from "../../../utils/https/common";
import util from "../../../utils/util";
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
list:[],
4 months ago
moreFlag:true
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
3 years ago
5 years ago
onLoad: function (options) {
this.getList(options)
},
getList:function(options){
if(!this.data.moreFlag) return
4 months ago
commonApi.user_post('coupon/use_coupon_list',{
5 years ago
money:options.money,
4 months ago
sku_ids:options.sku
5 years ago
}).then(res=>{
res.data.map(item=>{
item.selected = false;
})
this.setData({
4 months ago
list:res.data
5 years ago
})
3 years ago
this.getMaxC(options)
})
},
//获取最高优惠
getMaxC(options){
4 months ago
commonApi.user_post('coupon/use_max_coupon_list',{
3 years ago
money:options.money,
4 months ago
sku_ids:options.sku
3 years ago
}).then(res=>{
console.log(app.globalData.couponInfo);
app.globalData.couponInfo?app.globalData.couponInfo:app.globalData.couponInfo= res.data;
let listT = this.data.list
listT.forEach(item => {
if (item.id == app.globalData.couponInfo.id) {
item.selected = true
}
});
this.setData({
list:listT
})
5 years ago
})
},
selectIt:function(e){
wx.showLoading({
title: '加载中'
})
let list = this.data.list,index = e.currentTarget.dataset.index;
list.map((item,i)=>{
if(i!=index) {
item.selected = false;
}
})
list[index].selected = list[index].selected?false:true;
this.setData({
list:list
})
wx.hideLoading()
},
submit:function(){
let list = this.data.list,coupon = null;
list.map(item=>{
if(item.selected){
coupon = item;
3 years ago
item.SubCoupon = true
5 years ago
}
})
3 years ago
if (coupon===null) {
app.globalData.couponInfo = false
}else{
app.globalData.couponInfo = coupon;
}
5 years ago
util.back()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
3 years ago
5 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})