Procházet zdrojové kódy

购物车功能修改

LXT-NJ\Admin před 1 rokem
rodič
revize
9a03a7e0f2

+ 65 - 11
pages/gouwuche/index.vue

@@ -3,11 +3,15 @@
 		<tm-menubars title="购物车列表" :shadow="0" :showback="true"></tm-menubars>
 		<view class="zhuti shangpin" v-if="test.length>0">
 			<tm-sheet :padding="[0, 0]" class="jiaoxi xiao">
+				<view class="" style="width:100%;">
+					<tm-checkbox @change="chooseAll" v-model="checked"></tm-checkbox>{{checked?'取消全选':'全选'}}
+				</view>
 				<view v-for="item in test">
 					<tm-checkbox @change="choose" style="float: left;padding:2px !important;margin-top:9%;"
 						v-model="item.checked" label=""></tm-checkbox>
-					<tm-cartCellListFood @change="shuliangjia(item)" class="shuliang" :typeclick="typeclick"
-						:mdata="item" :cart-num.sync="item.buy"></tm-cartCellListFood>
+					<tm-cartCellListFood @change="shuliangjia(item)" v-on:jian="jian(item)" v-on:jia="jia(item)"
+						class="shuliang" :typeclick="typeclick" :mdata="item" :cart-num.sync="item.buy">
+					</tm-cartCellListFood>
 				</view>
 			</tm-sheet>
 		</view>
@@ -18,6 +22,7 @@
 				:show-right-icon="false"></tm-listitem>
 			<view class="text-align-center">
 				<!-- <tm-button theme="red" @click="qingkong()" :round="24" class="mt-50 logincla">清空</tm-button> -->
+
 				<tm-button theme="red" @click="shanchu" :round="24" class="mt-50 logincla">删除</tm-button>
 				<tm-button theme="primary" :round="24" class="mt-50 logincla" @click="goPay">立即付款</tm-button>
 			</view>
@@ -36,6 +41,8 @@
 				zongjia: 0,
 				test: [],
 				typeclick: 2, //1加入购物车,2购物车
+				checked: false,
+				number: 0
 			};
 		},
 		onLoad() {
@@ -51,6 +58,18 @@
 			this.getList()
 		},
 		methods: {
+			// ’
+			chooseAll() {
+				var data = this.test;
+				for (let i = 0; i < data.length; i++) {
+					if (this.checked) {
+						data[i].checked = true;
+					} else {
+						data[i].checked = false;
+					}
+				}
+				this.jiage()
+			},
 			// 清空
 			qingkong() {
 				let that = this;
@@ -82,15 +101,13 @@
 				for (let i = 0; i < data.length; i++) {
 					if (data[i].checked) {
 						console.log(that.zongjia, 'ss');
-						goods.push(
-							{
-								order_remark: '',
-								order_money:data[i].buy*data[i].price,
-								pay_money:data[i].buy*data[i].price,
-								buy_num: data[i].buy,
-								goods_id: data[i].goods_id,
-							}
-						)
+						goods.push({
+							order_remark: '',
+							order_money: data[i].buy * data[i].price,
+							pay_money: data[i].buy * data[i].price,
+							buy_num: data[i].buy,
+							goods_id: data[i].goods_id,
+						})
 						gw_id.push(data[i].id)
 						console.log(goods, gw_id, '下单数据');
 					}
@@ -135,6 +152,10 @@
 						console.log(ids);
 					}
 				}
+				if (ids.length == data.length) {
+					console.log(ids.length, data.length);
+					this.checked = true;
+				}
 				console.log(data, '数据');
 				if (ids.length == 0) {
 					that.$refs.toast.show({
@@ -164,12 +185,44 @@
 					}
 				})
 			},
+			jian(data) {
+				console.log(data, 'data');
+				if (data.buy >= 1) {
+					this.number = -1;
+				} else {
+					this.number = 1;
+				}
+			},
+			jia(data) {
+				this.number = 1;
+			},
+
+			// 数量增减
 			shuliangjia(num) {
+				console.log(num);
+				var that = this;
+				myRequest({
+					url: "/api/ShopCart/addShopCart",
+					method: 'post',
+					data: {
+						goods_id: num.goods_id,
+						goods_num: that.number
+					}
+				}).then(res => {
+					if (res.data.code == 200) {} else {
+						that.$refs.toast.show({
+							model: 'error',
+							label: res.data.msg
+						})
+					}
+				})
 				this.jiage();
 			},
+
 			choose() {
 				this.jiage()
 			},
