| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 | 
							- <template>
 
- 	<view class="content">
 
- 		<!-- 商品列表 -->
 
- 		<view class="goods-list">
 
- 			<view class="item" v-for="(item,index) in carts" :key="index">
 
- 				<label style="margin-right: 30upx;">
 
- 					<checkbox :value="item.checked"  :checked="item.checked" @click="checkChange(item)" />
 
- 				</label>
 
- 				<image class="goods-img" :src="item.productAttrImage==null||item.productAttrImage==''?item.productImage:item.productAttrImage" mode="aspectFit"></image>
 
- 				<view class="info-box">
 
- 					<view>
 
- 						<view class="title-box">
 
- 							<view class="tag">{{utils.getDictLabelName("storeProductType",item.productType)}}</view>
 
- 							<view class="title ellipsis">{{ item.productName }}</view>
 
- 						</view>
 
- 						<view class="intro ellipsis">{{item.productAttrName}}</view>
 
- 					</view>
 
- 					<view class="price-num">
 
- 						<view class="price">
 
- 							<text class="unit">¥</text>
 
- 							<text class="text">{{item.price}}</text>
 
- 						</view>
 
- 						<view class="num-box">
 
- 							<view class="img-box" @click="delNum(item)">
 
- 								<image v-if="item.cartNum <= 1" src="../../static/images/jian.png" mode=""></image>
 
- 								<image v-else src="../../static/images/jian2.png" mode=""></image>
 
- 							</view>
 
- 							<input  type="number" @change="changeNum($event,item)" :value="item.cartNum"   />
 
- 							<view class="img-box" @click="addNum(item)">
 
- 								<image src="../../static/images/add.png" mode=""></image>
 
- 							</view>
 
- 						</view>
 
- 					</view>
 
- 				</view>
 
- 			</view>
 
- 		</view>
 
- 	 
 
- 		<view v-if="carts.length == 0" class="no-data-box">
 
- 			<image src="../../static/images/no_data.png" mode="aspectFit"></image>
 
- 			<view class="empty-title">暂无数据</view>
 
- 		</view>
 
- 		<!-- 猜你喜欢 -->
 
- 		 
 
- 		<view class="like-product">
 
- 			<likeProduct  ref="product" />
 
- 		</view>
 
- 		<!-- 底部按钮 -->
 
- 		<view class="btn-foot">
 
- 			<view class="left">
 
- 				<label>
 
- 					<checkbox  :checked="checkAll" @click="handleCheckAll()" />
 
- 				</label>
 
- 				<text class="text">全选</text>
 
- 				<text class="text" @click="delCart()">删除</text>
 
- 			</view>
 
- 			<view class="right">
 
- 				<view class="total">
 
- 					<text class="label">合计:</text>
 
- 					<view class="price">
 
- 						<text class="unit">¥</text>
 
- 						<text class="num">{{totalMoney.toFixed(2)}}</text>
 
- 					</view>
 
- 				</view>
 
- 				<view class="btn" @click="submit">结算</view>
 
- 			</view>
 
- 		</view>
 
- 		
 
- 	</view>
 
- </template>
 
- <script>
 
- 	import {getCarts,cartNum,delCart} from '@/api/product'
 
- 	import likeProduct from '@/components/likeProduct.vue'
 
