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.
180 lines
3.9 KiB
180 lines
3.9 KiB
// pages/order/coupon/index.js
|
|
import commonApi from "../../../utils/https/common";
|
|
import util from "../../../utils/util";
|
|
let app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
noUseList: [],
|
|
list:[],
|
|
moreFlag:true,
|
|
|
|
productList: [],
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
console.log(app.globalData.postProduct,app.globalData.list,app.globalData.product)
|
|
let sourceFrom = options.sourceFrom
|
|
let postList = app.globalData.postProduct || []
|
|
let ticketList = app.globalData.list || []
|
|
let signleProduct = app.globalData.product || null
|
|
|
|
let listData = []
|
|
// 门票类
|
|
if (sourceFrom == 'cart') {
|
|
ticketList.forEach(v=>{
|
|
listData.push({
|
|
sku_id: v.sku.id,
|
|
price: v.sku.price,
|
|
sell_price: v.sku.price,
|
|
num: v.num,
|
|
use_date: v.time&&v.time.sale_date?v.time.sale_date:''
|
|
})
|
|
})
|
|
} else {
|
|
if (signleProduct) {
|
|
listData.push({
|
|
sku_id: signleProduct.sku.id,
|
|
price: signleProduct.sku.price,
|
|
sell_price: signleProduct.sku.price,
|
|
num: signleProduct.productNum,
|
|
use_date: signleProduct.date&&signleProduct.date.date?signleProduct.date.date:''
|
|
})
|
|
}
|
|
}
|
|
// 特产类
|
|
postList.forEach(v=>{
|
|
listData.push({
|
|
sku_id: v.sku.id,
|
|
price: v.sku.price,
|
|
sell_price: v.sku.price,
|
|
num: v.productNum,
|
|
})
|
|
})
|
|
|
|
this.setData({
|
|
productList: listData
|
|
})
|
|
this.getList(options)
|
|
},
|
|
getList:function(options){
|
|
if(!this.data.moreFlag) return
|
|
commonApi.user_post('coupon/use_coupon_listv3',{
|
|
money:options.money,
|
|
sku_ids:options.sku,
|
|
cart_data: this.data.productList
|
|
}).then(res=>{
|
|
res.data.map(item=>{
|
|
item.selected = false;
|
|
})
|
|
|
|
|
|
this.setData({
|
|
list:res.data.filter(x=>x.can_use),
|
|
noUseList: res.data.filter(x=>!x.can_use),
|
|
})
|
|
this.getMaxC(options)
|
|
})
|
|
},
|
|
//获取最高优惠
|
|
getMaxC(options){
|
|
commonApi.user_post('coupon/use_max_coupon_listv2',{
|
|
money:options.money,
|
|
sku_ids:options.sku,
|
|
cart_data: this.data.productList
|
|
}).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 () {
|
|
}
|
|
})
|