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.

166 lines
3.4 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,
coupon: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)
},
showNotice:function(){
this.setData({
showNoticeFlag:true
})
},
closeNotice:function(){
this.setData({
showNoticeFlag:false
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
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
})
},
add:function(){
this.setData({
productNum:this.data.productNum+1
})
},
userInput:function(e){
this.setData({
user:e.detail.value
})
},
telInput:function(e){
this.setData({
tel:e.detail.value
})
},
order:function(){
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
};
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 () {
}
})