Files
sykl-hy/pages/mall/submit/index.js

163 lines
3.8 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
goodId : '', //店铺id
skuId : '', //产品id
num : 1, //数量默认1
address : '', //地址
addressId : '', //地址id
stockData : '', //数据
amount : '', //总金额
freight : '', //运费
weight : '', //重量
remark : '', //备注
exchangeSee : false, //是否兑换
disabled : false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
goodId: options.goodsid,
skuId : options.skuid,
num : options.qty
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 获取订单前置
this.orderShow()
},
/**
* 订单前置
*/
orderShow() {
wx.$api.mall.foundOrder({
goods_sku_id: this.data.skuId,
address_id : this.data.addressId,
qty : this.data.num
}).then(res => {
this.setData({
address : res.data.address,
addressId : res.data.address.address_id,
stockData : res.data.detail,
amount : res.data.amount,
freight : res.data.freight,
weight : res.data.weight
})
}).catch(err => {})
},
/**
* 商品数量加减
*/
goodsNumber(e){
let num = this.data.num,
val = e.currentTarget.dataset.type
if (val == 'plus'){
num ++;
}else{
if (num > 1){
num --;
}else{
wx.showToast({
title : '商品数量不能小于1',
icon : 'none'
})
}
this.setData({
num: num
})
}
this.setData({
num: num
})
// 获取订单前置
this.orderShow()
},
/**
* 输入商品数量
*/
goodsNumberInput(e) {
let goodsNum = e.detail.value;
if (goodsNum > 0) {
this.setData({
num: goodsNum
})
} else {
wx.showToast({
title: '商品数量不能小于1',
icon: 'none'
});
this.setData({
num: 1
})
}
},
/**
* 是否确认兑换
*/
exchangeShow() {
this.setData({
exchangeSee: !this.data.exchangeSee
})
},
/**
* 关闭兑换弹出
*/
goodsCancel() {
this.setData({
exchangeSee: false
})
},
/**
* 确认订单
*/
goodsForm(e) {
let newQty = this.data.num
let data = {
goods_sku_id: this.data.skuId,
remark : this.data.remark,
qty : newQty,
address_id : this.data.address.address_id
}
wx.$api.mall.affirmOrder(data).then(res => {
wx.$api.mall.affirmPay(res.data.order_no).then(res => {
this.setData({
exchangeSee: false,
disabled : true
})
wx.showToast({
title: '兑换成功',
icon : 'success'
})
setTimeout(()=>{
wx.redirectTo({
url: '/pages/order/list/index?listType=paid'
})
},3000)
}).catch(err => {})
}).catch(err => {})
}
})