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.
261 lines
5.5 KiB
261 lines
5.5 KiB
// pages/order/food/index.js
|
|
import userApi from "../../../utils/https/user"
|
|
import commonApi from "../../../utils/https/common"
|
|
let app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
productNum:1,
|
|
product:app.globalData.product,
|
|
couponMoney:0,
|
|
user:"",
|
|
tel:"",
|
|
showNoticeFlag:false,
|
|
coupon:null,
|
|
price: 0,
|
|
smoothlyTotal: 0,
|
|
maxCouponObject: null,
|
|
couponCom: null
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.couponCom = this.selectAllComponents("#coupon")[0];
|
|
// 获取下用户信息 易梦静说默认用用户绑定的手机号和昵称
|
|
this.setData({
|
|
product:app.globalData.product
|
|
})
|
|
userApi.user_post("user/getMyInfo").then(res=>{
|
|
console.log(res)
|
|
this.setData({
|
|
tel:res.data.mobile,
|
|
user:res.data.fullname?res.data.fullname:""
|
|
})
|
|
})
|
|
console.log(app.globalData.product)
|
|
this.showAllPrice()
|
|
},
|
|
// 子组件发生改变时更新价格
|
|
handleUpdateTotalPrice(e) {
|
|
this.setData({
|
|
smoothlyTotal: e.detail.total
|
|
});
|
|
// 重新计算总价
|
|
this.showAllPrice();
|
|
},
|
|
// 调用子组件清除优惠券方法
|
|
callOtherCompMethod: function(e) {
|
|
this.couponCom.setNullCoupon()
|
|
this.setData({
|
|
coupon:null
|
|
})
|
|
},
|
|
showNotice:function(){
|
|
this.setData({
|
|
showNoticeFlag:true
|
|
})
|
|
},
|
|
closeNotice:function(){
|
|
this.setData({
|
|
showNoticeFlag:false
|
|
})
|
|
},
|
|
|
|
getNewCoupon(e){
|
|
this.setData({
|
|
coupon:e.detail
|
|
})
|
|
this.showAllPrice()
|
|
},
|
|
|
|
showAllPrice () {
|
|
console.log('couponInfo',app.globalData.couponInfo);
|
|
|
|
let price = this.data.product.sku.price * this.data.productNum
|
|
let allPrice = 0
|
|
|
|
allPrice = price
|
|
|
|
// 顺手购价格
|
|
if (!this.data.coupon) {
|
|
price += this.data.smoothlyTotal || 0;
|
|
}
|
|
|
|
if (this.data.coupon) {
|
|
if (this.data.coupon.activity.discount_type == 'pricebreak') {
|
|
price = price - this.data.coupon.activity.money
|
|
} else {
|
|
price =(price * this.data.coupon.activity.fold)/ 10
|
|
}
|
|
} else {
|
|
price = price
|
|
}
|
|
if (price >0) {
|
|
this.setData({ price:price/100})
|
|
}else {
|
|
this.setData({ price:0 })
|
|
}
|
|
|
|
const smoothlyComp = this.selectComponent("#smoothlyOrderComp");
|
|
const skuIds = []
|
|
skuIds.push(this.data.product.sku.id)
|
|
if(smoothlyComp) {
|
|
// 检查是否有选中的顺手购商品
|
|
const hasSkuIds = smoothlyComp.hasSelectedGoods();
|
|
if(hasSkuIds) {
|
|
skuIds.push(...smoothlyComp.emitSkuIds())
|
|
}
|
|
}
|
|
this.setData({
|
|
maxCouponObject: {
|
|
price: allPrice,
|
|
skuIds: skuIds.toString()
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
minus:function(){
|
|
if(this.data.productNum<=1) return;
|
|
if(this.data.coupon){
|
|
wx.showToast({
|
|
title: '订单价格发生变化,请重新选择优惠券',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
this.couponCom.setNullCoupon()
|
|
app.globalData.couponInfo = null;
|
|
this.setData({
|
|
productNum:(this.data.productNum-1),
|
|
coupon:null
|
|
})
|
|
this.showAllPrice()
|
|
},
|
|
add:function(){
|
|
this.setData({
|
|
productNum:this.data.productNum+1
|
|
})
|
|
this.showAllPrice()
|
|
|
|
},
|
|
userInput:function(e){
|
|
this.setData({
|
|
user:e.detail.value
|
|
})
|
|
},
|
|
telInput:function(e){
|
|
this.setData({
|
|
tel:e.detail.value
|
|
})
|
|
},
|
|
order:function(){
|
|
const smoothlyComp = this.selectComponent("#smoothlyOrderComp");
|
|
if(smoothlyComp) {
|
|
// 检查是否有选中的顺手购商品
|
|
const hasSelected = smoothlyComp.hasSelectedGoods();
|
|
if(hasSelected && !smoothlyComp.data.address) {
|
|
wx.showToast({
|
|
title: '请选择收货地址',
|
|
icon: 'none'
|
|
})
|
|
return;
|
|
}
|
|
}
|
|
|
|
// if(!this.data.user){
|
|
// wx.showToast({
|
|
// title: '请输入联系人',
|
|
// icon: 'none'
|
|
// })
|
|
// return;
|
|
// }
|
|
if(!this.data.tel){
|
|
wx.showToast({
|
|
title: '请输入手机号',
|
|
icon: 'none'
|
|
})
|
|
return;
|
|
}
|
|
let product = this.data.product;
|
|
let product_list = [{
|
|
type:product.product.type,
|
|
product_id:product.product.id,
|
|
sku_id:product.sku.id,
|
|
product_num:this.data.productNum,
|
|
reserve_username:this.data.user,
|
|
reserve_mobile:this.data.tel
|
|
}],data = {
|
|
product_list:product_list,
|
|
source:"WECHATXCX",
|
|
coupon_id:this.data.coupon?this.data.coupon.id:null
|
|
};
|
|
|
|
// 顺手购下单参数
|
|
if(smoothlyComp && smoothlyComp.emitOrder() && smoothlyComp.emitOrder().length) {
|
|
product_list.push(...smoothlyComp.emitOrder())
|
|
}
|
|
|
|
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;
|
|
}
|
|
commonApi.user_post("order/create",{
|
|
data:JSON.stringify(data)
|
|
}).then(res=>{
|
|
console.log(res)
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.setData({
|
|
coupon:app.globalData.couponInfo
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|