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
130 lines
2.5 KiB
// pages/order/coupon/index.js
|
|
import commonApi from "../../../utils/https/common";
|
|
import util from "../../../utils/util";
|
|
let app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
list:[],
|
|
moreFlag:true
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
this.getList(options)
|
|
},
|
|
getList:function(options){
|
|
if(!this.data.moreFlag) return
|
|
commonApi.user_post('coupon/use_coupon_list',{
|
|
money:options.money,
|
|
sku_ids:options.sku
|
|
}).then(res=>{
|
|
res.data.map(item=>{
|
|
item.selected = false;
|
|
})
|
|
this.setData({
|
|
list:res.data
|
|
})
|
|
this.getMaxC(options)
|
|
})
|
|
},
|
|
//获取最高优惠
|
|
getMaxC(options){
|
|
commonApi.user_post('coupon/use_max_coupon_list',{
|
|
money:options.money,
|
|
sku_ids:options.sku
|
|
}).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
|
|
})
|
|
})
|
|
},
|
|
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;
|
|
item.SubCoupon = true
|
|
}
|
|
})
|
|
if (coupon===null) {
|
|
app.globalData.couponInfo = false
|
|
}else{
|
|
app.globalData.couponInfo = coupon;
|
|
}
|
|
|
|
util.back()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
}
|
|
})
|