zs 2 vuotta sitten
vanhempi
commit
a1d46b2824
3 muutettua tiedostoa jossa 178 lisäystä ja 45 poistoa
  1. 24 7
      pages/my/index.vue
  2. 50 12
      pagesHome/order/detail.vue
  3. 104 26
      pagesMy/collection/market.vue

+ 24 - 7
pages/my/index.vue

@@ -14,14 +14,14 @@
 					</view>
 					</view>
 				</view>
 				</view>
 				<view class="one_2">
 				<view class="one_2">
-					<view class="one_2_1">
-						<text v-if="user._id">{{user.collect||0}}</text>
-						<text @click="toCommon('pagesMy/collection/market')">收藏的商品</text>
+					<view class="one_2_1" @click="toCommon('pagesMy/collection/market')">
+						<text v-if="user._id">{{market_num||0}}</text>
+						<text>收藏的商品</text>
 					</view>
 					</view>
 					<text class="link">|</text>
 					<text class="link">|</text>
-					<view class="one_2_1">
-						<text v-if="user._id">{{user.collect||0}}</text>
-						<text @click="toCommon('pagesMy/collection/shop')">收藏的店铺</text>
+					<view class="one_2_1" @click="toCommon('pagesMy/collection/shop')">
+						<text v-if="user._id">{{shop_name||0}}</text>
+						<text>收藏的店铺</text>
 					</view>
 					</view>
 				</view>
 				</view>
 			</view>
 			</view>
@@ -45,7 +45,8 @@
 					<view class="title">{{item.title}}</view>
 					<view class="title">{{item.title}}</view>
 					<view class="title">
 					<view class="title">
 						<text v-if="user.id&&item.title=='我的积分'">{{user.integral||0}}分</text>
 						<text v-if="user.id&&item.title=='我的积分'">{{user.integral||0}}分</text>
-						<text v-if="item.title=='客服电话'" @tap="makePhone(serviceContactInfo.phone)">{{serviceContactInfo.phone||''}}</text>
+						<text v-if="item.title=='客服电话'"
+							@tap="makePhone(serviceContactInfo.phone)">{{serviceContactInfo.phone||''}}</text>
 						<text class="iconfont icon-jiantouyou"></text>
 						<text class="iconfont icon-jiantouyou"></text>
 					</view>
 					</view>
 				</view>
 				</view>
@@ -132,6 +133,10 @@
 						route: ''
 						route: ''
 					},
 					},
 				],
 				],
+				// 收藏商品
+				market_num: '',
+				// 收藏店铺
+				shop_name: ''
 			};
 			};
 		},
 		},
 		onShow: async function() {
 		onShow: async function() {
@@ -152,6 +157,18 @@
 						let user = that.$jwt(res.data);
 						let user = that.$jwt(res.data);
 						const arr = await that.$api(`/user/${user.id}`, 'GET');
 						const arr = await that.$api(`/user/${user.id}`, 'GET');
 						if (arr.errcode == '0') that.$set(that, `user`, arr.data);
 						if (arr.errcode == '0') that.$set(that, `user`, arr.data);
+						const market = await that.$api(`/storeGoods`, 'GET', {
+							customer: user._id
+						})
+						if (market.errcode == '0') {
+							that.$set(that, `market_num`, market.total)
+						}
+						const shop = await that.$api(`/storeShop`, 'GET', {
+							customer: user._id
+						})
+						if (shop.errcode == '0') {
+							that.$set(that, `shop_num`, shop.total)
+						}
 					},
 					},
 					fail: (err) => {}
 					fail: (err) => {}
 				})
 				})

+ 50 - 12
pagesHome/order/detail.vue

@@ -2,10 +2,12 @@
 	<mobile-frame>
 	<mobile-frame>
 		<view class="main">
 		<view class="main">
 			<view class="onemain">
 			<view class="onemain">
-				<scroll-view scroll-y="true" class="scroll-view" scroll-with-animation :scroll-into-view="topItem" @scroll="handleScroll">
+				<scroll-view scroll-y="true" class="scroll-view" scroll-with-animation :scroll-into-view="topItem"
+					@scroll="handleScroll">
 					<view class="list-scroll-view" id="top">
 					<view class="list-scroll-view" id="top">
 						<view class="one">
 						<view class="one">
-							<swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff" indicator-active-color="#FB1438" :autoplay="true" :interval="3000" :duration="1000">
+							<swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff"
+								indicator-active-color="#FB1438" :autoplay="true" :interval="3000" :duration="1000">
 								<swiper-item class="list" v-for="(item,index) in bannerList" :key="index">
 								<swiper-item class="list" v-for="(item,index) in bannerList" :key="index">
 									<image class="image" :src="item.url" mode="">
 									<image class="image" :src="item.url" mode="">
 									</image>
 									</image>