+			// 总价
 			jiage() {
 				var data = this.test,
 					jiage = 0;
@@ -182,6 +235,7 @@
 				}
 				this.zongjia = jiage;
 			},
+			// /获取购物车列表
 			getList() {
 				var that = this;
 				myRequest({

+ 20 - 51
pages/shop/index.vue

@@ -88,18 +88,16 @@
 				<tm-cartCellListFood v-on:jiaruFun="jiarufuFun" v-on:goXiangQing="goXiangQing(item)"
 					v-for="item in test" :typeclick="typeclick" :mdata="item" :cart-num.sync="item.buy">
 				</tm-cartCellListFood>
-				<view class="" v-if="isBottom"
-					style="width: 100%;display: flex;justify-content: center;align-items: center;">
-					没有更多了~
-				</view>
 			</tm-sheet>
-
 		</view>
 		<view v-if="gouwuche.length!=0" class="fudong" @click="qugowuche">
 			<image src="../../static/img/87.png" mode="widthFix"></image>
 			<view class="shuzigwc">{{gouwuche.length}}</view>
 		</view>
-		<!-- <view style="width:100%;height:60px;"></view> -->
+		<view class="" v-if="isBottom" style="width: 100%;display: flex;justify-content: center;align-items: center;">
+			没有更多了~
+		</view>
+		<view style="width:100%;height:60px;"></view>
 		<!-- 弹出层消息 -->
 		<tm-message ref="toast"></tm-message>
 	</view>
@@ -131,6 +129,7 @@
 				typeclick: 1, //1加入购物车,2购物车
 				gouwuche: [],
 				page: 1,
+				total: 0
 			};
 		},
 		onLoad() {
@@ -317,9 +316,9 @@
 			},
 			// 获取推荐单品列表
 			getRecommend() {
-				this.page = 1;
+				// this.page = 1;
 				let that = this;
-				that.test = [];
+				// that.test = [];
 				myRequest({
 					url: "/api/ShopGoods/recommend",
 					method: 'get',
@@ -341,6 +340,7 @@
 								is_recommend: item.is_recommend,
 							})
 						})