- 	export default {
 
- 		components: {
 
- 			likeProduct
 
- 		},	
 
- 		data() {
 
- 			return {
 
- 				 
 
- 				totalMoney:0.00,
 
- 				carts:[],
 
- 				checkAll:false,
 
- 			}	
 
- 		},
 
- 		onLoad() {
 
- 			// this.getCarts();
 
- 		},
 
- 		onShow() {
 
- 			if(uni.getStorageSync('AppToken')){
 
- 				this.getCarts();
 
- 			}
 
- 		},
 
- 		onReachBottom() {
 
- 			this.$refs.product.getGoodsProducts();
 
- 		},
 
- 		methods: {
 
- 			delCart(){
 
- 				var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
 
- 				  return ele.id
 
- 				});
 
- 				if(selectCarts.length==0){
 
- 					uni.showToast({
 
- 						icon:'none',
 
- 						title: "请选择商品删除",
 
- 					});
 
- 					return;
 
- 				}
 
- 				let data = {ids:selectCarts};
 
- 				delCart(data).then(
 
- 					res => {
 
- 						if(res.code==200){
 
- 							uni.showToast({
 
- 								icon:'success',
 
- 								title: "操作成功",
 
- 							});
 
- 							this.getCarts()
 
- 						}else{
 
- 							
 
- 							uni.showToast({
 
- 								icon:'none',
 
- 								title: res.msg,
 
- 							});
 
- 						}
 
- 					},
 
- 					rej => {}
 
- 				);
 
- 				console.log(selectCarts)
 
- 			},
 
- 			computedMoney(){
 
- 				var money=0;
 
- 				var that=this;
 
- 				this.carts.forEach((item,index,arr)=>{
 
- 					 if(item.checked){
 
- 						 money+=item.price*item.cartNum;
 
- 					 }
 
- 				})
 
- 				console.log(money);
 
- 				this.totalMoney=money;
 
- 			},
 
- 			handleCheckAll(){
 
- 				this.checkAll=!this.checkAll;
 
- 				var that=this;
 
- 				this.carts.forEach((item,index,arr)=>{
 
- 				     item.checked=that.checkAll;
 
- 				})
 
- 				this.computedMoney();
 
- 			},
 
- 			checkChange(item){
 
- 				item.checked=!item.checked;
 
- 				this.computedMoney();
 
- 			},
 
- 			changeNum(e,item) {
 
- 				item.cartNum = e.detail.value.replace(/\D/g, '')
 
- 				if (item.cartNum <= 1) {
 
- 				  uni.showToast({
 
- 				    title: "已经是底线啦!",
 
- 				    icon: "none",
 
- 				    duration: 2000
 
- 				  });
 
- 				  return;
 
- 				}
 
- 				if(item.cartNum < 1) {
 
- 					item.cartNum = 1
 
- 				}
 
- 				if(item.cartNum>=item.stock){
 
- 					item.cartNum=item.stock;
 
- 				}
 
- 				this.changeCartNum(item)
 
- 			},
 
- 			changeCartNum(item){
 
- 				let data = {number:item.cartNum,id:item.id};
 
- 				cartNum(data).then(
 
- 					res => {
 
- 						if(res.code==200){
 
- 							uni.showToast({
 
- 								icon:'none',
 
- 								title: "操作成功",
 
- 							});
 
- 							this.computedMoney();
 
- 							
 
- 						}else{
 
- 							
 
- 							uni.showToast({
 
- 								icon:'none',
 
- 								title: res.msg,
 
- 							});
 
- 						}
 
- 					},
 
- 					rej => {}
 
- 				);
 
- 			},
 
- 			getCarts(){
 
- 				getCarts().then(
 
- 					res => {
 
- 						if(res.code==200){
 
- 							 this.carts=res.carts;
 
- 							 this.carts.forEach((item,index,arr)=>{
 
- 							      item.checked=false;
 
- 							 })
 
- 							 this.computedMoney();
 
- 						}else{
 
- 							uni.showToast({
 
- 								icon:'none',
 
- 								title: "请求失败",
 
- 							});
 
- 						}
 
- 					},
 
- 					rej => {}
 
- 				);
 
- 			},
 
- 			// 购物车减法
 
- 			delNum(item) {
 
- 				if (item.cartNum <= 1) {
 
- 				  uni.showToast({
 
- 				    title: "已经是底线啦!",
 
- 				    icon: "none",
 
- 				    duration: 2000
 
- 				  });
 
- 				  return;
 
- 				}
 
- 				item.cartNum --
 
- 				if(item.cartNum < 1) {
 
- 					item.cartNum = 1
 
- 				}
 
- 				 
 
- 				this.changeCartNum(item)
 
- 			},
 
