|
|
|
|
// pages/order/scene/index.js
|
|
|
|
|
let app = getApp()
|
|
|
|
|
import util from "../../../utils/util"
|
|
|
|
|
import commonApi from "../../../utils/https/common"
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
product:null,
|
|
|
|
|
productNum: 1,
|
|
|
|
|
linkmanList: [],
|
|
|
|
|
date: "",
|
|
|
|
|
time: "",
|
|
|
|
|
remark: "",
|
|
|
|
|
singlePrice: 0,
|
|
|
|
|
type: null,
|
|
|
|
|
coupon:null,
|
|
|
|
|
isLogin: false,
|
|
|
|
|
kjId: null,
|
|
|
|
|
gp_id: null,
|
|
|
|
|
groupName: "",
|
|
|
|
|
prizeId: null,
|
|
|
|
|
select_allowance: false,
|
|
|
|
|
showAllowance: false,
|
|
|
|
|
allowance_data: null,
|
|
|
|
|
allowance_price: 0,
|
|
|
|
|
pIndex: 0,
|
|
|
|
|
flag:null,
|
|
|
|
|
ticket_type:1,
|
|
|
|
|
isCar:'single',
|
|
|
|
|
showMask: false,
|
|
|
|
|
price:0,
|
|
|
|
|
|
|
|
|
|
status:false,
|
|
|
|
|
date: "",
|
|
|
|
|
time: "",
|
|
|
|
|
ydxz:false, //预定须知弹框
|
|
|
|
|
bookingInfo: null,
|
|
|
|
|
bookingInfoTitle: "",
|
|
|
|
|
showDate:false,
|
|
|
|
|
showDate2:false,
|
|
|
|
|
showYhq:null,
|
|
|
|
|
couponFlag:false
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.setData({
|
|
|
|
|
product: app.globalData.product,
|
|
|
|
|
type: options.type,
|
|
|
|
|
kjId: app.globalData.kjId,
|
|
|
|
|
gp_id: app.globalData.gp_id || app.globalData.team_id,
|
|
|
|
|
prizeId: wx.getStorageSync('prizeId'),
|
|
|
|
|
flag:options.flag,
|
|
|
|
|
date:null,
|
|
|
|
|
isCar:options.isCar,
|
|
|
|
|
showYhq:app.globalData.listName?false:true
|
|
|
|
|
})
|
|
|
|
|
console.log('-------',this.data.showYhq,this.data.time);
|
|
|
|
|
// debugger
|
|
|
|
|
|
|
|
|
|
console.log(app.globalData.list, app.globalData.index,'list---index')
|
|
|
|
|
if (!this.data.product) {
|
|
|
|
|
util.back();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.data.product.productNum) {
|
|
|
|
|
this.setData({
|
|
|
|
|
productNum: this.data.product.productNum < 1 ? 1 : this.data.product.productNum
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
this.setData({productNum: 1})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({singlePrice: this.data.product.sku.price})
|
|
|
|
|
this.showAllPrice()
|
|
|
|
|
|
|
|
|
|
console.log(this.data);
|
|
|
|
|
this.getNewCoupon()
|
|
|
|
|
this.couponCom = this.selectAllComponents("#coupon")[0];
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showBookingInfo: function (e) {
|
|
|
|
|
this.setData({
|
|
|
|
|
bookingInfo: this.data.product.sku.sku_model,
|
|
|
|
|
bookingInfoTitle: this.data.product.sku.sku_name
|
|
|
|
|
})
|
|
|
|
|
util.pagePoint({
|
|
|
|
|
event: "scene_notice",
|
|
|
|
|
param: {
|
|
|
|
|
type: this.data.product.type,
|
|
|
|
|
id: this.data.product.id
|
|
|
|
|
}
|
|
|
|
|
}, 1)
|
|
|
|
|
},
|
|
|
|
|
closeMask: function () {
|
|
|
|
|
this.setData({
|
|
|
|
|
bookingInfo: null
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
showAllPrice:function () {
|
|
|
|
|
|
|
|
|
|
console.log('couponInfo',app.globalData.couponInfo);
|
|
|
|
|
|
|
|
|
|
let price = 0
|
|
|
|
|
if (this.data.coupon) {
|
|
|
|
|
console.log(app.globalData.couponInfo,this.data.coupon);
|
|
|
|
|
if (this.data.coupon.activity.discount_type == 'pricebreak') {
|
|
|
|
|
price = this.data.singlePrice * this.data.productNum - this.data.coupon.activity.money
|
|
|
|
|
} else {
|
|
|
|
|
price =(this.data.singlePrice * this.data.productNum * this.data.coupon.activity.fold)/ 10
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
price = this.data.singlePrice * this.data.productNum
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (price >0) {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:price/100
|
|
|
|
|
})
|
|
|
|
|
}else {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// console.log(this.data.singlePrice);
|
|
|
|
|
if (price >0) {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:price/100
|
|
|
|
|
})
|
|
|
|
|
}else {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
cancel: function () {
|
|
|
|
|
this.setData({
|
|
|
|
|
showMask:false
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
changeGroupName: function (e) {
|
|
|
|
|
this.setData({
|
|
|
|
|
groupName: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
setLinkman: function (e) {
|
|
|
|
|
if (e.detail.phone || e.detail.phone=='') {
|
|
|
|
|
this.setData({
|
|
|
|
|
phone:e.detail.phone
|
|
|
|
|
})
|
|
|
|
|
}else {
|
|
|
|
|
console.log(e);
|
|
|
|
|
let linkmanList = e.detail;
|
|
|
|
|
if (this.data.productNum != linkmanList.length && this.data.coupon) {
|
|
|
|
|
// wx.showToast({
|
|
|
|
|
// title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
// icon: 'none'
|
|
|
|
|
// })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
// productNum: productNum,
|
|
|
|
|
linkmanList: linkmanList
|
|
|
|
|
})
|
|
|
|
|
console.log(this.data.linkmanList);
|
|
|
|
|
this.totalPrice(this.data.singlePrice)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
add: function () {
|
|
|
|
|
if (this.data.productNum==undefined) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请先添加出行人',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.data.product.sku.sku_model.traveller_limit_num != 0 && this.data.productNum == this.data.product.sku.sku_model.traveller_limit_num) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '本产品单笔限购' + this.data.product.sku.sku_model.traveller_limit_num + "份",
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
productNum: this.data.productNum + 1
|
|
|
|
|
})
|
|
|
|
|
this.data.product.num = this.data.productNum
|
|
|
|
|
// this.changePrice()
|
|
|
|
|
// this.showAllPrice()
|
|
|
|
|
this.totalPrice(this.data.singlePrice)
|
|
|
|
|
},
|
|
|
|
|
minus: function () {
|
|
|
|
|
if (this.data.productNum==undefined) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请先添加出行人',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (this.data.productNum == 1) return;
|
|
|
|
|
if (this.data.coupon) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (!this.data.kjId && !this.data.gp_id && this.data.product.isGroup != 1 && !this.data.flag && this.data.type!='museum') {
|
|
|
|
|
// this.couponCom.setNullCoupon()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
app.globalData.couponInfo = null;
|
|
|
|
|
console.log(this.data.couponFlag);
|
|
|
|
|
this.setData({
|
|
|
|
|
productNum: (this.data.productNum - 1),
|
|
|
|
|
coupon: null,
|
|
|
|
|
couponFlag:true
|
|
|
|
|
})
|
|
|
|
|
this.data.product.num = this.data.productNum
|
|
|
|
|
// this.changePrice()
|
|
|
|
|
// this.showAllPrice()
|
|
|
|
|
this.totalPrice(this.data.singlePrice)
|
|
|
|
|
},
|
|
|
|
|
totalPrice(price) {
|
|
|
|
|
let allPrice
|
|
|
|
|
if (this.data.coupon) {
|
|
|
|
|
if (this.data.coupon.activity.discount_type == 'pricebreak') {
|
|
|
|
|
allPrice = this.data.singlePrice * this.data.productNum - this.data.coupon.activity.money
|
|
|
|
|
} else {
|
|
|
|
|
allPrice =(this.data.singlePrice * this.data.productNum * this.data.coupon.activity.fold)/ 10
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
allPrice = this.data.singlePrice * this.data.productNum
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// allPrice = price * this.data.productNum - (this.data.coupon?this.data.coupon.activity.money:0)
|
|
|
|
|
if (allPrice >0) {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:allPrice/100,
|
|
|
|
|
singlePrice:price
|
|
|
|
|
})
|
|
|
|
|
}else {
|
|
|
|
|
this.setData({
|
|
|
|
|
price:0,
|
|
|
|
|
singlePrice:price
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
console.log('singlePrice',this.data.singlePrice);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
order:function() {
|
|
|
|
|
let linkmanList = this.data.linkmanList, productNum = this.data.productNum, date = this.data.date, time = this.data.time, remark = this.data.remark, product = this.data.product;
|
|
|
|
|
let linkmanIds = [];
|
|
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
|
coupon_id: this.data.coupon ? this.data.coupon.id : null,
|
|
|
|
|
source: "WECHATXCX",
|
|
|
|
|
product_list: [{
|
|
|
|
|
type: product.product.type,
|
|
|
|
|
product_id: product.product.id,
|
|
|
|
|
sku_id: product.sku.id,
|
|
|
|
|
start_time: '',
|
|
|
|
|
end_time: '',
|
|
|
|
|
use_date: '',
|
|
|
|
|
visitors: linkmanIds.join(","),
|
|
|
|
|
remark: remark,
|
|
|
|
|
product_num: productNum,
|
|
|
|
|
phone:this.data.phone,// 不实名的时候传的手机号参数
|
|
|
|
|
}],
|
|
|
|
|
originate_order_id: this.data.kjId,
|
|
|
|
|
gp_id: app.globalData.gp_id,
|
|
|
|
|
team_id: app.globalData.team_id,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (app.globalData.from) {
|
|
|
|
|
data.system_name = app.globalData.from;
|
|
|
|
|
}
|
|
|
|
|
if (app.globalData.retailId) {
|
|
|
|
|
data.commission_code = app.globalData.retailId;
|
|
|
|
|
app.globalData.retailId = null;
|
|
|
|
|
}
|
|
|
|
|
if (app.globalData.category_id) {
|
|
|
|
|
data.category_id = app.globalData.category_id;
|
|
|
|
|
}
|
|
|
|
|
if (this.data.prizeId) {
|
|
|
|
|
data.lottery_id = this.data.prizeId
|
|
|
|
|
}
|
|
|
|
|
let service = 'order/create', postData = {
|
|
|
|
|
data: JSON.stringify(data)
|
|
|
|
|
}
|
|
|
|
|
// if (app.globalData.product.isGroup == 1) {
|
|
|
|
|
// service = "team_order/appoint"
|
|
|
|
|
// postData.member_num = this.data.productNum
|
|
|
|
|
// postData.team_name = this.data.groupName
|
|
|
|
|
// postData.type = 1;
|
|
|
|
|
// }
|
|
|
|
|
// if(app.globalData.list){
|
|
|
|
|
// app.globalData.list[app.globalData.index] = this.data.product
|
|
|
|
|
// }
|
|
|
|
|
// app.globalData.linkmanList = this.data.linkmanList
|
|
|
|
|
app.globalData.ticketPrice += (this.data.singlePrice * this.data.productNum - (this.data.coupon?this.data.coupon.activity.money:0))/100;
|
|
|
|
|
console.log(app.globalData);
|
|
|
|
|
|
|
|
|
|
// if(app.globalData.list && app.globalData.list.length > app.globalData.index + 1 &&this.data.type!='museum'){
|
|
|
|
|
if (false) {
|
|
|
|
|
if(app.globalData.createDate){
|
|
|
|
|
app.globalData.createDate.product_list.push(data.product_list[0])
|
|
|
|
|
}else{
|
|
|
|
|
app.globalData.createDate = data
|
|
|
|
|
}
|
|
|
|
|
console.log(app.globalData.createDate);
|
|
|
|
|
app.globalData.index = app.globalData.index + 1
|
|
|
|
|
app.globalData.product = app.globalData.list[app.globalData.index]
|
|
|
|
|
wx.redirectTo({
|
|
|
|
|
url: '/pages/order/scene/index?flag='+ this.data.flag+'&isCar='+this.data.isCar,
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}else{
|
|
|
|
|
// if(app.globalData.list && app.globalData.list.length > 1 || app.globalData.postProduct.length>0){
|
|
|
|
|
if (false) {
|
|
|
|
|
if(app.globalData.createDate){
|
|
|
|
|
app.globalData.createDate.product_list.push(data.product_list[0])
|
|
|
|
|
}
|
|
|
|
|
wx.redirectTo({
|
|
|
|
|
url: '/pages/order/orderList/index?flag='+ this.data.flag
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
commonApi.user_post(service, postData).then(res => {
|
|
|
|
|
if (app.globalData.kjId) {
|
|
|
|
|
this.setData({
|
|
|
|
|
kjId: null
|
|
|
|
|
});
|
|
|
|
|
app.globalData.kjId = null;
|
|
|
|
|
}
|
|
|
|
|
if (app.globalData.gp_id) {
|
|
|
|
|
this.setData({
|
|
|
|
|
gp_id: null
|
|
|
|
|
});
|
|
|
|
|
app.globalData.gp_id = null;
|
|
|
|
|
}
|
|
|
|
|
if (res.code == 1 && app.globalData.product.isGroup == 1) {
|
|
|
|
|
// 团购跳转到团购详情
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/info/groupOrderInfo/index?id=' + res.data.order_id + '&from=order'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
next: function () {
|
|
|
|
|
console.log(this.data)
|
|
|
|
|
if (!util.isTel(this.data.phone)) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入正确的手机号',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
showMask:true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取最高优惠券
|
|
|
|
|
getNewCoupon(e){
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:e.detail
|
|
|
|
|
})
|
|
|
|
|
this.showAllPrice()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
|
|
if (!this.data.isLogin) {
|
|
|
|
|
commonApi.user_post("token/check").then(res => {
|
|
|
|
|
if (res.code == 1) {
|
|
|
|
|
this.setData({
|
|
|
|
|
isLogin: true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
this.setData({
|
|
|
|
|
couponFlag:false
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
this.setData({
|
|
|
|
|
kjId: null,
|
|
|
|
|
gp_id: null
|
|
|
|
|
});
|
|
|
|
|
app.globalData.kjId = null;
|
|
|
|
|
app.globalData.gp_id = null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|