|
|
|
@ -7,6 +7,9 @@ Page({ |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
pageUseType: 0, // 0 邮寄 1 自提 3邮寄或自提 购物车用 不考虑3
|
|
|
|
allProduct: [], |
|
|
|
|
|
|
|
product: [], |
|
|
|
showPrice: 0, |
|
|
|
from: null, |
|
|
|
@ -23,7 +26,9 @@ Page({ |
|
|
|
showAllowance: false, |
|
|
|
flag:null, |
|
|
|
isCar:'single', |
|
|
|
showYhq:null |
|
|
|
showYhq:null, |
|
|
|
|
|
|
|
pickupIndex: null, |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@ -39,28 +44,80 @@ Page({ |
|
|
|
isCar:options.isCar, |
|
|
|
showYhq:app.globalData.listName?false:true |
|
|
|
}) |
|
|
|
this.handleProduct() |
|
|
|
}, |
|
|
|
|
|
|
|
handleProduct () { |
|
|
|
app.globalData.postProduct.forEach((item,index) => { |
|
|
|
item.keyIndex = index |
|
|
|
item.sku.batch_shipment = item.sku.batch_shipment?item.sku.batch_shipment:0; |
|
|
|
// 用户选择的配送方式
|
|
|
|
item.user_select_type = item.sku.use_type === 1 ? 1 : 0 |
|
|
|
}) |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
allProduct: app.globalData.postProduct, |
|
|
|
}) |
|
|
|
|
|
|
|
if (this.data.from == "cart") { |
|
|
|
if (this.data.pageUseType == 0) { |
|
|
|
let pageUseType = app.globalData.postProduct.some(x=>x.user_select_type==0)?0:1 |
|
|
|
let productList = app.globalData.postProduct.filter(x=>x.user_select_type == pageUseType) |
|
|
|
this.setData({ |
|
|
|
product: productList, |
|
|
|
pageUseType: pageUseType, |
|
|
|
}) |
|
|
|
} else { |
|
|
|
let productList = app.globalData.postProduct.filter(x=>x.user_select_type == 1) |
|
|
|
this.setData({ |
|
|
|
product: productList, |
|
|
|
pageUseType: 1, |
|
|
|
}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.setData({ |
|
|
|
product: app.globalData.postProduct, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
console.log(this.data.product, "页面数据") |
|
|
|
|
|
|
|
let price = 0, sku_id = []; |
|
|
|
app.globalData.postProduct.map(item => { |
|
|
|
this.data.product.forEach(item=>{ |
|
|
|
if (!app.globalData.kjId && !this.data.gp_id) { |
|
|
|
price = price + item.sku.price * item.productNum; |
|
|
|
} |
|
|
|
else if (this.data.gp_id) { |
|
|
|
price = price + item.sku.event_price * item.productNum; |
|
|
|
} |
|
|
|
item.sku.batch_shipment = item.sku.batch_shipment?item.sku.batch_shipment:0; |
|
|
|
sku_id.push(item.sku.id) |
|
|
|
}) |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
product: app.globalData.postProduct, |
|
|
|
showPrice: app.globalData.kjId ? 0 : price, |
|
|
|
sku_id: sku_id.join(",") |
|
|
|
sku_id: sku_id.join(","), |
|
|
|
}) |
|
|
|
console.log(this.data.product) |
|
|
|
|
|
|
|
|
|
|
|
if (!this.data.kjId && !this.data.gp_id) { |
|
|
|
this.couponCom = this.selectAllComponents("#coupon")[0]; |
|
|
|
} |
|
|
|
console.log(this.data.showPrice) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
changeUserPost (e) { |
|
|
|
let item = e.currentTarget.dataset.item |
|
|
|
let value = e.currentTarget.dataset.value |
|
|
|
let index = e.currentTarget.dataset.index |
|
|
|
item.user_select_type = value |
|
|
|
|
|
|
|
this.data.product[index] = item |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
product: this.data.product |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
price() { |
|
|
|
let allPrice |
|
|
|
if (this.data.coupon) { |
|
|
|
@ -83,6 +140,23 @@ Page({ |
|
|
|
product: product |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
phoneInput: function (e) { |
|
|
|
let index = e.currentTarget.dataset.index, product = this.data.product; |
|
|
|
product[index].phone = e.detail.value; |
|
|
|
this.setData({ |
|
|
|
product: product |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
delTel: function(e) { |
|
|
|
let index = e.currentTarget.dataset.index, product = this.data.product; |
|
|
|
product[index].phone = ""; |
|
|
|
this.setData({ |
|
|
|
product: product |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
setAddress: function (e) { |
|
|
|
console.log('我触发了'); |
|
|
|
this.setData({ |
|
|
|
@ -90,6 +164,31 @@ Page({ |
|
|
|
}) |
|
|
|
this.getPostFee() |
|
|
|
}, |
|
|
|
|
|
|
|
changePickup:function (e) { |
|
|
|
let index = e.currentTarget.dataset.index; |
|
|
|
let item = e.currentTarget.dataset.item |
|
|
|
this.setData({ |
|
|
|
pickupIndex: index |
|
|
|
}) |
|
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
url:`/subPackages/techanNew/selfPickPoint/index?pickupId=null&goodsId=${item.product.id}&skuId=${item.sku.id}` |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
setPickUpPoint: function (data) { |
|
|
|
console.log(data) |
|
|
|
let goods = this.data.product[this.data.pickupIndex] |
|
|
|
if (goods) { |
|
|
|
goods.pickupAddress = data |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
product: this.data.product |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
minus: function (e) { |
|
|
|
let index = e.currentTarget.dataset.index, product = this.data.product; |
|
|
|
let productNum = product[index].productNum; |
|
|
|
@ -140,27 +239,80 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
order: function () { |
|
|
|
|
|
|
|
for(let info of this.data.product) { |
|
|
|
if (info.user_select_type == 0) { |
|
|
|
if (!this.data.address) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择收货地址!', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
wx.showToast({title: '请选择收货地址',icon: 'none'}); |
|
|
|
return; |
|
|
|
} |
|
|
|
let product = this.data.product, product_list = []; |
|
|
|
product.map(item => { |
|
|
|
let productItem = { |
|
|
|
type: item.product.type, |
|
|
|
product_id: item.product.id, |
|
|
|
sku_id: item.sku.id, |
|
|
|
post: this.data.address.id, |
|
|
|
product_num: item.productNum, |
|
|
|
remark: item.remark, |
|
|
|
is_batch_shipment: item.sku.batch_shipment, |
|
|
|
compose_sku_id: item.sku.compose_sku_id, |
|
|
|
} |
|
|
|
product_list.push(productItem) |
|
|
|
if (info.user_select_type == 1) { |
|
|
|
if (!info.pickupAddress||!info.pickupAddress.id) { |
|
|
|
wx.showToast({title: '请选择自提点',icon: 'none'}); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!info.phone) { |
|
|
|
wx.showToast({title: '请输入预留手机号',icon: 'none'}); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let allProductIndex = this.data.allProduct.findIndex(x=>x.keyIndex == info.keyIndex) |
|
|
|
if (allProductIndex>=0) { |
|
|
|
this.data.allProduct[allProductIndex] = info |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断邮寄自提下单结束
|
|
|
|
let canEnd = this.data.from == "cart"?false:true; |
|
|
|
if (!canEnd) { |
|
|
|
// 还有自提的产品
|
|
|
|
if (this.data.pageUseType==0 && this.data.allProduct.some(x=>x.user_select_type==1)) { |
|
|
|
canEnd = false |
|
|
|
} else { |
|
|
|
canEnd = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!canEnd) { |
|
|
|
this.setData({ |
|
|
|
pageUseType: 1 |
|
|
|
}) |
|
|
|
this.handleProduct() |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 真下单
|
|
|
|
let product_list = []; |
|
|
|
for(let info of this.data.allProduct) { |
|
|
|
let param = { |
|
|
|
type: info.product.type, |
|
|
|
product_id: info.product.id, |
|
|
|
sku_id: info.sku.id, |
|
|
|
// post: this.data.address.id,
|
|
|
|
product_num: info.productNum, |
|
|
|
remark: info.remark, |
|
|
|
is_batch_shipment: info.sku.batch_shipment, |
|
|
|
compose_sku_id: info.sku.compose_sku_id, |
|
|
|
supplier_id: info.product.supplier_id, |
|
|
|
} |
|
|
|
if (info.user_select_type == 0) { |
|
|
|
param.use_type = 1 |
|
|
|
param.post = this.data.address.id |
|
|
|
} |
|
|
|
if (info.user_select_type == 1) { |
|
|
|
param.use_type = 2 |
|
|
|
param.pickup_shop_id = info.pickupAddress.id |
|
|
|
param.pickup_shop_info = info.pickupAddress |
|
|
|
|
|
|
|
} |
|
|
|
product_list.push(param) |
|
|
|
} |
|
|
|
|
|
|
|
let data = { |
|
|
|
source: "WECHATXCX", |
|
|
|
product_list: product_list, |
|
|
|
@ -189,8 +341,19 @@ Page({ |
|
|
|
data.partner_code = ZTPointProduct.product.ZTPoint |
|
|
|
data.channel = ZTPointProduct.product.ZTPoint |
|
|
|
} |
|
|
|
console.log(app.globalData.list) |
|
|
|
console.log(app.globalData.list,this.data.flag) |
|
|
|
if(!app.globalData.list || app.globalData.list.length == 0){ |
|
|
|
// 判断混合下单
|
|
|
|
let use_type = product_list[0].use_type |
|
|
|
if (product_list.some(x=>x.use_type!=use_type)) { |
|
|
|
app.globalData.productPrice = (this.data.showPrice + this.data.postFee - (this.data.coupon?this.data.coupon.activity.money:0))/100; |
|
|
|
app.globalData.createDate = data |
|
|
|
wx.redirectTo({ |
|
|
|
url: '/pages/order/orderList/index?flag=mix' |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
commonApi.user_post("order/create", { |
|
|
|
data: JSON.stringify(data) |
|
|
|
}).then(res => { |
|
|
|
@ -199,14 +362,14 @@ Page({ |
|
|
|
this.setData({ |
|
|
|
kjId: null |
|
|
|
}) |
|
|
|
this.onLoad({}) |
|
|
|
// this.onLoad({})
|
|
|
|
} |
|
|
|
app.globalData.gp_id = null; |
|
|
|
app.globalData.team_id = null; |
|
|
|
this.setData({ |
|
|
|
gp_id: null |
|
|
|
}) |
|
|
|
this.onLoad({}); |
|
|
|
// this.onLoad({});
|
|
|
|
}) |
|
|
|
}else{ |
|
|
|
app.globalData.productPrice = (this.data.showPrice + this.data.postFee - (this.data.coupon?this.data.coupon.activity.money:0))/100; |
|
|
|
@ -222,7 +385,39 @@ Page({ |
|
|
|
}, |
|
|
|
getPostFee: function () { |
|
|
|
if (!this.data.address) return; |
|
|
|
let product = this.data.product, list = [], that = this; |
|
|
|
let list = [], indexList = [],that = this; |
|
|
|
let product = this.data.product.filter((x,i)=>{ |
|
|
|
if (x.user_select_type == 0) { |
|
|
|
indexList.push(i) |
|
|
|
return x |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (product.length<=0) { |
|
|
|
let postFee = 0; |
|
|
|
this.data.product.forEach(x=>{ |
|
|
|
x.postFee = 0; |
|
|
|
}) |
|
|
|
if (this.data.coupon && this.data.postFee != postFee) { |
|
|
|
wx.showToast({ |
|
|
|
title: '订单价格发生变化,请重新选择优惠券', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
app.globalData.couponInfo = null; |
|
|
|
if (!this.data.kjId && !this.data.gp_id) { |
|
|
|
this.couponCom.setNullCoupon() |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
coupon: null |
|
|
|
}) |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
postFee: postFee, |
|
|
|
product: this.data.product, |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
product.map(item => { |
|
|
|
list.push(commonApi.user_post("order/get_post_price", { |
|
|
|
sku_id: item.sku.id, |
|
|
|
@ -268,9 +463,13 @@ Page({ |
|
|
|
coupon: null |
|
|
|
}) |
|
|
|
} |
|
|
|
for(let i=0;i<indexList.length;i++) { |
|
|
|
this.data.product[indexList[i]] = product[i] |
|
|
|
} |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
postFee: postFee, |
|
|
|
product: product |
|
|
|
product: this.data.product |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|