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.

358 lines
9.7 KiB

5 years ago
// pages/order/post/index.js
let app = getApp()
import commonApi from "../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
product: [],
showPrice: 0,
from: null,
address: null,
postFee: 0,
3 years ago
coupon:app.globalData.couponInfo,
sku_id: '',
kjId: null,
gp_id: null,
prizeId: null,
select_allowance: false,
allowance_data: null,
allowance_price: 0,
showAllowance: false,
flag:null,
2 years ago
isCar:'single',
showYhq:null
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
from: options.from,
kjId: app.globalData.kjId,
gp_id: app.globalData.gp_id || app.globalData.team_id,
prizeId: wx.getStorageSync('prizeId'),
flag:options.flag,
2 years ago
isCar:options.isCar,
showYhq:app.globalData.listName?false:true
5 years ago
})
let price = 0, sku_id = [];
app.globalData.postProduct.map(item => {
if (!app.globalData.kjId && !this.data.gp_id) {
5 years ago
price = price + item.sku.price * item.productNum;
5 years ago
}
else if (this.data.gp_id) {
5 years ago
price = price + item.sku.event_price * item.productNum;
}
5 years ago
sku_id.push(item.sku.id)
})
this.setData({
product: app.globalData.postProduct,
showPrice: app.globalData.kjId ? 0 : price,
sku_id: sku_id.join(",")
5 years ago
})
if (!this.data.kjId && !this.data.gp_id) {
5 years ago
this.couponCom = this.selectAllComponents("#coupon")[0];
}
console.log(this.data.showPrice)
5 years ago
},
2 years ago
price() {
let allPrice
if (this.data.coupon) {
if (this.data.coupon.discount_type == 'pricebreak') {
return allPrice = this.data.showPrice + this.data.postFee - this.data.coupon.activity.money>0?this.data.showPrice + this.data.postFee - this.data.coupon.activity.money/100:0
} else {
return allPrice = (this.data.showPrice* this.data.coupon.activity.fold)/ 10 + this.data.postFee
}
}
},
changeAllowance: function () {
this.setData({
showAllowance: !this.data.showAllowance
})
},
inputRemark: function (e) {
let index = e.currentTarget.dataset.index, product = this.data.product;
5 years ago
product[index].remark = e.detail.value;
this.setData({
product: product
5 years ago
})
},
setAddress: function (e) {
3 years ago
console.log('我触发了');
this.setData({
address: e.detail
})
5 years ago
this.getPostFee()
},
minus: function (e) {
let index = e.currentTarget.dataset.index, product = this.data.product;
5 years ago
let productNum = product[index].productNum;
if (productNum <= 1) return;
5 years ago
product[index].productNum--;
this.setData({
product: product,
coupon: null
5 years ago
})
this.getPostFee()
this.changePrice()
},
add: function (e) {
let index = e.currentTarget.dataset.index, product = this.data.product;
product[index].productNum = product[index].productNum + 1;
5 years ago
this.setData({
product: product,
coupon: null
5 years ago
})
this.getPostFee()
this.changePrice()
},
changePrice: function () {
let product = this.data.product, price = 0;
product.map(item => {
5 years ago
price = price + item.sku.price * item.productNum;
if (this.data.allowance_data && this.data.select_allowance && this.data.allowance_price) {
let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price);
price -= this.data.allowance_price * item.productNum < spread_price ? this.data.allowance_price * item.productNum : spread_price
}
5 years ago
})
if (this.data.coupon && this.data.showPrice != price) {
5 years ago
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
app.globalData.couponInfo = null;
if (!this.data.kjId && !this.data.gp_id) {
5 years ago
this.couponCom.setNullCoupon()
}
5 years ago
this.setData({
coupon: null
5 years ago
})
}
this.setData({
showPrice: app.globalData.kjId ? 0 : price
5 years ago
})
},
order: function () {
if (!this.data.address) {
5 years ago
wx.showToast({
title: '请选择收货地址!',
icon: 'none'
5 years ago
})
return;
}
let product = this.data.product, product_list = [];
product.map(item => {
5 years ago
let productItem = {
type: item.product.type,
product_id: item.product.id,
sku_id: item.sku.id,
post: this.data.address.id,
product_num: item.productNum,
remark: item.remark
5 years ago
}
product_list.push(productItem)
})
let data = {
source: "WECHATXCX",
product_list: product_list,
coupon_id: this.data.coupon ? this.data.coupon.id : null,
originate_order_id: this.data.kjId,
gp_id: app.globalData.gp_id,
team_id: app.globalData.team_id
5 years ago
};
if (this.data.select_allowance) data.is_allowance = 1
if (app.globalData.from) {
5 years ago
data.system_name = app.globalData.from;
}
if (app.globalData.retailId) {
5 years ago
data.commission_code = app.globalData.retailId;
app.globalData.retailId = null;
}
if (this.data.prizeId) {
4 years ago
data.lottery_id = this.data.prizeId
}
if (app.globalData.category_id) {
5 years ago
data.category_id = app.globalData.category_id;
}
4 years ago
console.log(app.globalData.list)
if(!app.globalData.list || app.globalData.list.length == 0){
commonApi.user_post("order/create", {
data: JSON.stringify(data)
}).then(res => {
if (app.globalData.kjId) {
app.globalData.kjId = null;
this.setData({
kjId: null
})
this.onLoad({})
}
app.globalData.gp_id = null;
app.globalData.team_id = null;
this.setData({
gp_id: null
})
this.onLoad({});
})
}else{
app.globalData.productPrice = (this.data.showPrice + this.data.postFee - (this.data.coupon?this.data.coupon.activity.money:0))/100;
app.globalData.createDate = data
4 years ago
console.log(app.globalData.product)
if (!app.globalData.product) {
app.globalData.product = app.globalData.list[0]
}
wx.redirectTo({
url: '/pages/order/scene/index?flag='+this.data.flag+'&isCar='+this.data.isCar,
})
}
5 years ago
},
getPostFee: function () {
if (!this.data.address) return;
let product = this.data.product, list = [], that = this;
product.map(item => {
list.push(commonApi.user_post("order/get_post_price", {
sku_id: item.sku.id,
num: item.productNum,
consignee_id: that.data.address.id
5 years ago
}))
})
// 获取邮费
Promise.all(list).then(res => {
let postFee = 0, flag = true;
res.map((item, index) => {
if (item.data.price < 0) flag = false;
postFee = postFee + Number(item.data.price);
5 years ago
product[index].postFee = item.data.price;
})
if (!flag) {
5 years ago
wx.showToast({
title: '该地区不发货',
icon: 'none'
5 years ago
})
product.map(item => {
5 years ago
item.postFee = 0;
})
postFee = 0;
}
if (this.data.coupon && this.data.postFee != postFee) {
5 years ago
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
app.globalData.couponInfo = null;
if (!this.data.kjId && !this.data.gp_id) {
5 years ago
this.couponCom.setNullCoupon()
}
5 years ago
this.setData({
coupon: null
5 years ago
})
}
this.setData({
postFee: postFee,
product: product
5 years ago
})
})
},
/**
* 选择补贴
*/
selectAllowance: function () {
this.setData({
select_allowance: !this.data.select_allowance
})
this.changePrice()
},
3 years ago
//获取最高优惠券
getNewCoupon(e){
this.setData({
coupon:e.detail
})
},
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
3 years ago
// this.setData({
// coupon: app.globalData.couponInfo
// })
// 获取补贴
3 years ago
// if (this.data.product.length == 1) {
// commonApi.user_post("product/getProductAllowancePrice", {
// product_code: this.data.product[0].product.product_code
// }).then(resTwo => {
// console.log(resTwo)
// if (resTwo && resTwo.code == 1) {
// this.setData({
// allowance_data: resTwo.data
// })
// let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price)
// let sInfo = this.data.product[0].sku
// console.log(9999, this.data.allowance_data.discount_rate / 100 * sInfo.price)
// console.log(9999, spread_price)
// if (spread_price > 0) {
// if (spread_price < this.data.allowance_data.discount_rate / 100 * sInfo.price) {
// this.setData({
// allowance_price: spread_price
// })
// } else {
// this.setData({
// allowance_price: this.data.allowance_data.discount_rate / 100 * sInfo.price
// })
// }
// this.changePrice()
// } else {
// this.setData({
// allowance_price: 0
// })
// }
// }
// })
// }
5 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
5 years ago
this.setData({
kjId: null,
gp_id: null
5 years ago
});
app.globalData.kjId = null;
5 years ago
app.globalData.gp_id = null;
app.globalData.team_id = null;
5 years ago
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})