UIAPP 购物车功能

<template>
	<view>
		<view class="empty" v-if="show==false">
			<image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309" mode="widthFix" style="width: 400rpx;"></image>
		<view class="empty-text">空空如也的购物</view>
		<view class="empty-button" @click="goshopping">去选购</view>
		</view>
		<view v-if="show==true">
			<view class="goods-detail" v-for="(item,index) in goods" :key="index">
				<view class="detail-left">
					<view class="goods-left">
						<checkbox-group @change="selected(item)">
							<label>
								<checkbox  class="selected" color="#555555" :checked="checked"/><text></text>
							</label>
						</checkbox-group>
						  <image :src="item.goodsImage" style="width: 150rpx;height: 140rpx;"></image>
					</view>
					<view class="size">
					    <text style="font-size: 25rpx;">尺码:{{item.size}}</text>
					    <text class="goods-price">¥{{item.price}}/件</text>
					</view>
				</view>
				<view class="detail-right">
					<text class="subtract" @click="reduce(item)">-</text>
					<text class="num">{{item.num}}</text>
					<text @click="add(item)" class="add">+</text>
				</view>
			</view>
		</view>
		<view class="end">
			<view class="end-left">
				<checkbox-group @change="selectgoods()">
					<label>
						<checkbox  :checked="allchecked" />全选
					</label>
				</checkbox-group>
				<view>
					总计:<text style="color: #f00;font-weight: bold;">¥ {{totalPrice}}</text>
				</view>
				</view>
				<view class="end-right">
				    结算({{totalNum}})
				</view>
			
			
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				show:true,
				 allchecked:true,
				    checked:true,
					goods:[{
						size:"女款-M",
						num:1,
						flag:true,
						price:149,
						goodsImage:"https://img0.baidu.com/it/u=4158246207,3235707994&fm=26&fmt=auto&gp=0.jpg",
					},
					{
						size:"女款-xs",
						num:1,
						flag:true,
						price:219,
						goodsImage:"https://img0.baidu.com/it/u=811765333,1656843554&fm=11&fmt=auto&gp=0.jpg",
					},
					{
						size:"女款-L",
						num:1,
						flag:true,
						price:240,
						goodsImage:"https://img1.baidu.com/it/u=233755383,2522308225&fm=26&fmt=auto&gp=0.jpg",
					},
					{
						size:"女款-XXL",
						num:1,
						flag:true,
						price:410,
						goodsImage:"https://img0.baidu.com/it/u=3894000947,2570065196&fm=26&fmt=auto&gp=0.jpg",
					},
					{
						size:"女款-XXL",
						num:1,
						flag:true,
						price:500,
						goodsImage:"https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg",
					},
					],
			}
		},
		methods:{
			goshopping(){
				uni.navigateTo({
					url:'../contact/contact'
				})
			},
			change(e){
				console.log(e)
			},
			selected(item){
				item.flag=!item.flag
				if(!item.flag){
					this.allchecked=false
					
				}else{
					const a=this.goods.forEach((item)=>{
						return item.flag===true
					})
					if(a){
						this.allchecked=true
					}else{
						this.allchecked=false
					}
				}
			},
			selectgoods(){
				this.allchecked=!this.allchecked
				if(this.allchecked){
					this.goods.map(item=>{
						this.checked=true
						item.flag=true
					})
				}else{
					this.checked=false
					this.goods.map(item=>{
						item.flag=false
					})
				}
			},
			reduce(item){
				let num=item.num
				if(num>1){
					num-=1
				}else if(num=1){
					uni.showToast({
					                    title:"该宝贝不能减少了哟~" 
					                })
				}
					
				
				item.num=num
			},
			add(item){
				let num =item.num
				item.num=num+1
			}
		},
		computed:{
			totalNum(){
				let totalNum = 0;
				this.goods.map(item => {
				    item.flag ? totalNum += item.num : totalNum += 0
				})
				return totalNum
			},
			
			totalPrice() {
			    let totalPrice = 0;
			    this.goods.map(item => {
			        item.flag ? totalPrice += item.num * item.price : totalPrice += 0
			    })
			    return totalPrice
			}
		}
	}
	
</script>

<style lang="scss">
	.goods{
		line-height: 80rpx;
		background-color: #FFFFFF;
		&-detail{
		    display: flex;
		    padding: 30rpx 15rpx 30rpx 30rpx;
		    background-color: #fff;
		    justify-content: space-between;
		    border-bottom: 5rpx solid #F1F1F1;
		    align-items: center;
		    .detail-left{
		        display: flex;
		        .goods-left{
		            display: flex;
		            align-items: center;
		        }
		    }
		    .size{
		        display: flex;
		        justify-content: space-around;
		        flex-direction: column;
		        margin-left: 30rpx;
		        .goods-price{
		            font-size: 25rpx;
		            color: #F44545;
		            
		        }
		    }
		    .detail-right{
		        text{
		            width: 50rpx;
		            line-height: 50rpx;
		            text-align: center;
		            display: inline-block;
		            background-color: #F7F7F7;
		            margin-right: 10rpx;
		        }
		        .add {
		            color: #FA4305;
		            border-radius: 10rpx 30rpx 30rpx 10rpx;
		            margin-right: 20rpx;
		        }
		        .subtract{
		            border-radius: 30rpx 10rpx 10rpx 30rpx;
		        }
		    }
		}
	}
	.empty{
		
		    position: relative;
		    top: 220rpx;
		    text-align: center;
		    display: flex;
		    align-items: center;
		    flex-direction: column;
		    &-text{
		        color: #808080;
		        margin-bottom: 50rpx;
		    }
		    &-button{
		        width: 300rpx;
		        height: 90rpx;
		        color:orange;
		        border: 1rpx solid orange;
		        text-align: center;
		        line-height: 90rpx;
		        border-radius: 48rpx;
		    }		
	}
	.end{
	    width: 100%;
	    height: 90rpx;
	    background-color:#fff;
	    position: fixed;
	    bottom: 100rpx;
	    left: 0;
	    display: flex;
	    align-items: center;
	    &-left{
	        width: 70%;
	        display: flex;
	        justify-content: space-between;
	        padding: 0 30rpx;
	        .end-flex{
	            display: flex;
	            align-items: center;
	        }
	    }
	    &-right{
	        width: 30%;
	        line-height: 90rpx;
	        background-color: #F44545;
	        text-align: center;
	        color: #fff;
	    }
	}
</style>

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黑猫大人-魏盛楠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值