+						that.total = res.data.data.count;
 					} else {
 						that.$refs.toast.show({
 							model: 'error',
@@ -351,47 +351,14 @@
 			},
 			// 加载更多
 			loadMore() {
-				if (this.isBottom) return;
-				this.page++;
-				let that = this;
-				myRequest({
-					url: "/api/ShopGoods/recommend",
-					method: 'get',
-					data: {
-						page: that.page
-					}
-				}).then(res => {
-					console.log(res.data.data);
-					if (res.data.code == 200) {
-						if (that.test.length < res.data.data.count) {
-							res.data.data.list.forEach(item => {
-								that.test.push({
-									img: item.image,
-									title: item.goods_name,
-									price: item.sale_price,
-									id: item.id,
-									category_id: item.category_id,
-									sale_num: item.sale_num,
-									stock_num: item.stock_num,
-									is_recommend: item.is_recommend,
-								})
-							})
-							console.log(that.test, '下拉架子啊');
-						} else {
-							that.isBottom = true;
-							that.page--;
-						}
-					} else {
-						that.page--;
-						that.isBottom = false;
-						that.$refs.toast.show({
-							model: 'error',
-							label: res.data.msg
-						})
-					}
-				})
+				if (this.test.length < this.total) {
+					this.isBottom = false;
+					this.page++;
+					this.getRecommend()
+				} else {
+					this.isBottom = true;
+				}
 			},
-
 			tiaozhuan() {
 				uni.navigateTo({
 					url: "/pages/gengduo/index",
@@ -435,6 +402,8 @@
 				this.$refs.a_1.play()
 				this.current = this.current - 1;
 			},
+
+			// 加入购物车
 			jiarufuFun(data) {
 				var that = this;
 				console.log(data)
@@ -444,9 +413,9 @@
 						method: 'post',
 						data: {
 							goods_id: data.data.id,
-							goods_name: data.data.title,
-							goods_image: data.data.img,
-							goods_price: data.data.price,
+							// goods_name: data.data.title,
+							// goods_image: data.data.img,
+							// goods_price: data.data.price,
 							goods_num: 1
 						}
 					}).then(res => {

+ 19 - 89
pages/shopdetail/index.vue

@@ -69,8 +69,7 @@
 				</view>
 				<view style="clear: both;"></view>
 
-				<view class="bottom-end" v-if="isEnd || listdata.length==0">
-					没有更多~</view>
+				<view class="bottom-end" v-if="isEnd || listdata.length==0">没有更多~</view>
 				<view v-else style="clear: both;" class="more ma-40 pt-40" @click="gengmore()">
 					<image src="/static/img/30.png" mode="widthFix"></image>
 					<text class="text-size-s">下拉加载更多~</text>
@@ -100,11 +99,12 @@
 		data() {
 			return {
 				isEnd: false,
-				// 商品的id
+				// id
 				ids: '',
 				// 分类id
 				classId: '',
 				page: 1,
+				total: 0,
 				showList: ['名称', '款式', '商品编号', '尺寸', '货号'],
 				xianshi: true,
 				swipList: [],
@@ -138,9 +138,9 @@
 
 		},
 		methods: {
-			// 详情数据
+			// 获取详情
 			getDetail() {
-				console.log(this.ids,'ids');
+				console.log(this.ids, 'ids');
 				let that = this;
 				myRequest({
 					url: "/api/ShopGoods/getShopGoodsDetail",
@@ -161,11 +161,10 @@
 					}
 				})
 			},
+
 			// 猜你喜欢
 			getLike() {
-				this.page = 1;
 				let that = this;
-				that.listdata = [];
 				myRequest({
 					url: "/api/ShopGoods/getRecommendGoods",
 					method: 'get',
@@ -185,9 +184,9 @@
 								jiage: item.sale_price,
 								id: item.id,
 								category_id: item.category_id
-
 							})
 						})
+						that.total = res.data.data.count;
 					} else {
 						that.$refs.toast.show({
 							model: 'error',
@@ -197,49 +196,17 @@
 				})
 			},
 
-			// 点击加载更多
+			// 喜欢加载更多
 			gengmore() {
-				if (this.isEnd) return;
-				this.page++;
-				let that = this;
-				myRequest({
-					url: "/api/ShopGoods/getRecommendGoods",
-					method: 'get',
-					data: {
-						goods_id: that.ids,
-						category_id: that.cartId,
-						page: that.page
-					}
-				}).then(res => {
-					if (res.data.code == 200) {
-						console.log(res.data.data, '更多');
-						console.log(that.listdata, '33');
-						if (that.listdata.length < res.data.data.count) {
-							res.data.data.list.forEach(item => {
-								that.listdata.push({
-									image: item.image,
-									text: item.goods_name,
-									xiaol: item.sale_num,
-									jiage: item.sale_price,
-									id: item.id,
-									category_id: item.category_id
-								})
-							})
-						} else {
-							that.page--;
-							that.isEnd = true;
-						}
-
-					} else {
-						that.$refs.toast.show({
-							model: 'error',
-							label: res.data.msg
-						})
-					}
-				})
+				if (this.listdata.length < this.total) {
+					this.isEnd = false;
+					this.page++;
+					this.getLike()
+				} else {
+					this.isEnd = true;
+				}
 			},
-
-			// 喜欢的详情
+			// 喜欢内容点击去详情
 			goDetail(data) {
 				uni.navigateTo({
 					url: "/pages/shopdetail/index?cartId=" + data.id + '&classId=' + data.category_id,
@@ -264,9 +231,9 @@
 					method: 'post',
 					data: {
 						goods_id: item ? item.id : that.details.id,
-						goods_name: item ? item.text : that.details.goods_name,
-						goods_image: item ? item.image : that.details.image,
-						goods_price: item ? item.jiage : that.details.sale_price,
+						// goods_name: item ? item.text : that.details.goods_name,
+						// goods_image: item ? item.image : that.details.image,
+						// goods_price: item ? item.jiage : that.details.sale_price,
 						goods_num: 1
 					}
 				}).then(res => {
@@ -285,43 +252,6 @@
 				})
 			},
 
-			//加入购物车
-			goBar() {
-				var that = this;
-				// console.log(data)
-				// if (data.type == 2) {
-				myRequest({
-					url: "/api/ShopCart/addShopCart",
-					method: 'post',
-					data: {
-						goods_id: that.details.id,
-						goods_name: that.details.title,
-						goods_image: that.details.img,
-						goods_price: that.details.price,
-						goods_num: 1
-					}
-				}).then(res => {
-					if (res.data.code == 200) {
-						that.$refs.toast.show({
-							model: 'success',
-							label: res.data.msg
-						})
-						that.getGwc()
-					} else {
-						that.$refs.toast.show({
-							model: 'error',
-							label: res.data.msg
-						})
-					}
-				})
-				// } 
-				// else {
-				// 	uni.navigateTo({
-				// 		url: "/pages/shopdetail/index?id=" + data.id,
-				// 	})
-				// }
-			},
-
 			// 立即购买
 			goBuy() {
 				console.log('购买');

+ 10 - 27
pages/sort/index.vue

@@ -9,7 +9,7 @@
 						<view class="pa-15 text-size-s">
 							<view class="text-overflow-2">
 								<text class="text-size-lg">{{item.goods_name}}</text>
-								<view class="text-gray mt-6">销量:{{item.stock_num}}</view>
+								<view class="text-gray mt-6">销量:{{item.sale_num}}</view>
 							</view>
 							<view class="mt-2 flex-between flex-center">
 								<view class="touxiang mt-30">
@@ -62,30 +62,15 @@ export default {
 		this.getSort()
 	},
 	methods: {
+		// 加载更多
 		gengmore(){
-			this.page++;
-			let that=this;
-			myRequest({
-				url:'/api/ShopGoods/childrenClassificationList',
-				method:'post',
-				data:{id:that.soId,page:that.page,pagesize:that.pagesize}
-			}).then(res=>{
-				if(res.data.code==200){
-					if(res.data.data.length<res.data.data.total){
-						console.log(res.data.data,'liebiao');
-						// that.total=res.data.data.total;
-						that.listdata=that.listdata.concat(res.data.data.data);
-					}else{
-						that.page--;
-					}
-				}else{
-					that.$refs.toast.show({
-						model: 'error',
-						label: res.data.msg
-					})
-				}
-			})
+			if(this.listdata.length<this.total){
+				this.page++;
+				this.getSort();
+			}else{
+			}
 		},
+		// 加入购物车
 		jiarufuFun(data){
 			let that=this;
 			myRequest({
@@ -108,9 +93,8 @@ export default {
 			// console.log(data)
 			// this.gouwuche.push(data)
 		},
+		// 获取列表数据
 		getSort(){
-			this.page=1;
-			this.pagesize=8;
 			let that=this;
 			myRequest({
 				url:'/api/ShopGoods/childrenClassificationList',
@@ -136,13 +120,12 @@ export default {
 		goindex(){
 			uni.navigateBack();
 		},
-		
+		// 去详情
 		goDetail(data){
 			uni.navigateTo({
 				url:'/pages/shopdetail/index?cartId='+data.id+'&classId='+data.category_id
 			})
 		},
-		
 		change(e){
 			console.log(e)
 		},

+ 40 - 29
tm-vuetify/components/tm-cartCellListFood/tm-cartCellListFood.vue

@@ -15,9 +15,9 @@
 		<view class="tm-cartCellListFood-r fulled ">
 			<view class="pl-15">
 				<view class="title  text-size-s text-weight-b text-overflow-2" style="line-height: 32rpx;"
-					:class="[black_tmeme ? 'bk' : '',]" >
+					:class="[black_tmeme ? 'bk' : '',]">
 					{{mdata[keyMap['title']]}}
-					<image v-if="typeclick==4" class="shanchu" src="/static/img/94.png" @click="shanchu(mdata)"  ></image>
+					<image v-if="typeclick==4" class="shanchu" src="/static/img/94.png" @click="shanchu(mdata)"></image>
 				</view>
 				<view style="min-height: 64rpx;">
 					<view v-if="!dense&&mdata[keyMap['label']]"
@@ -34,7 +34,8 @@
 				</view>
 				<view class="tm-cartCellListFood-price flex-between">
 					<view>
-						<text class="text-size-xs text-red" v-if="typeclick!=7 && typeclick!=6  && typeclick!=8">¥</text>
+						<text class="text-size-xs text-red"
+							v-if="typeclick!=7 && typeclick!=6  && typeclick!=8">¥</text>
 						<text v-if="typeclick!=7 && typeclick!=6 && typeclick!=8"
 							class="text-size-n text-red text-weight-b px-5">{{mdata[keyMap['price']]}}</text>
 						<text v-if="mdata[keyMap['unit']]"
@@ -46,11 +47,11 @@
 						<image class="" src="/static/img/86.png"></image>
 					</view>
 					<view class="flex" v-if="typeclick==2">
-						<block v-if="cNum>0">
-							<view :style="{
+						<block>
+							<view  v-if="cNum>1" :style="{
 							width:`${actionSize}rpx`,
 							height:`${actionSize}rpx`,
-						}" :class="[color,black_tmeme ? 'bk' : '',]" @click="jian"
+						}" :class="[color,black_tmeme ? 'bk' : '',]" @click.stop="jian"
 								class="tm-cartCellListFood-actions rounded  flex-center outlined">
 								<text class="iconfont icon-minus text-size-xxs"></text>
 							</view>
@@ -59,7 +60,7 @@
 						<view :style="{
 							width:`${actionSize}rpx`,
 							height:`${actionSize}rpx`,
-						}" :class="[color,`border-${color}-a-1`,black_tmeme ? 'bk' : '',]" @click="jia"
+						}" :class="[color,`border-${color}-a-1`,black_tmeme ? 'bk' : '',]" @click.stop="jia"
 							class="tm-cartCellListFood-actions rounded  flex-center ">
 							<text class="iconfont icon-plus text-size-xs"></text>
 						</view>
@@ -72,8 +73,9 @@
 							<view class="fukuan" @click="goPay(mdata,0)">去付款</view>
 						</view>
 						<view class="flex" v-if="mdata[keyMap['orderStatus']]==1 ||mdata[keyMap['orderStatus']]==2">
-							<view class="fukuan mr-10" @click="goBuy(mdata,1)">再次购买</view>	
-							<view class="fukuan" @click="goSure(mdata,1)" v-if="mdata[keyMap['orderStatus']]==1">确认收货</view>						
+							<view class="fukuan mr-10" @click="goBuy(mdata,1)">再次购买</view>
+							<view class="fukuan" @click="goSure(mdata,1)" v-if="mdata[keyMap['orderStatus']]==1">确认收货
+							</view>
 							<view class="fukuan" @click="goEval(mdata,2)"
 								v-if="mdata[keyMap['orderStatus']]==2 && mdata[keyMap['isEval']]== 0 ">去评价</view>
 							<!-- <view class="fukuan" @click="goEvalList(mdata,2)"
@@ -91,7 +93,7 @@
 					<view style="position: absolute;right: 20px;" v-if="typeclick==7">
 						<view class="genghuan mr-10" @click="genghuan(mdata,1)">更换</view>
 					</view>
-					<view style="position: absolute;right: 20px;" v-if="typeclick==8">				
+					<view style="position: absolute;right: 20px;" v-if="typeclick==8">
 					</view>
 				</view>
 			</view>
@@ -156,7 +158,7 @@
 						buy: 'buy',
 						size: 'size',
 						orderStatus: 'orderStatus',
-						isEval:'isEval'
+						isEval: 'isEval'
 					}
 				}
 			},
@@ -234,7 +236,7 @@
 		},
 		data() {
 			return {
-				cNum: 0,
+				cNum: 1,
 			};
 		},
 		mounted() {
@@ -242,46 +244,46 @@
 		},
 		methods: {
 			// 点击详情
-			goXiangQing(data){
-				console.log(data,'详情数据');
+			goXiangQing(data) {
+				console.log(data, '详情数据');
 				this.$emit('goXiangQing', {
 					data: data
 				});
 			},
 			// 删除订单
-			shanchu(data){
-				console.log(data,'3');
+			shanchu(data) {
+				console.log(data, '3');
 				this.$emit('shanchu', {
 					data: data
 				});
 			},
 			// 付款
-			goPay(data,type){
+			goPay(data, type) {
 				console.log(data);
 			},
 			// 评价
-			goEval(data,type){
-				console.log(data,type);
+			goEval(data, type) {
+				console.log(data, type);
 				this.$emit('Eval', {
 					data: data,
 					type: 2
 				});
 			},
-			goEvalList(data,type){},
+			goEvalList(data, type) {},
 			// 确认收货
-			goSure(data,type){
+			goSure(data, type) {
 				console.log(data);
 				this.$emit('sure', {
 					data: data,
 					type: 1
 				});
-				
+
 			},
 			//购买 
-			goBuy(data,type){
+			goBuy(data, type) {
 				console.log(data);
 			},
-			
+
 			jiaru(data) {
 				this.$emit('jiaruFun', {
 					data: data,
@@ -307,18 +309,27 @@
 					type: 1
 				});
 			},
-			jian() {
+			jian(data) {
 				const buyNum = this.cNum;
 				if (buyNum <= 0) {
-					this.cart_num = 0;
+					this.cart_num = 1;
 					return
+				} else {
+					this.cart_num = buyNum - 1
 				}
-				this.cart_num = buyNum - 1
+				this.$emit('jian', {
+					data: data,
+					type: 2
+				});
 			},
-			jia() {
+			jia(data) {
+				this.$emit('jian', {
+					data: data,
+					type: 2
+				});
 				const buyNum = this.cNum;
 				this.cart_num = parseInt(buyNum) + 1
-			},	
+			},
 		}
 	}
 </script>