guhongwei 2 лет назад
Родитель
Сommit
6b94c1652a
3 измененных файлов с 116 добавлено и 41 удалено
  1. 38 5
      pages/store/index.vue
  2. 44 12
      pagesHome/order/detail.vue
  3. 34 24
      pagesHome/shop/index.vue

+ 38 - 5
pages/store/index.vue

@@ -18,7 +18,7 @@
 										<text>关注数<text>{{item.follow_num}}</text></text>
 									</view>
 								</view>
-								<view class="r" @tap="toFolllow(item)">
+								<view class="r" @tap.stop="toFolllow(item)">
 									<text class="iconfont icon-yduishoucangshixin-copy" v-if="item.is_follow==true"></text>
 									<text class="iconfont icon-yduishoucangkongxin-copy" v-else></text>
 								</view>
@@ -46,6 +46,7 @@
 				frameStyle: {
 					useBar: true
 				},
+				user: {},
 				list: [],
 				total: 0,
 				page: 0,
@@ -53,11 +54,23 @@
 				limit: 5,
 			};
 		},
-		onShow: function() {
+		onShow: async function() {
 			const that = this;
-			that.search()
+			await that.watchLogin();
+			await that.search();
 		},
 		methods: {
+			// 监听用户是否登录
+			watchLogin() {
+				const that = this;
+				uni.getStorage({
+					key: 'token',
+					success: function(res) {
+						let user = that.$jwt(res.data);
+						that.$set(that, `user`, user)
+					}
+				})
+			},
 			async search() {
 				const that = this;
 				let info = {
@@ -114,8 +127,28 @@
 				})
 			},
 			// 关注
-			toFolllow(e) {
-				console.log(e);
+			async toFolllow(e) {
+				const that = this;
+				let user = that.user;
+				if (user && user._id && e && e._id) {
+					let res = await that.$api(`/storeShop`, `POST`, {
+						customer: user._id,
+						shop: e._id
+					});
+					if (res.errcode == '0') {
+						uni.showToast({
+							title: res.data.msg,
+							icon: 'none'
+						})
+						that.clearPage();
+						that.search()
+					}
+				} else {
+					uni.showToast({
+						title: '缺少必要信息,无法收藏',
+						icon: 'none'
+					})
+				}
 			},
 			toPath(e) {
 				const that = this;

+ 44 - 12
pagesHome/order/detail.vue

@@ -2,12 +2,10 @@
 	<mobile-frame>
 		<view class="main">
 			<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="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">
 									<image class="image" :src="item.url" mode="">
 									</image>
@@ -57,7 +55,7 @@
 							</view>
 							<view class="four_2">
 								<view class="btn" @tap="toShop('pagesHome/shop/index')">进入店铺</view>
-								<view class="btn">关注</view>
+								<view class="btn" @tap="shopCollect">{{shop_collect==true?'已关注':'关注'}}</view>
 							</view>
 						</view>
 						<view class="five">
@@ -70,8 +68,7 @@
 				</scroll-view>
 			</view>
 			<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 class="collect">
@@ -110,8 +107,7 @@
 				<view class="two">
 					<view class="two_1">规格</view>
 					<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 class="thr">
@@ -202,8 +198,10 @@
 				// 是否显示返回顶部
 				isShow: false,
 				topItem: '',
-				// 收藏
+				// 商品收藏
 				collection: false,
+				// 店铺收藏
+				shop_collect: false,
 				// 菜单显示
 				menu: false,
 				disabled: true,
@@ -220,9 +218,11 @@
 		onLoad: async function(e) {
 			const that = this;
 			that.$set(that, `id`, e.id || '');
+		},
+		onShow: function() {
+			const that = this;
 			that.search();
 		},
-		onShow: function() {},
 		methods: {
 			//店铺,
 			// 购物车,客服跳转
@@ -273,6 +273,29 @@
 					})
 				}
 			},
