|
|
|
|
// pages/order/scene/index.js
|
|
|
|
|
let app = getApp()
|
|
|
|
|
import util from "../../../utils/util"
|
|
|
|
|
import commonApi from "../../../utils/https/common"
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
product:app.globalData.product,
|
|
|
|
|
productNum:1,
|
|
|
|
|
linkmanList:[],
|
|
|
|
|
date:"",
|
|
|
|
|
time:"",
|
|
|
|
|
remark:"",
|
|
|
|
|
singlePrice:0,
|
|
|
|
|
type:null,
|
|
|
|
|
coupon:app.globalData.couponInfo,
|
|
|
|
|
isLogin:false
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.setData({
|
|
|
|
|
type:options.type
|
|
|
|
|
})
|
|
|
|
|
if(!app.globalData.product){
|
|
|
|
|
util.back();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log(app.globalData.product)
|
|
|
|
|
this.setData({
|
|
|
|
|
product:app.globalData.product,
|
|
|
|
|
singlePrice:app.globalData.product.sku.price
|
|
|
|
|
})
|
|
|
|
|
this.couponCom = this.selectAllComponents("#coupon")[0];
|
|
|
|
|
},
|
|
|
|
|
setLinkman:function(e){
|
|
|
|
|
let linkmanList = e.detail;
|
|
|
|
|
if(this.data.productNum!=linkmanList.length && this.data.coupon){
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.couponCom.setNullCoupon()
|
|
|
|
|
app.globalData.couponInfo = null;
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
productNum:linkmanList.length==0?1:linkmanList.length,
|
|
|
|
|
linkmanList:linkmanList
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
add:function(){
|
|
|
|
|
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
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
minus:function(){
|
|
|
|
|
if(this.data.productNum==1) return;
|
|
|
|
|
if(this.data.coupon){
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// this.couponCom = this.selectAllComponents("#coupon")
|
|
|
|
|
this.couponCom.setNullCoupon()
|
|
|
|
|
app.globalData.couponInfo = null;
|
|
|
|
|
this.setData({
|
|
|
|
|
productNum:(this.data.productNum-1),
|
|
|
|
|
coupon:null
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
changeDate:function(e){
|
|
|
|
|
if(e.detail.price!=this.data.singlePrice && this.data.coupon) {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:null
|
|
|
|
|
})
|
|
|
|
|
// this.couponCom = this.selectAllComponents("#coupon")
|
|
|
|
|
this.couponCom.setNullCoupon()
|
|
|
|
|
app.globalData.couponInfo = null;
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
date:e.detail,
|
|
|
|
|
singlePrice:e.detail.price
|
|
|
|
|
})
|
|
|
|
|
console.log(e.detail)
|
|
|
|
|
},
|
|
|
|
|
changeTime:function(e){
|
|
|
|
|
this.setData({
|
|
|
|
|
time:e.detail
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
changeRemark:function(e){
|
|
|
|
|
this.setData({
|
|
|
|
|
remark:e.detail.value
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
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=[];
|
|
|
|
|
if(linkmanList.length<productNum){
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请选择'+productNum+"个出行人",
|
|
|
|
|
icon:"none"
|
|
|
|
|
})
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(!date){
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请选择使用日期',
|
|
|
|
|
icon:'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if(!time && date.is_time_stock==true){
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请选择使用时间',
|
|
|
|
|
icon:'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
linkmanList.map(item=>{
|
|
|
|
|
linkmanIds.push(item.id)
|
|
|
|
|
})
|
|
|
|
|
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:time.start_time,
|
|
|
|
|
end_time:time.end_time,
|
|
|
|
|
use_date:date.date,
|
|
|
|
|
visitors:linkmanIds.join(","),
|
|
|
|
|
remark:remark,
|
|
|
|
|
product_num:productNum
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
commonApi.user_post("order/create",{
|
|
|
|
|
data:JSON.stringify(data)
|
|
|
|
|
}).then(res=>{
|
|
|
|
|
console.log(res)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
if(!this.data.isLogin){
|
|
|
|
|
commonApi.user_post("token/check").then(res=>{
|
|
|
|
|
if(res.code==1){
|
|
|
|
|
this.setData({
|
|
|
|
|
isLogin:true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
coupon:app.globalData.couponInfo
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|