@@ -68,7 +70,8 @@
 				</scroll-view>
 				</scroll-view>
 			</view>
 			</view>
 			<view class="foot">
 			<view class="foot">
-				<uni-goods-nav :options="options" :button-group="buttonGroup" @click="onClick" @buttonClick="buttonClick" />
+				<uni-goods-nav :options="options" :button-group="buttonGroup" @click="onClick"
+					@buttonClick="buttonClick" />
 			</view>
 			</view>
 		</view>
 		</view>
 		<view class="collect">
 		<view class="collect">
@@ -107,7 +110,8 @@
 				<view class="two">
 				<view class="two">
 					<view class="two_1">规格</view>
 					<view class="two_1">规格</view>
 					<view class="two_2">
 					<view class="two_2">
-						<text v-for="(item,index) in specs" :key="index" @click="toStyle(item,index)" :class="{ 'style': isActive==index}">{{item.name}}</text>
+						<text v-for="(item,index) in specs" :key="index" @click="toStyle(item,index)"
+							:class="{ 'style': isActive==index}">{{item.name}}</text>
 					</view>
 					</view>
 				</view>
 				</view>
 				<view class="thr">
 				<view class="thr">
@@ -184,6 +188,7 @@
 				],
 				],
 				// 商品id
 				// 商品id
 				id: '',
 				id: '',
+				user: {},
 				// 轮播图
 				// 轮播图
 				bannerList: [],
 				bannerList: [],
 				// 商品详情
 				// 商品详情
@@ -246,17 +251,24 @@
 				})
 				})
 			},
 			},
 			// 收藏
 			// 收藏
-			toCollect() {
+			async toCollect() {
 				const that = this;
 				const that = this;
-				that.collection = !that.collection;
-				if (that.collection == true) {
-					uni.showToast({
-						title: `收藏成功`,
-						icon: 'none'
-					})
+				let user = that.user;
+				if (user) {
+					let res = await that.$api(`/storeGoods`, `POST`, {
+						customer: user._id,
+						goods: that.id
+					});
+					if (res.errcode == '0') {
+						uni.showToast({
+							title: res.data.msg,
+							icon: 'none'
+						})
+						that.$set(that, `collection`, res.data.result)
+					}
 				} else {
 				} else {
 					uni.showToast({
 					uni.showToast({
-						title: `取消成功`,
+						title: '无用户登录无法收藏商品',
 						icon: 'none'
 						icon: 'none'
 					})
 					})
 				}
 				}
@@ -317,6 +329,7 @@
 					key: 'token',
 					key: 'token',
 					success: async function(res) {
 					success: async function(res) {
 						let user = that.$jwt(res.data);
 						let user = that.$jwt(res.data);
+						that.$set(that, `user`, user)
 						if (that.Selected) {
 						if (that.Selected) {
 							let specs_id;
 							let specs_id;
 							let specs = that.specs.find(i => i.name == that.Selected)
 							let specs = that.specs.find(i => i.name == that.Selected)
@@ -387,6 +400,20 @@
 			// 详情数据
 			// 详情数据
 			async search() {
 			async search() {
 				const that = this;
 				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: function(res) {
+						let user = that.$jwt(res.data);
+						if (user) that.$set(that, `user`, user);
+						that.searchOther()
+					},
+					fail: function(err) {
+						uni.showToast({
+							title: '无用户登录无法查看收藏信息',
+							icon: 'none'
+						})
+					}
+				});
 				let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
 				let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
 					id: that.id
 					id: that.id
 				});
 				});
@@ -398,6 +425,17 @@
 					that.$set(that, `bannerList`, res.data.goods.file)
 					that.$set(that, `bannerList`, res.data.goods.file)
 				}
 				}
 			},
 			},
+			async searchOther() {
+				const that = this;
+				let user = that.user;
+				let res = await that.$api(`/storeGoods/check`, `GET`, {
+					customer: user._id,
+					goods: that.id
+				});
+				if (res.errcode == '0') {
+					that.$set(that, `collection`, res.data)
+				}
+			},
 		}
 		}
 	}
 	}
 </script>
 </script>

+ 104 - 26
pagesMy/collection/market.vue

@@ -5,17 +5,19 @@
 				<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
 				<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
 					<view class="list-scroll-view">
 					<view class="list-scroll-view">
 						<view class="list" v-for="(item, index) in list" :key="index" @click="toView(item)">
 						<view class="list" v-for="(item, index) in list" :key="index" @click="toView(item)">