+			// 关注商铺
+			async shopCollect() {
+				const that = this;
+				let user = that.user;
+				if (user && user._id) {
+					let res = await that.$api(`/storeShop`, `POST`, {
+						customer: user._id,
+						shop: that.shop._id
+					});
+					if (res.errcode == '0') {
+						uni.showToast({
+							title: res.data.msg,
+							icon: 'none'
+						})
+						that.$set(that, `shop_collect`, res.data.result)
+					}
+				} else {
+					uni.showToast({
+						title: '无用户登录无法关注商铺',
+						icon: 'none'
+					})
+				}
+			},
 			//主菜单跳转
 			toPath(e) {
 				if (e && e.route) uni.reLaunch({
@@ -405,7 +428,7 @@
 					success: function(res) {
 						let user = that.$jwt(res.data);
 						if (user) that.$set(that, `user`, user);
-						that.searchOther()
+						that.searchOther();
 					},
 					fail: function(err) {
 						uni.showToast({
@@ -428,6 +451,7 @@
 			async searchOther() {
 				const that = this;
 				let user = that.user;
+				// 商品是否收藏
 				let res = await that.$api(`/storeGoods/check`, `GET`, {
 					customer: user._id,
 					goods: that.id
@@ -435,6 +459,14 @@
 				if (res.errcode == '0') {
 					that.$set(that, `collection`, res.data)
 				}
+				// 商铺是否收藏
+				let arr = await that.$api(`/storeShop/check`, `GET`, {
+					customer: user._id,
+					shop: that.shop._id
+				});
+				if (arr.errcode == '0') {
+					that.$set(that, `shop_collect`, arr.data)
+				}
 			},
 		}
 	}

+ 34 - 24
pagesHome/shop/index.vue

@@ -10,8 +10,7 @@
 						<scroll-view scroll-y="true" class="scroll-view">
 							<view class="list-scroll-view">
 								<view class="list" v-for="(item,index) in shoplist" :key="index">
-									<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
-										mode=""></image>
+									<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
 									<view class="name">
 										{{item.name}}
 									</view>
@@ -37,20 +36,17 @@
 						<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
 							<view class="list-scroll-view">
 								<view class="second_1">
-									<view :class="['list',condActive==index?'activeList':'']"
-										v-for="(item,index) in condList" :key="index" @tap="toCond(index,item)">
+									<view :class="['list',condActive==index?'activeList':'']" v-for="(item,index) in condList" :key="index" @tap="toCond(index,item)">
 										<view class="name">
 											{{item.name}}
 										</view>
 										<view class="icon">
 											<view class="icon_1">
-												<text :class="['iconfont',item.shangActive]"
-													v-if="condActive==index&&shang=='1'"></text>
+												<text :class="['iconfont',item.shangActive]" v-if="condActive==index&&shang=='1'"></text>
 												<text :class="['iconfont',item.shang]" v-else></text>
 											</view>
 											<view class="icon_1">
-												<text :class="['iconfont', item.xiaActive]"
-													v-if="condActive==index&&xia=='-1'"></text>
+												<text :class="['iconfont', item.xiaActive]" v-if="condActive==index&&xia=='-1'"></text>
 												<text :class="['iconfont', item.xia]" v-else></text>
 											</view>
 										</view>
@@ -58,8 +54,7 @@
 								</view>
 								<view class="second_2">
 									<view class="list" v-for="(item,index) in list" :key="index">
-										<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
-											mode=""></image>
+										<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
 										<view class="sale" v-if="item.is_sale==true">
 											<text>已售尽</text>
 										</view>
@@ -103,8 +98,7 @@
 						</view>
 						<view class="second_2">
 							<view class="second_2_bor">
-								<image class="image" :src="info.qrcode&&info.qrcode.length>0?info.qrcode[0].url:''"
-									mode=""></image>
+								<image class="image" :src="info.qrcode&&info.qrcode.length>0?info.qrcode[0].url:''" mode=""></image>
 							</view>
 							<view class="txt">
 								店铺二维码
@@ -200,11 +194,12 @@
 				]
 			};
 		},
-		onLoad: function(e) {
+		onLoad: async function(e) {
 			const that = this;
 			that.$set(that, `id`, e.id || '');
-			that.watchLogin()
-			that.search()
+			await that.watchLogin();
+			await that.search();
+			await that.searchOther();
 		},
 		onShow: function() {},
 		methods: {
@@ -342,18 +337,33 @@
 				that.clearPage();
 				that.searchAll();
 			},
+			// 查询其他信息
+			async searchOther() {
+				const that = this;
+				let user = that.user;
+				let shop = that.info;
+				if (user && user._id && shop && shop._id) {
+					// 商铺是否收藏
+					let arr = await that.$api(`/storeShop/check`, `GET`, {
+						customer: user._id,
+						shop: shop._id
+					});
+					if (arr.errcode == '0') {
+						that.$set(that, `collection`, arr.data)
+					}
+				}
+			},
 			// 收藏
 			async toCollect() {
 				const that = this;
-				var params = {};
-				params = {
-					shop: that.id,
-					customer: that.user.id
-				}
-				if (that.user) {
-					let res = await that.$api(`/storeShop`, `POST`, params);
+				let user = that.user;
+				let shop = that.info;
+				if (user && user._id && shop && shop._id) {
+					let res = await that.$api(`/storeShop`, `POST`, {
+						customer: user._id,
+						shop: shop._id
+					});
 					if (res.errcode == '0') {
-						console.log(res);
 						uni.showToast({
 							title: res.data.msg,
 							icon: 'none'
@@ -362,7 +372,7 @@
 					}
 				} else {
 					uni.showToast({
-						title: '无用户登录无法收藏店铺',
+						title: '缺少必要信息,无法收藏',
 						icon: 'none'
 					})
 				}