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.
444 lines
12 KiB
444 lines
12 KiB
// 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,
|
|
kjId: null,
|
|
gp_id: null,
|
|
groupName: "",
|
|
prizeId: null,
|
|
select_allowance: false,
|
|
showAllowance: false,
|
|
allowance_data: null,
|
|
allowance_price: 0,
|
|
pIndex: 0,
|
|
flag:null,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
type: options.type,
|
|
kjId: app.globalData.kjId,
|
|
gp_id: app.globalData.gp_id || app.globalData.team_id,
|
|
prizeId: wx.getStorageSync('prizeId'),
|
|
flag:options.flag
|
|
})
|
|
if (!app.globalData.product) {
|
|
util.back();
|
|
return;
|
|
}
|
|
if (app.globalData.product.productNum) {
|
|
this.setData({
|
|
productNum: app.globalData.product.productNum < 1 ? 1 : app.globalData.product.productNum
|
|
})
|
|
}else{
|
|
this.setData({
|
|
productNum: app.globalData.product.num < 1 ? 1 : app.globalData.product.num
|
|
})
|
|
}
|
|
this.setData({
|
|
product: app.globalData.product,
|
|
singlePrice: this.data.gp_id ? app.globalData.product.sku.event_price : app.globalData.product.sku.price
|
|
})
|
|
if (!this.data.kjId && !this.data.gp_id && this.data.product.isGroup != 1) {
|
|
this.couponCom = this.selectAllComponents("#coupon")[0];
|
|
}
|
|
},
|
|
changeGroupName: function (e) {
|
|
this.setData({
|
|
groupName: e.detail.value
|
|
})
|
|
},
|
|
setLinkman: function (e) {
|
|
let linkmanList = e.detail;
|
|
if (this.data.productNum != linkmanList.length && this.data.coupon) {
|
|
wx.showToast({
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
icon: 'none'
|
|
})
|
|
if (!this.data.kjId && !this.data.gp_id && this.data.product.isGroup != 1) {
|
|
this.couponCom.setNullCoupon()
|
|
}
|
|
app.globalData.couponInfo = null;
|
|
this.setData({
|
|
coupon: null
|
|
})
|
|
}
|
|
let productNum = linkmanList.length == 0 ? 1 : this.data.productNum > linkmanList.length ? this.data.productNum : linkmanList.length;
|
|
if (this.data.gp_id) {
|
|
productNum = app.globalData.product.maxNum;
|
|
}
|
|
this.setData({
|
|
productNum: productNum,
|
|
linkmanList: linkmanList
|
|
})
|
|
this.changePrice()
|
|
},
|
|
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()
|
|
},
|
|
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.couponCom.setNullCoupon()
|
|
}
|
|
app.globalData.couponInfo = null;
|
|
this.setData({
|
|
productNum: (this.data.productNum - 1),
|
|
coupon: null
|
|
})
|
|
this.data.product.num = this.data.productNum
|
|
this.changePrice()
|
|
},
|
|
changeDate: function (e) {
|
|
if (e.detail.price != this.data.singlePrice && this.data.coupon) {
|
|
wx.showToast({
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
icon: 'none'
|
|
})
|
|
this.setData({
|
|
coupon: null
|
|
})
|
|
if (!this.data.kjId && !this.data.gp_id && this.data.product.isGroup != 1) {
|
|
this.couponCom.setNullCoupon()
|
|
}
|
|
app.globalData.couponInfo = null;
|
|
}
|
|
this.setData({
|
|
date: e.detail,
|
|
singlePrice: this.data.gp_id ? this.data.product.sku.event_price : e.detail.price
|
|
})
|
|
this.changePrice()
|
|
},
|
|
changeTime: function (e) {
|
|
this.setData({
|
|
time: e.detail
|
|
})
|
|
},
|
|
changeAllowance: function () {
|
|
this.setData({
|
|
showAllowance: !this.data.showAllowance
|
|
})
|
|
},
|
|
changeRemark: function (e) {
|
|
this.setData({
|
|
remark: e.detail.value
|
|
})
|
|
},
|
|
/**
|
|
* 补贴价
|
|
*/
|
|
changePrice: function () {
|
|
let product = this.data.product, price = product.sku.price;
|
|
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 < spread_price ? this.data.allowance_price : spread_price
|
|
}
|
|
this.setData({
|
|
singlePrice: app.globalData.kjId ? 0 : price
|
|
})
|
|
|
|
},
|
|
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 && app.globalData.product.isGroup != 1) {
|
|
// 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
|
|
}
|
|
if (app.globalData.product.isGroup == 1 && !this.data.groupName) {
|
|
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: date.sku_id ? date.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: app.globalData.product.isGroup == 1 ? 1 : productNum
|
|
}],
|
|
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.ticketPrice += (this.data.singlePrice * this.data.productNum - (this.data.coupon?this.data.coupon.activity.money:0))/100;
|
|
if(app.globalData.list && app.globalData.list.length > app.globalData.index + 1){
|
|
if(app.globalData.createDate){
|
|
app.globalData.createDate.product_list.push(data.product_list[0])
|
|
}else{
|
|
app.globalData.createDate = data
|
|
}
|
|
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,
|
|
})
|
|
return
|
|
}else{
|
|
if(app.globalData.list && app.globalData.list.length > 1 || app.globalData.postProduct.length>0){
|
|
if(app.globalData.createDate){
|
|
app.globalData.createDate.product_list.push(data.product_list[0])
|
|
}
|
|
wx.redirectTo({
|
|
url: '/pages/order/orderList/index'
|
|
})
|
|
}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'
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
},
|
|
// 活动预约
|
|
activityOrder: function () {
|
|
if (this.data.linkmanList && this.data.linkmanList.length > 0) {
|
|
commonApi.user_post("pbservice/Culture/booking", {
|
|
id: this.data.product.product.id,
|
|
name: this.data.linkmanList[0].name,
|
|
card_number: this.data.linkmanList[0].id_number,
|
|
tel: this.data.linkmanList[0].tel
|
|
}).then(res => {
|
|
if (res.code == 1) {
|
|
wx.showToast({
|
|
title: '预约成功',
|
|
icon: 'success'
|
|
})
|
|
setTimeout(() => {
|
|
wx.navigateBack()
|
|
}, 1000)
|
|
return;
|
|
}
|
|
})
|
|
}
|
|
else {
|
|
wx.showToast({
|
|
title: '请选择出行人',
|
|
icon: 'none'
|
|
})
|
|
return;
|
|
}
|
|
|
|
},
|
|
/**
|
|
* 选择补贴
|
|
*/
|
|
selectAllowance: function () {
|
|
this.setData({
|
|
select_allowance: !this.data.select_allowance
|
|
})
|
|
this.changePrice()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
if(app.globalData.list && app.globalData.list.length != 0){
|
|
app.globalData.product = app.globalData.list[app.globalData.index]
|
|
}
|
|
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
|
|
})
|
|
// 获取补贴
|
|
// if (this.data.product) {
|
|
// commonApi.user_post("product/getProductAllowancePrice", {
|
|
// product_code: this.data.product.product.product_code
|
|
// }).then(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.sku
|
|
// 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
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
// }
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
this.setData({
|
|
kjId: null,
|
|
gp_id: null
|
|
});
|
|
app.globalData.kjId = null;
|
|
app.globalData.gp_id = null;
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|