- 			// 购物车加法
 
- 			addNum(item) {
 
- 				console.log(item)
 
- 				item.cartNum++
 
- 				if(item.cartNum>=item.stock){
 
- 					item.cartNum=item.stock;
 
- 				}
 
- 				this.changeCartNum(item)
 
- 			},
 
- 			// 结算
 
- 			submit() {
 
- 				var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
 
- 				  return ele.id
 
- 				});
 
- 				if(selectCarts.length==0){
 
- 					uni.showToast({
 
- 						icon:'none',
 
- 						title: "请选择商品",
 
- 					});
 
- 					return;
 
- 				}
 
- 				uni.navigateTo({
 
- 					url: '/pages_shopping/shopping/confirmOrder?type=cart&cartIds='+selectCarts.toString()
 
- 				})
 
- 			},
 
- 			showProduct(item){
 
- 				uni.navigateTo({
 
- 					url: '/pages_shopping/shopping/productDetails?productId='+item.productId
 
- 				})
 
- 			},
 
- 		}
 
- 	}
 
- </script>
 
- <style lang="scss">
 
- 	page {
 
- 		height: 100%;
 
- 	}
 
- 	.content{
 
- 		height: 100%;
 
- 		padding: 20upx;
 
- 		.goods-list{
 
- 			.item{
 
- 				box-sizing: border-box;
 
- 				height: 221upx;
 
- 				background: #FFFFFF;
 
- 				border-radius: 16upx;
 
- 				margin-bottom: 20upx;
 
- 				padding: 30upx;
 
- 				display: flex;
 
- 				align-items: center;
 
- 				&:last-child{
 
- 					margin-bottom: 0;
 
- 				}
 
- 				.goods-img{
 
- 					width: 160upx;
 
- 					height: 160upx;
 
- 					background: #FFFFFF;
 
- 					margin-right: 30upx;
 
- 					flex-shrink: 0;
 
- 				}
 
- 				.info-box{
 
- 					height: 160upx;
 
- 					display: flex;
 
- 					flex-direction: column;
 
- 					justify-content: space-between;
 
- 					width: calc(100% - 255upx);
 
- 					.title-box{
 
- 						width: 100%;
 
- 						display: flex;
 
- 						align-items: center;
 
- 						.tag{
 
- 							padding: 0 6upx;
 
- 							height: 30upx;
 
- 							line-height: 30upx;
 
- 							font-size: 22upx;
 
- 							font-family: PingFang SC;
 
- 							font-weight: bold;
 
- 							color: #FFFFFF;
 
- 							background: linear-gradient(90deg, #2BC7B9 0%, #77cbf3 100%);
 
- 							border-radius: 4upx;
 
- 							margin-right: 10upx;
 
- 							flex-shrink: 0;
 
- 						}
 
- 						.title{
 
- 							flex: 1;
 
- 							font-size: 28upx;
 
- 							font-family: PingFang SC;
 
- 							font-weight: 500;
 
- 							color: #111111;
 
- 							line-height: 1;
 
- 						}
 
- 					}
 
- 					.intro{
 
- 						font-size: 24upx;
 
- 						font-family: PingFang SC;
 
- 						font-weight: 500;
 
- 						color: #999999;
 
- 						margin-top: 22upx;
 
- 						line-height: 1;
 
- 					}
 
- 					.price-num{
 
- 						display: flex;
 
- 						align-items: center;
 
- 						justify-content: space-between;
 
- 						.price{
 
- 							display: flex;
 
- 							align-items: flex-end;
 
- 							.unit{
 
- 								font-size: 24upx;
 
- 								font-family: PingFang SC;
 
- 								font-weight: 500;
 
- 								color: #FF6633;
 
- 								line-height: 1.2;
 
- 								margin-right: 4upx;
 
- 							}
 
- 							.text{
 
- 								font-size: 32upx;
 
- 								font-family: PingFang SC;
 
- 								font-weight: bold;
 
- 								color: #FF6633;
 
- 								line-height: 1;
 
- 							}
 
- 						}
 
- 						.num-box{
 
- 							display: flex;
 
- 							align-items: center;
 
- 							.img-box{
 
- 								width: 60upx;
 
- 								height: 60upx;
 
- 								// border-radius: 4upx;
 
- 								border: 1px solid #dddddd;
 
- 								display: flex;
 
- 								align-items: center;
 
- 								justify-content: center;
 
- 								image{
 
- 									width: 25rpx;
 
- 									height: 25rpx;
 
- 								}
 
- 							}
 
- 							input{
 
- 								width: 60upx;
 
- 								height: 60upx;
 
- 								line-height: 60upx;
 
- 								font-size: 28upx;
 
- 								font-family: PingFang SC;
 
- 								font-weight: 500;
 
- 								color: #111111;
 
- 								// border-radius: 4upx;
 
- 								border-top: 1px solid #dddddd;
 
- 								border-bottom: 1px solid #dddddd;
 
- 								text-align: center;
 
- 								// margin: 0 16upx;
 
- 							}
 
- 						}
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		.like-product{
 
- 			padding-bottom: 120upx;
 
- 		}
 
- 		.btn-foot{
 
- 			box-sizing: border-box;
 
- 			width: 100%;
 
- 			height: 121upx;
 
- 			background: #FFFFFF;
 
- 			padding: 16upx 30upx 16upx 60upx;
 
- 			display: flex;
 
- 			align-items: center;
 
- 			justify-content: space-between;
 
- 			position: fixed;
 
- 			left: 0;
 
- 			bottom: 0rpx;
 
- 			z-index: 99;
 
- 			.left{
 
- 				display: flex;
 
- 				align-items: center;
 
- 				.text{
 
- 					margin-left: 14upx;
 
- 					font-size: 28upx;
 
- 					font-family: PingFang SC;
 
- 					font-weight: 500;
 
- 					color: #666666;
 
- 					line-height: 1;
 
- 				}
 
- 			}
 
- 			.right{
 
- 				display: flex;
 
- 				align-items: center;
 
- 				.total{
 
- 					display: flex;
 
- 					align-items: flex-end;
 
- 					margin-right: 36upx;
 
- 					.label{
 
- 						font-size: 26upx;
 
- 						font-family: PingFang SC;
 
- 						font-weight: 500;
 
- 						color: #999999;
 
- 						line-height: 1.5;
 
- 					}
 
- 					.price{
 
- 						display: flex;
 
- 						align-items: flex-end;
 
- 						.unit{
 
- 							font-size: 32upx;
 
- 							font-family: PingFang SC;
 
- 							font-weight: bold;
 
- 							color: #FF6633;
 
- 							line-height: 1.2;
 
- 							margin-right: 10upx;
 
- 						}
 
- 						.num{
 
- 							font-size: 30upx;
 
- 							font-family: PingFang SC;
 
- 							font-weight: bold;
 
- 							color: #FF6633;
 
- 							line-height: 1;
 
- 						}
 
- 					}
 
- 				}
 
- 				.btn{
 
- 					width: 200upx;
 
- 					height: 88upx;
 
- 					line-height: 88upx;
 
- 					text-align: center;
 
- 					font-size: 30upx;
 
- 					font-family: PingFang SC;
 
- 					font-weight: bold;
 
- 					color: #FFFFFF;
 
- 					background: #2BC7B9;
 
- 					border-radius: 44upx;
 
- 				}
 
- 			}
 
- 		}
 
- 	}
 
- </style>
 
 
  |