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.

243 lines
5.6 KiB

5 years ago
// 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:[],
skuIndex:0,
type:0,
address:null,
postFee:0,
coupon:null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(!app.globalData.product){
util.back();
return;
}
this.couponCom = this.selectAllComponents("#coupon")[0];
this.setData({
product:app.globalData.product
})
if(app.globalData.product.product.sku[0].sku_model.fetch_type=='post'){
this.setData({
type:1
})
}
},
changeType:function(e){
if(e.currentTarget.dataset.type==this.data.type) return;
this.setData({
type:e.currentTarget.dataset.type,
linkmanList:[],
address:null
})
if(this.data.coupon){
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
this.couponCom.setNullCoupon()
app.globalData.couponInfo = null;
this.setData({
coupon:null
})
}
},
setSku:function(e){
let skuIndex = e.currentTarget.dataset.index;
if(skuIndex==this.data.skuIndex) return;
this.setData({
skuIndex:skuIndex
})
if(this.data.coupon){
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
this.couponCom.setNullCoupon()
app.globalData.couponInfo = null;
this.setData({
coupon:null
})
}
},
setLinkman:function(e){
let linkmanList = e.detail;
this.setData({
productNum:linkmanList.length==0?1:linkmanList.length,
linkmanList:linkmanList
})
},
setAddress:function(e){
this.setData({
address:e.detail,
postFee:0
})
this.getPostFee()
},
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
})
this.getPostFee()
},
minus:function(){
this.setData({
productNum:this.data.productNum>1?(this.data.productNum-1):1
})
if(this.data.coupon){
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
this.couponCom.setNullCoupon()
app.globalData.couponInfo = null;
this.setData({
coupon:null
})
}
this.getPostFee()
},
getPostFee:function(){
if(!this.data.address) return;
commonApi.user_post("order/get_post_price",{
sku_id:this.data.product.sku.id,
num:this.data.productNum,
consignee_id:this.data.address.id
}).then(res=>{
if(res.data.price<0) {
wx.showToast({
title: '该地区不发货',
icon:'none'
})
res.data.price = 0;
};
if(res.data.price!=this.data.postFee && this.data.coupon){
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
this.couponCom.setNullCoupon()
app.globalData.couponInfo = null;
this.setData({
coupon:null
})
}
this.setData({
postFee:res.data.price
})
})
},
order:function(){
let linkmanList = this.data.linkmanList,productNum = this.data.productNum,product = this.data.product,visitors=[];
if(linkmanList.length<productNum && this.data.type==0){
wx.showToast({
title: '请选择'+productNum+'个出行人',
icon:'none'
})
return;
}
else if(this.data.type==1 && !this.data.address){
wx.showToast({
title: '请选择收货地址',
icon:'none'
})
return;
}
linkmanList.map(item=>{
visitors.push(item.id)
})
let data = {
source:"WECHATXCX",
coupon_id:this.data.coupon?this.data.coupon.id:null,
product_list:[{
type:product.product.type,
product_id:product.product.id,
sku_id:product.sku.id,
product_num:productNum,
recharge:product.sku.sku_model.recharge[this.data.skuIndex] || 0,
visitors:visitors.join(","),
post:this.data.type==0?'':this.data.address.id,
fetch_type:this.data.type==0?'selffetch':'post'
}]
}
5 years ago
if(app.globalData.retailId){
data.commission_code = app.globalData.retailId;
app.globalData.retailId = null;
}
if(app.globalData.from){
data.system_name = app.globalData.from;
}
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)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setData({
coupon:app.globalData.couponInfo
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})