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

5 years ago
// 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,
7 months ago
coupon:null,
price: 0,
3 months ago
smoothlyTotal: 0,
3 months ago
maxCouponObject: null,
couponCom: null
5 years ago
},
/**
* 生命周期函数--监听页面加载
*/
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)
7 months ago
this.showAllPrice()
5 years ago
},
3 months ago
// 子组件发生改变时更新价格
handleUpdateTotalPrice(e) {
this.setData({
smoothlyTotal: e.detail.total
});
// 重新计算总价
this.showAllPrice();
},
// 调用子组件清除优惠券方法
callOtherCompMethod: function(e) {
this.couponCom.setNullCoupon()
3 months ago
this.setData({
coupon:null
})
3 months ago
},
5 years ago
showNotice:function(){
this.setData({
showNoticeFlag:true
})
},
closeNotice:function(){
this.setData({
showNoticeFlag:false
})
},
7 months ago
getNewCoupon(e){
this.setData({
coupon:e.detail
})
this.showAllPrice()
},
showAllPrice () {
console.log('couponInfo',app.globalData.couponInfo);
3 months ago
let price = this.data.product.sku.price * this.data.productNum
let allPrice = 0
allPrice = price
3 months ago
// 顺手购价格
if (!this.data.coupon) {
price += this.data.smoothlyTotal || 0;
}
7 months ago
if (this.data.coupon) {
if (this.data.coupon.activity.discount_type == 'pricebreak') {
3 months ago
price = price - this.data.coupon.activity.money
7 months ago
} else {
3 months ago
price =(price * this.data.coupon.activity.fold)/ 10
7 months ago
}
} else {
3 months ago
price = price
7 months ago
}
if (price >0) {
this.setData({ price:price/100})
}else {
this.setData({ price:0 })
}
3 months ago
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()
}
})
7 months ago
},
5 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
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
})
7 months ago
this.showAllPrice()
5 years ago
},
add:function(){
this.setData({
productNum:this.data.productNum+1
})
7 months ago
this.showAllPrice()
5 years ago
},
userInput:function(e){
this.setData({
user:e.detail.value
})
},
telInput:function(e){
this.setData({
tel:e.detail.value
})
},
order:function(){
3 months ago
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;
// }
5 years ago
if(!this.data.tel){
wx.showToast({
title: '请输入手机号',
5 years ago
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
};
3 months ago
// 顺手购下单参数
if(smoothlyComp && smoothlyComp.emitOrder() && smoothlyComp.emitOrder().length) {
product_list.push(...smoothlyComp.emitOrder())
}
5 years ago
if(app.globalData.from){
data.system_name = app.globalData.from;
}
if(app.globalData.retailId){
data.commission_code = app.globalData.retailId;
app.globalData.retailId = null;
}
5 years ago
if(app.globalData.category_id){
data.category_id = app.globalData.category_id;
}
5 years ago
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 () {
}
})