|
|
|
|
// pages/order/comment/index.js
|
|
|
|
|
let app = getApp()
|
|
|
|
|
import commonApi from "../../../utils/https/common"
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
goodsList: [],
|
|
|
|
|
ticketList: [],
|
|
|
|
|
productPrice: 0,
|
|
|
|
|
ticketPrice: 0,
|
|
|
|
|
product:"",
|
|
|
|
|
sku_id: '',
|
|
|
|
|
kjId: null,
|
|
|
|
|
gp_id: null,
|
|
|
|
|
showPrice: 0,
|
|
|
|
|
postFee: 0,
|
|
|
|
|
coupon:app.globalData.couponInfo,
|
|
|
|
|
select_allowance: false,
|
|
|
|
|
allowance_data: null,
|
|
|
|
|
allowance_price: 0,
|
|
|
|
|
flag:null
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.setData({
|
|
|
|
|
goodsList: app.globalData.postProduct,
|
|
|
|
|
ticketList: app.globalData.list,
|
|
|
|
|
kjId: app.globalData.kjId,
|
|
|
|
|
gp_id: app.globalData.gp_id || app.globalData.team_id,
|
|
|
|
|
flag:options.flag
|
|
|
|
|
})
|
|
|
|
|
let price = 0, sku_id = [] ,postFee= 0;
|
|
|
|
|
app.globalData.postProduct.map(item => {
|
|
|
|
|
if (!app.globalData.kjId && !this.data.gp_id) {
|
|
|
|
|
price = price + item.sku.price * item.productNum;
|
|
|
|
|
postFee +=item.postFee
|
|
|
|
|
}
|
|
|
|
|
else if (this.data.gp_id) {
|
|
|
|
|
price = price + item.sku.event_price * item.productNum;
|
|
|
|
|
}
|
|
|
|
|
sku_id.push(item.sku.id)
|
|
|
|
|
})
|
|
|
|
|
app.globalData.list.map(item => {
|
|
|
|
|
price = price + item.sku.price * item.num;
|
|
|
|
|
sku_id.push(item.sku.id)
|
|
|
|
|
})
|
|
|
|
|
this.setData({
|
|
|
|
|
showPrice: app.globalData.kjId ? 0 : price,
|
|
|
|
|
postFee:postFee,
|
|
|
|
|
sku_id: sku_id.join(",")
|
|
|
|
|
})
|
|
|
|
|
if (!this.data.kjId && !this.data.gp_id) {
|
|
|
|
|
this.couponCom = this.selectAllComponents("#coupon")[0];
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
order: function (){
|
|
|
|
|
console.log(app.globalData.createDate);
|
|
|
|
|
app.globalData.createDate.coupon_id= this.data.coupon ? this.data.coupon.id : null;
|
|
|
|
|
let service = "order/create", postData = {data: JSON.stringify(app.globalData.createDate)}
|
|
|
|
|
commonApi.user_post(service, postData).then(res => {
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
changePrice: function () {
|
|
|
|
|
let product = this.data.product, price = 0;
|
|
|
|
|
product.map(item => {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (this.data.coupon && this.data.showPrice != price) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
app.globalData.couponInfo = null;
|
|
|
|
|
if (!this.data.kjId && !this.data.gp_id) {
|
|
|
|
|
this.couponCom.setNullCoupon()
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon: null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
showPrice: app.globalData.kjId ? 0 : price
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
inputRemark: function (e) {
|
|
|
|
|
app.globalData.createDate.product_list.map((item)=>{
|
|
|
|
|
if (item.type.includes('post')) {
|
|
|
|
|
item.remark = e.detail.value;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
//获取最高优惠券
|
|
|
|
|
getNewCoupon(e){
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:e.detail
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
try {
|
|
|
|
|
if (Object.keys(app.globalData.couponInfo).length!=0) {
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon: app.globalData.couponInfo
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|