Initial Commit
This commit is contained in:
353
pages/cart/cart.js
Normal file
353
pages/cart/cart.js
Normal file
@ -0,0 +1,353 @@
|
||||
// pages/cart/cart.js
|
||||
const app = getApp();
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
checkNum: 0,//勾选数量
|
||||
checkAll: false,//全选
|
||||
cartData: [],
|
||||
login: false,
|
||||
price:0,
|
||||
|
||||
},
|
||||
|
||||
//商品详情
|
||||
goodsDetails(e) {
|
||||
let id = e.currentTarget.dataset.id;
|
||||
wx.navigateTo({
|
||||
url: '/pages/goodsDetails/goodsDetails?goodsId=' + id,
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
//去购物
|
||||
goShop(e) {
|
||||
wx.switchTab({
|
||||
url: '/pages/classify/classify'
|
||||
})
|
||||
},
|
||||
onLoad: function (options) {
|
||||
if (options.pId) {
|
||||
wx.setStorage({
|
||||
data: options.pId,
|
||||
key: 'pId',
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
wx.getStorage({
|
||||
key: 'user',
|
||||
success: s => {
|
||||
wx.showLoading({
|
||||
title: '加载中..',
|
||||
})
|
||||
wx.request({
|
||||
url: app.globalData.ip + '/wisdommining/api/goods/getCart',
|
||||
method: 'POST',
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
userId: s.data.id
|
||||
},
|
||||
success: res => {
|
||||
wx.hideLoading()
|
||||
console.log(res)
|
||||
if (res.data.code == 1) {
|
||||
this.setData({
|
||||
cartData: res.data.value,
|
||||
})
|
||||
//判断全选 数量
|
||||
this.judgeCheckAll();
|
||||
if (res.data.value.length == 0) {
|
||||
app.globalData.cartNum = '';
|
||||
wx.hideTabBarRedDot({
|
||||
index: 3
|
||||
})
|
||||
} else {
|
||||
app.globalData.cartNum = res.data.value.length.toString()
|
||||
//购物车数量显示
|
||||
wx.setTabBarBadge({
|
||||
index: 3,
|
||||
text: app.globalData.cartNum
|
||||
})
|
||||
}
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: '提示!',
|
||||
content: res.data.message,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//结算 recommendedBulyPrice
|
||||
pay() {
|
||||
let goodsList = this.data.cartData;
|
||||
let goods = [];
|
||||
|
||||
for (let i = 0; i < goodsList.length; i++) {
|
||||
goodsList[i].wisdGoods.wisdGoodsSpec.price = goodsList[i].wisdGoods.wisdGoodsSpec.specBulyPrice == null ? goodsList[i].wisdGoods.wisdGoodsSpec.specPrice : goodsList[i].wisdGoods.wisdGoodsSpec.specBulyPrice
|
||||
if (goodsList[i].check) {
|
||||
goods.push({
|
||||
isDiscount: goodsList[i].wisdGoods.isDiscount,
|
||||
goodsPhoto: goodsList[i].wisdGoods.goodsPhoto,
|
||||
goodsName: goodsList[i].wisdGoods.goodsName,
|
||||
goodsId: goodsList[i].wisdGoods.id,
|
||||
num: goodsList[i].goodsNum,
|
||||
specs: goodsList[i].wisdGoods.wisdGoodsSpec
|
||||
})
|
||||
}
|
||||
}
|
||||
if (goods.length == 0) {
|
||||
return
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/cartPay/cartPay?goods=' + JSON.stringify(goods) + '&isCar=1',
|
||||
})
|
||||
},
|
||||
|
||||
//加 减
|
||||
add(e) {
|
||||
let id = e.currentTarget.dataset.id;
|
||||
let type = e.currentTarget.dataset.type;
|
||||
let index = e.currentTarget.dataset.index;
|
||||
let cartData = this.data.cartData;
|
||||
if (type == 2 && cartData[index].goodsNum <= 1) {
|
||||
wx.showToast({
|
||||
title: '不能再减了~',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.showLoading({
|
||||
title: '加载中..',
|
||||
})
|
||||
wx.request({
|
||||
url: app.globalData.ip + '/wisdommining/api/goods/updateCartNum',
|
||||
method: 'POST',
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
id: id,
|
||||
type: type,
|
||||
},
|
||||
success: res => {
|
||||
wx.hideLoading()
|
||||
console.log(res)
|
||||
if (res.data.code == 1) {
|
||||
if(type==1){
|
||||
cartData[index].goodsNum++
|
||||
}else{
|
||||
cartData[index].goodsNum--
|
||||
}
|
||||
this.setData({
|
||||
cartData:cartData
|
||||
})
|
||||
//判断全选 数量
|
||||
this.judgeCheckAll();
|
||||
} else {
|
||||
wx.showModal({
|
||||
title: '提示!',
|
||||
content: res.data.message,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
//全选
|
||||
checkAll() {
|
||||
this.setData({
|
||||
checkAll: !this.data.checkAll,
|
||||
})
|
||||
let cartData = this.data.cartData;
|
||||
for (let i = 0; i < cartData.length; i++) {
|
||||
if (this.data.checkAll) {
|
||||
cartData[i].check = true;
|
||||
} else {
|
||||
cartData[i].check = false;
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
cartData: cartData,
|
||||
|
||||
// total: total.toFixed(2),
|
||||
// totalIntegral: total,
|
||||
})
|
||||
//判断全选 数量
|
||||
this.judgeCheckAll();
|
||||
},
|
||||
|
||||
//勾选
|
||||
check(e) {
|
||||
let index = e.currentTarget.dataset.index;
|
||||
let cartData = this.data.cartData;
|
||||
cartData[index].check = !cartData[index].check;
|
||||
this.setData({
|
||||
cartData: cartData,
|
||||
})
|
||||
//判断全选 数量
|
||||
this.judgeCheckAll();
|
||||
},
|
||||
|
||||
|
||||
|
||||
//判断全选 数量
|
||||
judgeCheckAll() {
|
||||
|
||||
let cartData = this.data.cartData;
|
||||
let all = 0;
|
||||
let checkNum = 0;
|
||||
let price = 0;
|
||||
for (let i = 0; i < cartData.length; i++) {
|
||||
if (!cartData[i].check) {
|
||||
//有未选中
|
||||
all = 1;
|
||||
} else {
|
||||
|
||||
|
||||
let p = cartData[i].wisdGoods.wisdGoodsSpec.specBulyPrice==null?cartData[i].wisdGoods.wisdGoodsSpec.specPrice:cartData[i].wisdGoods.wisdGoodsSpec.specBulyPrice
|
||||
checkNum++
|
||||
|
||||
|
||||
price = price + parseFloat((cartData[i].goodsNum*p ).toFixed(2))
|
||||
console.log(p)
|
||||
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
checkNum: checkNum,
|
||||
price:price
|
||||
})
|
||||
if (all === 0) {
|
||||
this.setData({
|
||||
checkAll: true,
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
checkAll: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
//删除
|
||||
del() {
|
||||
if (this.data.checkNum == 0) {
|
||||
wx.showToast({
|
||||
title: '请先选择商品~',
|
||||
icon: 'none',
|
||||
duration: 500
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '您确认删除当前购物车中商品么?',
|
||||
success: c => {
|
||||
if (c.confirm) {
|
||||
let shopCartId = '';
|
||||
for (var i = 0; i < this.data.cartData.length; i++) {
|
||||
if (this.data.cartData[i].check) {
|
||||
shopCartId = shopCartId + this.data.cartData[i].id + ',';
|
||||
}
|
||||
}
|
||||
// shopCartId = shopCartId.substr(1);
|
||||
console.log(shopCartId)
|
||||
wx.showLoading({
|
||||
title: '删除中..',
|
||||
mask: true,
|
||||
})
|
||||
wx.request({
|
||||
url: app.globalData.ip + '/wisdommining/api/goods/delCart',
|
||||
method: 'DELETE',
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
ids: shopCartId,
|
||||
},
|
||||
success: res => {
|
||||
console.log(res)
|
||||
wx.hideLoading()
|
||||
if (res.data.code == 1) {
|
||||
wx.showToast({
|
||||
title: '删除成功',
|
||||
success: e => {
|
||||
setTimeout(() => {
|
||||
this.onShow();
|
||||
}, 1500)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showModal({
|
||||
content: res.data.message,
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom: function () {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage: function () {
|
||||
app.share();
|
||||
return {
|
||||
path: '/pages/index/index?pId=' + app.globalData.userId,
|
||||
title: '三品慧采小程序等你来~'
|
||||
}
|
||||
},
|
||||
|
||||
})
|
4
pages/cart/cart.json
Normal file
4
pages/cart/cart.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "购物车"
|
||||
}
|
60
pages/cart/cart.wxml
Normal file
60
pages/cart/cart.wxml
Normal file
@ -0,0 +1,60 @@
|
||||
<!-- 有数据 -->
|
||||
<view wx:if='{{cartData.length>0}}'>
|
||||
<view class='data'>
|
||||
<view class="top display_J_B">
|
||||
<view class="top-l">共计{{cartData.length}}件商品</view>
|
||||
<view class="top-r" catchtap="del">删除</view>
|
||||
</view>
|
||||
<!-- 数据 -->
|
||||
<view class="cont display_J_B" wx:for='{{cartData}}' wx:key='index' data-id='{{item.goodsId}}' catchtap="goodsDetails">
|
||||
<view class="check display_A_C" catchtap="check" data-index='{{index}}'>
|
||||
<image src="{{item.check?'/icon/checked.png':'/icon/check.png'}}"></image>
|
||||
</view>
|
||||
<image class="data-img" src="{{item.wisdGoods.goodsPhoto}}"></image>
|
||||
<view class="name-price">
|
||||
<view class="name GStitleOne">{{item.wisdGoods.goodsName}}</view>
|
||||
<view class="specName GStitleOne">规格:{{item.wisdGoods.wisdGoodsSpec.specName}}</view>
|
||||
<view class="display_J_B">
|
||||
<view class="price">
|
||||
¥{{item.wisdGoods.wisdGoodsSpec.specBulyPrice==null?item.wisdGoods.wisdGoodsSpec.specPrice:item.wisdGoods.wisdGoodsSpec.specBulyPrice}}
|
||||
<text>¥{{item.wisdGoods.wisdGoodsSpec.originalPrice}}</text>
|
||||
</view>
|
||||
<view class="num display_J_B">
|
||||
<view class="num1" catchtap="add" data-index='{{index}}' data-type='2' data-id='{{item.id}}'>-</view>
|
||||
<view class="num2">{{item.goodsNum}}</view>
|
||||
<view class="num3" catchtap="add" data-index='{{index}}' data-type='1' data-id='{{item.id}}'>+</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 数据结束 -->
|
||||
</view>
|
||||
<view class="height100"></view>
|
||||
<view class="bom display_J_B display_A_C">
|
||||
<view class="bom-l display_A_C" catchtap="checkAll">
|
||||
<image src="{{checkAll?'/icon/checked.png':'/icon/check.png'}}"></image>全选
|
||||
</view>
|
||||
<!-- <view class="bom-m">已选中{{checkNum}}件商品</view> -->
|
||||
|
||||
<wxs module="filters" src="../../utils/filters.wxs"></wxs>
|
||||
<view class="bom-m" >共计:<text>¥<text >{{filters.toFix(price) }}</text> </text></view>
|
||||
<view class="{{checkNum>0?'bom-r':'bom-r__empty'}}" catchtap="pay">去结算</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 无数据 -->
|
||||
<view wx:if='{{cartData.length==0}}'>
|
||||
<view class="empty">
|
||||
<view class="empty-img"><image src="/icon/empty.png"></image></view>
|
||||
<view class="tips">暂无商品,先去添加~</view>
|
||||
<view class="goShop" catchtap="goShop">去购物</view>
|
||||
</view>
|
||||
|
||||
<view class="bom display_J_B display_A_C">
|
||||
<view class="bom-l display_A_C">
|
||||
<image src="/icon/check.png"></image>全选
|
||||
</view>
|
||||
<view class="bom-m">已选中0件商品</view>
|
||||
<view class="bom-r__empty">去结算</view>
|
||||
</view>
|
||||
</view>
|
201
pages/cart/cart.wxss
Normal file
201
pages/cart/cart.wxss
Normal file
@ -0,0 +1,201 @@
|
||||
/* pages/cart/cart.wxss */
|
||||
page {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.data {
|
||||
width: 690rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 0 30rpx;
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
.top {
|
||||
font-size: 32rpx;
|
||||
color: #333333;
|
||||
height: 80rpx;
|
||||
width: 100%;
|
||||
line-height: 80rpx;
|
||||
}
|
||||
|
||||
.cont {
|
||||
width: 100%;
|
||||
padding: 30rpx 0;
|
||||
border-bottom: 1rpx #dcdcdc solid;
|
||||
}
|
||||
|
||||
.cont:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.check {
|
||||
width: 42rpx;
|
||||
}
|
||||
|
||||
.check image {
|
||||
width: 42rpx;
|
||||
height: 42rpx;
|
||||
}
|
||||
|
||||
.data-img {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.name-price {
|
||||
padding: 10rpx 0;
|
||||
width: 430rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-content: space-between;
|
||||
}
|
||||
|
||||
.name-price>view {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.name-price .name {
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
width: 250rpx;
|
||||
}
|
||||
|
||||
.specName{
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.price {
|
||||
font-size: 36rpx;
|
||||
color: #ee7b1e;
|
||||
}
|
||||
|
||||
.price text {
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
text-decoration: line-through;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
.num1 {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: solid 2rpx #ff5502;
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
line-height: 40rpx;
|
||||
border-radius: 50%;
|
||||
color: #ff291e;
|
||||
}
|
||||
|
||||
.num3 {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
border: solid 2rpx #ee7b1e;
|
||||
background-color: #ee7b1e;
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
line-height: 40rpx;
|
||||
border-radius: 50%;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.num2 {
|
||||
font-size: 32rpx;
|
||||
color: #0b0b0b;
|
||||
height: 44rpx;
|
||||
text-align: center;
|
||||
line-height: 44rpx;
|
||||
padding: 0 25rpx;
|
||||
}
|
||||
|
||||
.bom {
|
||||
width: 690rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 100rpx;
|
||||
background-color: #ffffff;
|
||||
border-radius: 20rpx 20rpx 0rpx 0rpx;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.bom-l {
|
||||
font-size: 32rpx;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.bom-l image {
|
||||
width: 42rpx;
|
||||
height: 42rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.bom-m {
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
}
|
||||
.bom-m text{
|
||||
color: #ee7b1e;
|
||||
}
|
||||
.bom-m text text{
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.bom-r {
|
||||
width: 190rpx;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
background-image: linear-gradient(-90deg,
|
||||
#ee7b1e 0%,
|
||||
#fdae03 100%);
|
||||
border-radius: 30rpx;
|
||||
font-size: 32rpx;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 无 */
|
||||
.bom-r__empty{
|
||||
width: 190rpx;
|
||||
height: 60rpx;
|
||||
line-height: 60rpx;
|
||||
background-color: #cccccc;
|
||||
border-radius: 30rpx;
|
||||
font-size: 32rpx;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
}
|
||||
.empty{
|
||||
width: 100%;
|
||||
}
|
||||
.empty-img{
|
||||
width: 300rpx;
|
||||
height: 300rpx;
|
||||
margin: 200rpx auto 40rpx;
|
||||
}
|
||||
.empty-img image{
|
||||
width:293rpx;
|
||||
height: 317rpx;
|
||||
}
|
||||
.tips{
|
||||
font-size: 28rpx;
|
||||
letter-spacing: 3rpx;
|
||||
color: #bababa;
|
||||
text-align: center;
|
||||
}
|
||||
.goShop{
|
||||
margin: 70rpx auto 0;
|
||||
width: 180rpx;
|
||||
height: 60rpx;
|
||||
border-radius: 10rpx;
|
||||
border: solid 2rpx #ee7b1e;
|
||||
font-size: 28rpx;
|
||||
letter-spacing: 3rpx;
|
||||
color: #ee7b1e;
|
||||
text-align: center;
|
||||
line-height: 60rpx;
|
||||
}
|
Reference in New Issue
Block a user