购物车

This commit is contained in:
唐明明
2023-09-22 09:46:47 +08:00
parent 7ab5dfb2d8
commit 677b0d040a
15 changed files with 686 additions and 201 deletions

View File

@@ -11,20 +11,21 @@ Page({
data: {
isFixedTop : 0,
barHeight : getApp().globalData.barHeight, // 状态栏高度
goodsId : '', // 商品id
goodsData : '', // 商品数据
mallContent : '', // 商品详情
skus : [], // 显示的规格-提交
goodsId : '', // 商品id
goodsData : '', // 商品数据
mallContent : '', // 商品详情
skus : [], // 显示的规格-提交
skuid : '',
specselect : '', // 确认购买的规格
selectSkusValues: '', // 默认选项
valueId : '', // 选中规格id
valueIndex : '', // 选中规格下标index
specselect : '', // 确认购买的规格
selectSkusValues: '', // 默认选项
valueId : '', // 选中规格id
valueIndex : '', // 选中规格下标index
specselectIndex : '',
qtyNumber : 1, // 产品数量
qtyNumber : 1, // 产品数量
goodsSize : false,
invite : '',
isParent : false, // 绑定邀请码
isParent : false, // 绑定邀请码
buyType : null // 购物方式
},
/**
@@ -34,7 +35,9 @@ Page({
this.setData({
goodsId: options.id,
})
getApp().globalData.invite = options.invite || ''
if(getApp().globalData.invite == '' && options.invite){
getApp().globalData.invite = options.invite
}
},
/**
@@ -85,8 +88,8 @@ Page({
mask : true
})
wx.request({
// url : 'https://api.xhtest.douhuofalv.com/api/mall/goods/' + this.data.goodsId,
url : 'https://api.xuanhuojk.com/api/mall/goods/' + this.data.goodsId,
url : 'https://api.xhtest.douhuofalv.com/api/mall/goods/' + this.data.goodsId,
// url : 'https://api.xuanhuojk.com/api/mall/goods/' + this.data.goodsId,
header : {
"Accept" : "application/json",
"channel" : "client",
@@ -120,21 +123,6 @@ Page({
})
}
})
// wx.$api.mall.goodsSee(this.data.goodsId).then(res => {
// this.setData({
// goodsData : res.data,
// mallContent : res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'),
// skus : res.data.skus,
// skuid : res.data.skus[0].sku_id,
// selectSkusValues: res.data.skus[0],
// specselect : res.data.skus[0].unit.split('|'),
// invite : res.data.invite
// })
// }).catch(err =>{
// console.log(err)
// }).finally(() => {
// wx.hideLoading()
// })
},
/**
@@ -228,9 +216,10 @@ Page({
/**
* 规格弹出
*/
buyPop() {
buyPop(e) {
this.setData({
goodsSize: !this.data.goodsSize
goodsSize : !this.data.goodsSize,
buyType : e.currentTarget.dataset.type
})
},
@@ -239,52 +228,86 @@ Page({
*/
closeTap() {
this.setData({
goodsSize: false
goodsSize: false,
buyType : null
})
},
/**
* 确认购买
* 检查登录状态
*/
buyTap() {
// 获取登录状态
if(wx.getStorageSync("token") != ''){
let {
sku_id,
stock
} = this.data.selectSkusValues;
if (stock > 0) {
this.setData({
skuid : sku_id,
goodsSize : false
})
// 是否有推荐人
if(this.data.goodsData.has_parent) {
wx.navigateTo({
url: '/pages/mall/confirm/confirm?skuId=' + sku_id + '&qty=' + this.data.qtyNumber || 1
})
return
}
// 显示绑定手机号弹窗
this.setData({
isParent: true
})
} else {
uni.showToast({
title: '当前商品库存不足',
icon: 'none',
mask: true,
duration: 2000
})
let token = wx.getStorageSync("token") || null
if(token != null){
switch (this.data.buyType) {
case 'card':
this.orderCard()
break;
default:
this.orderBuy()
break;
}
}else{
// 去登录
wx.navigateTo({
url: "/pages/login/index"
})
}
},
/**
* 立即购买
*/
orderBuy(){
let { sku_id, stock } = this.data.selectSkusValues;
if (stock > 0) {
this.setData({
skuid : sku_id,
goodsSize : false
})
// 是否有推荐人
if(this.data.goodsData.has_parent) {
wx.navigateTo({
url: '/pages/mall/confirm/confirm?skuId=' + sku_id + '&qty=' + this.data.qtyNumber || 1
})
return
}
// 显示绑定手机号弹窗
this.setData({
isParent: true
})
} else {
uni.showToast({
title: '当前商品库存不足',
icon: 'none',
mask: true,
duration: 2000
})
}
},
/**
* 加入购物车
*/
orderCard(){
let { sku_id, stock } = this.data.selectSkusValues;
let qty = this.data.qtyNumber || 1
if (stock <= 0) {
uni.showToast({
title: '当前商品库存不足',
icon : 'none',
})
return
}
wx.showLoading({
title: '加载中...',
mask : true
})
wx.$api.bag.add({ sku_id, qty }).then(res => {
wx.showToast({
title: "已加入",
icon: "success"
})
this.closeTap()
})
},
/**
* 监听页面滑动事件