105 lines
2.7 KiB
JavaScript
105 lines
2.7 KiB
JavaScript
/*
|
|
* 手太欠
|
|
* 愿这世界都如故事里一样 美好而动人~
|
|
*/
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
disabled : true, //按钮
|
|
skuId : '',
|
|
address : '', // 地址
|
|
goodskData : '', // 数据
|
|
amount : '', // 商品总金额
|
|
total : '', // 支付金额
|
|
freight : '', // 运费
|
|
weight : '', // 重量
|
|
distribution : [
|
|
{ type: 0, title: "选择配送方式" },
|
|
{ type: 1, title: "快递" },
|
|
{ type: 2, title: "自提" },
|
|
],
|
|
distributionIndex: 0
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
skuId : options.skuId
|
|
})
|
|
// 获取商品下单信息
|
|
this.placeInfo(options.skuId);
|
|
},
|
|
|
|
/**
|
|
* 配送方式选择
|
|
*/
|
|
distributionChange(e){
|
|
if(e.detail.value === this.data.distributionIndex) return
|
|
this.setData({
|
|
distributionIndex: e.detail.value
|
|
})
|
|
this.placeInfo(this.data.skuId);
|
|
},
|
|
/**
|
|
* 商品下单信息
|
|
*/
|
|
placeInfo(skuid, type) {
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
mask : true
|
|
})
|
|
wx.$api.bag.buyCarts({
|
|
cart_ids : skuid,
|
|
address_id : this.data.address.address_id || '',
|
|
delivery_type: this.data.distributionIndex
|
|
}).then(res => {
|
|
if(type != 'chooseAdd'){
|
|
this.setData({
|
|
address: res.data.address,
|
|
})
|
|
}
|
|
this.setData({
|
|
goodskData: res.data.detail,
|
|
amount : res.data.amount,
|
|
total : res.data.total,
|
|
freight : res.data.freight,
|
|
weight : res.data.weight
|
|
})
|
|
wx.hideLoading()
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 商品确认下单
|
|
*/
|
|
buyTap() {
|
|
if(this.data.distributionIndex == 0){
|
|
wx.showToast({
|
|
title: '请选择配送方式',
|
|
icon : 'none'
|
|
})
|
|
return
|
|
}
|
|
wx.showLoading({
|
|
title: '下单中...',
|
|
mask : true
|
|
})
|
|
wx.$api.bag.postCarts({
|
|
cart_ids : this.data.skuId,
|
|
address_id : this.data.address.address_id,
|
|
remark : '',
|
|
delivery_type : this.data.distributionIndex
|
|
}).then(res => {
|
|
wx.redirectTo({
|
|
url: '/pages/pay/index?params=' + encodeURIComponent(JSON.stringify(res.data))
|
|
})
|
|
wx.hideLoading()
|
|
}).catch(() =>{}).finally(() => {})
|
|
},
|
|
}) |