-							<image class="image" :src="item.file" mode=""></image>
+							<image class="image"
+								:src="item.goods.file&&item.goods.file.length>0?item.goods.file[0].url:''" mode="">
+							</image>
 							<view class="name">
 							<view class="name">
-								{{item.name||'暂无'}}
+								{{item.goods.name||'暂无'}}
 							</view>
 							</view>
 							<view class="money">
 							<view class="money">
 								<text>¥</text>
 								<text>¥</text>
-								<text>{{item.money}}</text>
+								<text>{{item.goods.money}}</text>
 							</view>
 							</view>
 							<view class="other">
 							<view class="other">
 								<view class="other_1">
 								<view class="other_1">
-									{{item.num||0}}人评价
+									{{item.goods.num||0}}人评价
 								</view>
 								</view>
 								<view class="other_2">
 								<view class="other_2">
 									<text @click="toDel(item)" class="iconfont icon-del"></text>
 									<text @click="toDel(item)" class="iconfont icon-del"></text>
@@ -34,29 +36,17 @@
 	export default {
 	export default {
 		data() {
 		data() {
 			return {
 			return {
-				list: [{
-						file: require('@/static/test.png'),
-						name: '摩奇桃汁250ml*24盒',
-						money: 59.90,
-						num: 0
-					},
-					{
-						file: require('@/static/test.png'),
-						name: '摩奇桃汁250ml*24盒',
-						money: 59.90,
-						num: 0
-					},
-					{
-						file: require('@/static/test.png'),
-						name: '摩奇桃汁250ml*24盒',
-						money: 59.90,
-						num: 0
-					}
-				]
+				user: {},
+				list: [],
+				total: 0,
+				skip: 0,
+				limit: 5,
+				page: 0
 			};
 			};
 		},
 		},
 		onShow: function() {
 		onShow: function() {
-
+			const that = this;
+			that.watchLogin()
 		},
 		},
 		methods: {
 		methods: {
 			// 详细信息
 			// 详细信息
@@ -67,12 +57,100 @@
 			// 删除
 			// 删除
 			toDel(e) {
 			toDel(e) {
 				const that = this;
 				const that = this;
-				console.log(e);
+				let user = that.user;
+				uni.showModal({
+					title: '提示',
+					content: '确定取消收藏吗?',
+					success: async function(res) {
+						if (res.confirm) {
+							let res = await that.$api(`/storeGoods`, `POST`, {
+								customer: user._id,
+								goods: that.id
+							});
+							const arr = await that.$api(`/storeGoods`, 'POST', {
+								customer: user._id,
+								goods: e.goods._id
+							});
+							if (arr.errcode == '0') {
+								uni.showToast({
+									title: '取消收藏成功',
+									icon: 'none'
+								})
+								that.clearPage();
+								that.search();
+							} else {
+								uni.showToast({
+									title: arr.errmsg,
+									icon: 'none'
+								})
+							}
+						}
+					}
+				});
+			},
+			// 监听用户是否登录
+			watchLogin() {
+				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: function(res) {
+						let user = that.$jwt(res.data);
+						that.$set(that, `user`, user);
+						that.search()
+					},
+					fail: function(err) {
+						uni.reLaunch({
+							url: `/pages/login/index`
+						})
+					}
+				})
+			},
+			// 查询列表
+			async search() {
+				const that = this;
+				let user = that.user;
+				let info = {
+					skip: that.skip,
+					limit: that.limit,
+					customer: user._id
+				}
+				const res = await that.$api(`/storeGoods`, 'GET', {
+					...info
+				})
+				if (res.errcode == '0') {
+					let list = [...that.list, ...res.data];
+					that.$set(that, `list`, list);
+					that.$set(that, `total`, res.total)
+				}
 			},
 			},
 			// 分页
 			// 分页
 			toPage(e) {
 			toPage(e) {
-			
+				const that = this;
+				let list = that.list;
+				let limit = that.limit;
+				if (that.total > list.length) {
+					uni.showLoading({
+						title: '加载中',
+						mask: true
+					})
+					let page = that.page + 1;
+					that.$set(that, `page`, page)
+					let skip = page * limit;
+					that.$set(that, `skip`, skip)
+					that.search();
+					uni.hideLoading();
+				} else uni.showToast({
+					title: '没有更多数据了'
+				});
 			},
 			},
+			// 清空列表
+			clearPage() {
+				const that = this;
+				that.$set(that, `list`, [])
+				that.$set(that, `skip`, 0)
+				that.$set(that, `limit`, 5)
+				that.$set(that, `page`, 0)
+			}
 		}
 		}
 	}
 	}
 </script>
 </script>