You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							369 lines
						
					
					
						
							9.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							369 lines
						
					
					
						
							9.8 KiB
						
					
					
				
								<template>
							 | 
						|
									<view>
							 | 
						|
										<lf-nav :spreadOut="true" :showIcon="true" bgColor="white" title="购物车"></lf-nav>
							 | 
						|
										<view style="height: 1rpx;"></view>
							 | 
						|
										<view>
							 | 
						|
											<view v-for="(s_item, s_index) in list" :key="s_index" class="online-card">
							 | 
						|
												<view class="lf-m-b-20" @click="$url('/pages/shop/shopdetail?id='+ s_item.id)">
							 | 
						|
													<text class="lf-iconfont icon-Group- lf-font-28"></text>
							 | 
						|
													<text class="lf-color-black lf-font-28 lf-font-bold lf-m-l-10">{{ s_item.name }}</text>
							 | 
						|
													<text class="lf-iconfont icon-xiangyou lf-font-24 lf-m-l-10"></text>
							 | 
						|
												</view>
							 | 
						|
												<view class="lf-row-between" v-if="s_item.full_minus">
							 | 
						|
													<view class="lf-flex">
							 | 
						|
														<view class="gray-tag">满减</view>
							 | 
						|
														<view class="lf-m-l-15 lf-font-24 lf-color-333">{{s_item.full_minus}}</view>
							 | 
						|
													</view>
							 | 
						|
													<view class="red-tag" @click="$msg('敬请期待')">去凑单</view>
							 | 
						|
												</view>
							 | 
						|
												<!-- 单个商品信息,增加滑动删除 -->
							 | 
						|
												<view v-for="(g_item, g_index) in s_item.goods" :key="g_index">
							 | 
						|
													<lf-swipe-action :options="options" :index="g_index" :show="show" @button="onButton($event, s_index, g_index)">
							 | 
						|
														<view class="lf-row-between">
							 | 
						|
															<u-checkbox-group>
							 | 
						|
																<u-checkbox shape="circle" active-color="#15716E" @change="goodsCheckChange($event, s_index, g_index)"  v-model="g_item.checked"></u-checkbox>
							 | 
						|
															</u-checkbox-group>
							 | 
						|
															<view class="lf-m-t-30" style="display: flex;">
							 | 
						|
																<image class="content-img" :src="g_item.img"  @click="$url('/pages/shop/goodsdetail?id='+ g_item.com_id)"></image>
							 | 
						|
																<view class="lf-m-l-15 content-info">
							 | 
						|
																	<view class="lf-color-333 lf-font-26 lf-line-2" style="max-width: 480rpx;">
							 | 
						|
																		<text>{{g_item.name}}</text>
							 | 
						|
																		<text class="lf-m-l-10">{{g_item.color ? g_item.color+' ' : ''}}</text>
							 | 
						|
																		<text>{{g_item.size ? g_item.size : ''}}</text>
							 | 
						|
																	</view>
							 | 
						|
																	<!-- <view class="lf-font-24 lf-color-777 lf-m-t-14">
							 | 
						|
																		<view>{{g_item.qty ? g_item.qty+'件;' : ''}}{{g_item.color ? g_item.color+';' : ''}}{{g_item.size ? g_item.size : ''}}</view>
							 | 
						|
																	</view> -->
							 | 
						|
																	<view class="lf-row-between">
							 | 
						|
																		<view class="lf-font-32 lf-color-price" style="line-height: 1;">¥{{ g_item.price }}</view>
							 | 
						|
																		<view class="lf-flex">
							 | 
						|
																			<view class="num-btn" @click="changeNum('less', s_index, g_index)">
							 | 
						|
																				<text class="lf-iconfont icon-jian1 lf-font-30"></text>
							 | 
						|
																			</view>
							 | 
						|
																			<view>
							 | 
						|
																				<input class="input" :value="g_item.qty" :disabled="true" />
							 | 
						|
																			</view>
							 | 
						|
																			<view class="num-btn lf-text-right" @click="changeNum('add', s_index, g_index)">
							 | 
						|
																				<text class="lf-iconfont icon-jia lf-font-30"></text>
							 | 
						|
																			</view>
							 | 
						|
																		</view>
							 | 
						|
																	</view>
							 | 
						|
																</view>
							 | 
						|
															</view>
							 | 
						|
														</view>
							 | 
						|
													</lf-swipe-action>
							 | 
						|
												</view>
							 | 
						|
											</view>
							 | 
						|
											<view class="loading-more" v-if="list.length == 0">
							 | 
						|
												<lf-nocontent src="/static/images/empty-cart.png"></lf-nocontent>
							 | 
						|
											</view>
							 | 
						|
										</view>
							 | 
						|
										<view style="height: 60rpx;"></view>
							 | 
						|
										<view class="cart-bottom">
							 | 
						|
											<u-checkbox-group>
							 | 
						|
												<u-checkbox shape="circle" active-color="#15716E" @change="allCheckChange"  v-model="allChecked">
							 | 
						|
													<text class="lf-font-28 lf-color-777">全选</text>
							 | 
						|
												</u-checkbox>
							 | 
						|
											</u-checkbox-group>
							 | 
						|
											<view class="lf-row-between">
							 | 
						|
												<view class="lf-font-32 lf-color-222 lf-font-bold lf-m-r-30">
							 | 
						|
													合计: ¥{{ total_price || 0 }}
							 | 
						|
												</view>
							 | 
						|
												<view class="cart-btn" hover-class="lf-opacity" @click="submit">
							 | 
						|
													<text>结算</text>
							 | 
						|
													<text v-if="total_count">({{ total_count }})</text>
							 | 
						|
												</view>
							 | 
						|
											</view>
							 | 
						|
										</view>
							 | 
						|
									</view>
							 | 
						|
								</template>
							 | 
						|
								
							 | 
						|
								<script>
							 | 
						|
									import lfSwipeAction from '@/components/lf-swipeAction/lf-swipeAction.vue';
							 | 
						|
									import Bigc from '@/common/js/bigc.js';
							 | 
						|
									export default {
							 | 
						|
										components: {
							 | 
						|
											lfSwipeAction
							 | 
						|
										},
							 | 
						|
										data() {
							 | 
						|
											return {
							 | 
						|
												token: '', // 用户token
							 | 
						|
												allChecked: false, // 全选
							 | 
						|
												list: [], // 购物车列表
							 | 
						|
												total_price: '', // 总金额
							 | 
						|
												total_count: '', // 总数量
							 | 
						|
												options: [{
							 | 
						|
								                    text: '删除',
							 | 
						|
								                    style: {
							 | 
						|
								                        backgroundColor: '#dd524d'
							 | 
						|
								                    }
							 | 
						|
								                },{
							 | 
						|
								                    text: '取消',
							 | 
						|
								                    style: {
							 | 
						|
								                        backgroundColor: '#15716E'
							 | 
						|
								                    }
							 | 
						|
								                }],
							 | 
						|
												show: false,
							 | 
						|
												show_count: 0
							 | 
						|
											}
							 | 
						|
										},
							 | 
						|
										watch: {
							 | 
						|
											list: {
							 | 
						|
												deep: true,
							 | 
						|
												handler: function(val){
							 | 
						|
													let total_count = 0;
							 | 
						|
													let total_price = new Bigc(0);
							 | 
						|
													val.map(s => {
							 | 
						|
														s.goods.map(g => {
							 | 
						|
															if(g.checked){
							 | 
						|
																total_count++;
							 | 
						|
																let itemPrice = new Bigc(g.price).times(g.qty);
							 | 
						|
																total_price = total_price.plus(itemPrice);
							 | 
						|
															}
							 | 
						|
														})
							 | 
						|
													})
							 | 
						|
													this.total_count = total_count;
							 | 
						|
													this.total_price = total_price;
							 | 
						|
												}
							 | 
						|
											}
							 | 
						|
										},
							 | 
						|
										onLoad(){
							 | 
						|
											this.token = this.$cookieStorage.get('user_token');
							 | 
						|
											this.getCartList();
							 | 
						|
										},
							 | 
						|
										onShow(){
							 | 
						|
											this.show_count++;
							 | 
						|
											if(this.show_count > 1){
							 | 
						|
												this.allChecked = false;
							 | 
						|
												this.total_price = '';
							 | 
						|
												this.total_count = '';
							 | 
						|
												this.getCartList();
							 | 
						|
											}
							 | 
						|
										},
							 | 
						|
										methods: {
							 | 
						|
											// 购物车商品加减
							 | 
						|
											changeNum(type, parentIndex, childIndex){
							 | 
						|
												let goodsItem = this.list[parentIndex].goods[childIndex];
							 | 
						|
												if(type == 'add'){
							 | 
						|
													if(goodsItem.qty < 10){
							 | 
						|
														goodsItem.qty++;
							 | 
						|
													}else{
							 | 
						|
														return;
							 | 
						|
													}
							 | 
						|
												}else if(type == 'less'){
							 | 
						|
													if(goodsItem.qty > 1){
							 | 
						|
														goodsItem.qty--;
							 | 
						|
													}else{
							 | 
						|
														return;
							 | 
						|
													}
							 | 
						|
												}
							 | 
						|
												let __raw_id = goodsItem.__raw_id;
							 | 
						|
												this.$http.ajax({
							 | 
						|
													api: 'api/shopping/cart/'+ __raw_id,
							 | 
						|
													method: 'PUT',
							 | 
						|
													header: {
							 | 
						|
													  Authorization: this.token
							 | 
						|
													},
							 | 
						|
													data: {
							 | 
						|
														attributes: {
							 | 
						|
															qty: goodsItem.qty
							 | 
						|
														}
							 | 
						|
													}
							 | 
						|
												}).then(res => {
							 | 
						|
													if(!res.data.status){
							 | 
						|
														this.$msg('购物车更新失败', {icon: 'error'});
							 | 
						|
													}
							 | 
						|
												})
							 | 
						|
											},
							 | 
						|
											getCartList(){
							 | 
						|
												uni.showLoading({
							 | 
						|
													title: '正在查询购物车'
							 | 
						|
												})
							 | 
						|
												this.$http.get({
							 | 
						|
													api: 'api/cart',
							 | 
						|
													header: {
							 | 
						|
														Authorization: this.token
							 | 
						|
													}
							 | 
						|
												}).then(res => {
							 | 
						|
													console.log("===", res);
							 | 
						|
													uni.hideLoading();
							 | 
						|
													let data = res.data.data;
							 | 
						|
													let list = [];
							 | 
						|
													for(let i in data){
							 | 
						|
														let goods = data[i].goods.map(item => {
							 | 
						|
															item.checked = false;
							 | 
						|
															return item;
							 | 
						|
														})
							 | 
						|
														list.push({
							 | 
						|
															name: data[i].name,
							 | 
						|
															full_minus: '',
							 | 
						|
															goods: goods,
							 | 
						|
															id: data[i].id
							 | 
						|
														})
							 | 
						|
													}
							 | 
						|
													this.list = list;
							 | 
						|
												}).catch(err => uni.hideLoading())
							 | 
						|
											},
							 | 
						|
											// 商品被勾选
							 | 
						|
											goodsCheckChange(event, parentIndex, childIndex) {
							 | 
						|
												this.list[parentIndex].goods[childIndex].checked = event.value;
							 | 
						|
												let check_list = this.list.map(item => {
							 | 
						|
													return item.goods.every(g => g.checked);
							 | 
						|
												});
							 | 
						|
												this.allChecked = check_list.every(a => a);
							 | 
						|
											},
							 | 
						|
											// 全选被改变
							 | 
						|
											allCheckChange(event){
							 | 
						|
												this.allChecked = event.value;
							 | 
						|
												this.list.forEach(s => {
							 | 
						|
													s.goods.forEach(g => {
							 | 
						|
														g.checked = event.value;
							 | 
						|
													})
							 | 
						|
												})
							 | 
						|
											},
							 | 
						|
											// 结算
							 | 
						|
											submit(){
							 | 
						|
												if(this.total_count){
							 | 
						|
													let brand = [];
							 | 
						|
													let cart_ids = [];
							 | 
						|
													this.list.map(item => {
							 | 
						|
														let checked = item.goods.every(g => g.checked);
							 | 
						|
														item.goods.map(g => {
							 | 
						|
															if(g.checked){
							 | 
						|
																cart_ids.push(g.__raw_id);
							 | 
						|
															}
							 | 
						|
														})
							 | 
						|
														if(checked){
							 | 
						|
															brand.push(item.name);
							 | 
						|
														}
							 | 
						|
													})
							 | 
						|
													if(brand.length > 1){
							 | 
						|
														this.$msg('只支持单个店铺结算哦');
							 | 
						|
													}else{
							 | 
						|
														let par = {
							 | 
						|
															cart_ids: cart_ids,
							 | 
						|
															type: "normal",
							 | 
						|
															wechat_group_id: ""
							 | 
						|
														};
							 | 
						|
														this.$cookieStorage.set('order_confirm', par);
							 | 
						|
														this.$url('/pages/order/confirm/confirm');
							 | 
						|
													}
							 | 
						|
												}else{
							 | 
						|
													this.$msg('您未选择需要结算的商品');
							 | 
						|
												}
							 | 
						|
											},
							 | 
						|
											// 滑动组件,按钮被点击
							 | 
						|
											onButton(event, parentIndex, childIndex){
							 | 
						|
												if(event.buttonIndex == 0){
							 | 
						|
													let __raw_id = this.list[parentIndex].goods[childIndex].__raw_id;
							 | 
						|
													uni.showModal({
							 | 
						|
														title: '温馨提示',
							 | 
						|
														content: '确定移除该商品吗?',
							 | 
						|
														success: result => {
							 | 
						|
															if(result.confirm){
							 | 
						|
																uni.showLoading({
							 | 
						|
																	title: '正在删除'
							 | 
						|
																})
							 | 
						|
																this.$http.ajax({
							 | 
						|
																	api: 'api/shopping/cart/'+ __raw_id,
							 | 
						|
																	method: 'DELETE',
							 | 
						|
																	header: {
							 | 
						|
																		Authorization: this.token
							 | 
						|
																	}
							 | 
						|
																}).then(res => {
							 | 
						|
																	if(res.data.code == 200){
							 | 
						|
																		this.$msg('删除成功', {icon: 'success'}).then(() => {
							 | 
						|
																			this.list[parentIndex].goods.splice(childIndex, 1);
							 | 
						|
																			if(this.list[parentIndex].goods.length <= 0){
							 | 
						|
																				this.list.splice(parentIndex, 1);
							 | 
						|
																			}
							 | 
						|
																		})
							 | 
						|
																	}else{
							 | 
						|
																		this.$msg('删除失败', {icon: 'error'});
							 | 
						|
																	}
							 | 
						|
																	uni.hideLoading();
							 | 
						|
																}).catch(err => uni.hideLoading())
							 | 
						|
															}
							 | 
						|
														}
							 | 
						|
													})
							 | 
						|
												}
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
								</script>
							 | 
						|
								
							 | 
						|
								<style>
							 | 
						|
									page {
							 | 
						|
										background-color:  #F8F8F8;
							 | 
						|
									}
							 | 
						|
								</style>
							 | 
						|
								
							 | 
						|
								<style scoped lang="scss">
							 | 
						|
									.cart-btn {
							 | 
						|
										display: flex;
							 | 
						|
										justify-content: center;
							 | 
						|
										align-items: center;
							 | 
						|
										width: 200rpx;
							 | 
						|
										height: 80rpx;
							 | 
						|
										background: #15716E;
							 | 
						|
										border-radius: 40rpx;
							 | 
						|
										color: #FFFFFF;
							 | 
						|
										font-size: 28rpx;
							 | 
						|
									}
							 | 
						|
									.cart-bottom {
							 | 
						|
										display: flex;
							 | 
						|
										justify-content: space-between;
							 | 
						|
										width: 750rpx;
							 | 
						|
										height: 120rpx;
							 | 
						|
										background: #FFFFFF;
							 | 
						|
										position: fixed;
							 | 
						|
										bottom: 0;
							 | 
						|
										padding: 32rpx;
							 | 
						|
									}
							 | 
						|
									.gray-tag {
							 | 
						|
										border-radius: 2rpx;
							 | 
						|
										border: 1rpx solid #979797;
							 | 
						|
										color: #777;
							 | 
						|
										padding: 0 6rpx;
							 | 
						|
										font-size: 20rpx;
							 | 
						|
										width: max-content;
							 | 
						|
									}
							 | 
						|
									.red-tag {
							 | 
						|
										font-size: 20rpx;
							 | 
						|
										color: #F63434;
							 | 
						|
									}
							 | 
						|
									.content-img {
							 | 
						|
										width: 130rpx;
							 | 
						|
										height: 130rpx;
							 | 
						|
										border-radius: 5rpx;
							 | 
						|
									}
							 | 
						|
									.content-info{
							 | 
						|
										width: 410rpx;
							 | 
						|
										display: flex;
							 | 
						|
										flex-direction: column;
							 | 
						|
										justify-content: space-between;
							 | 
						|
									}
							 | 
						|
									.online-card {
							 | 
						|
										width: 686rpx;
							 | 
						|
										height: auto;
							 | 
						|
										background: #FFFFFF;
							 | 
						|
										border-radius: 20rpx;
							 | 
						|
										// margin-bottom: 30rpx;
							 | 
						|
										padding: 30rpx;
							 | 
						|
										margin: 30rpx auto;
							 | 
						|
										overflow: hidden;
							 | 
						|
										&:last-child {
							 | 
						|
											margin-bottom: 150rpx;
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
									.num-btn{
							 | 
						|
										width: 36rpx;
							 | 
						|
									}
							 | 
						|
									.input{
							 | 
						|
										width: 40rpx;
							 | 
						|
										height: 45rpx;
							 | 
						|
										border-radius: 2rpx;
							 | 
						|
										background-color: #F3F8F7;
							 | 
						|
										text-align: center;
							 | 
						|
									}
							 | 
						|
								</style>
							 |