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.

135 lines
3.4 KiB

5 years ago
// pages/order/components/coupon/index.js
3 years ago
import commonApi from "../../../../utils/https/common"
5 years ago
let app = getApp()
Component({
/**
* 组件的属性列表
*/
properties: {
money:{
type:String,
value:"0"
},
sku:{
type:String,
value:""
},
couponFlag:{
type:Boolean,
value:false,
observer(nv, ov) {
console.log(nv,ov)
if (nv) {
app.globalData.couponInfo = null
this.setData({
coupon:null
})
}
}
6 months ago
},
sourceFrom: {
type:String,
value:""
},
5 years ago
},
/**
* 组件的初始数据
*/
data: {
coupon:null
},
pageLifetimes: {
show: function() {
3 years ago
this.getMaxCoupon()
5 years ago
}
},
3 years ago
lifetimes:{
attached(){
},
},
5 years ago
/**
* 组件的方法列表
*/
methods: {
setNullCoupon:function(){
3 years ago
app.globalData.couponInfo = null
5 years ago
this.setData({
coupon:null
})
3 years ago
},
getMaxCoupon(){
// console.log(app.globalData.couponInfo);
console.log(this.data.coupon);
if (app.globalData.couponInfo===false) {
this.setData({
coupon:null
})
this.triggerEvent('getNewCoupon',null);
}else{
6 months ago
let postList = app.globalData.postProduct || []
let ticketList = app.globalData.list || []
let signleProduct = app.globalData.product || null
let listData = []
if (this.properties.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:''
})
}
}
6 months ago
postList.forEach(v=>{
listData.push({
sku_id: v.sku.id,
price: v.sku.price,
sell_price: v.sku.price,
num: v.productNum,
})
})
6 months ago
commonApi.user_post('coupon/use_max_coupon_listv2',{
3 years ago
money:this.data.money,
6 months ago
sku_ids:this.data.sku,
cart_data: listData
3 years ago
}).then(res=>{
if (app.globalData.couponInfo&&app.globalData.couponInfo.hasOwnProperty('SubCoupon')) {
this.setData({
coupon:app.globalData.couponInfo
})
this.triggerEvent('getNewCoupon',app.globalData.couponInfo);
console.log("我用的原来的数据");
}else{
console.log("我用的新的数据");
2 years ago
console.log('123123132',res.data);
3 years ago
if ( Object.keys(res.data).length!=0) {
app.globalData.couponInfo = res.data
this.setData({
coupon:res.data
})
console.log(this.data.coupon);
this.triggerEvent('getNewCoupon',res.data);
}
}
})
}
5 years ago
}
3 years ago
},
5 years ago
})