Browse Source

添加分享按钮功能

yuxingxing 1 year ago
parent
commit
bbf9375e85
3 changed files with 118 additions and 122 deletions
  1. 24 14
      pages/groupbuying_details/index.vue
  2. 31 26
      pages/index/diy/components/latestGroupBuying.vue
  3. 63 82
      pages/index/index.vue

+ 24 - 14
pages/groupbuying_details/index.vue

@@ -149,7 +149,7 @@
 				<view style="    margin-right: 30rpx;">
 					<view class="bnt acea-row">
 						<view class="buy-box" >
-							<button class="share-btn ">
+							<button class="share-btn " open-type="share">
 								分享有礼
 							</button>
 							<button class="now-btn " @click="goBuyNew">
@@ -483,6 +483,10 @@ export default {
     let that = this;
     that.selfTakeId = options.selfTakeId;
     that.organizerUserId = options.organizerUserId;
+	if(options.inviteUserId){
+		this.$Cache.set('INVITE_USER_ID', options.inviteUserId);
+	}
+	
 		console.log(this.userInfo);
 		uni.hideShareMenu();
 		console.log("是否登录:" + this.isLogin);
@@ -580,21 +584,35 @@ export default {
 	 */
 	// #ifdef MP
 	onShareAppMessage: function (res) {
+		let groupon = this.storeInfo;
 		let userInfo = this.$Cache.get("USER_INFO", true)
 		let that = this;
-		// 校验是否可以分享(先购买产品)
 		return {
-			title: userInfo.realName + "邀请您购买共富1580商品",
-			imageUrl: "http://wine.gzzzyd.com/test/static/img/bg.a82f9752.jpg" || that.storeInfo.image,
-			path: "/pages/goods_details/index?id=" + that.id + "&inviteCode=" + that.promotionShare + "&zoneType=8",
+			title: groupon.mainTitle,
+			imageUrl: groupon.slideshow[0],
+			path: `/pages/groupbuying_details/index?id=${groupon.id}&selfTakeId=${that.selfTakeId}&organizerUserId=${that.organizerUserId}&inviteUserId=${userInfo.userId}`,
+			success(res){
+                uni.showToast({
+                    title:'分享成功'
+                })
+            },
+            fail(res){
+                uni.showToast({
+                    title:'分享失败',
+                    icon:'none'
+                })
+            }
 		};
 	},
-
 	// #endif
 	onNavigationBarButtonTap (e) {
 		this.currentPage = !this.currentPage
 	},
 	methods: {
+		// 分享关闭
+		listenerActionClose: function () {
+			
+		},
 		openImg (index) {
 			uni.previewImage({
 				current: index,
@@ -1332,14 +1350,6 @@ export default {
 		authColse: function (e) {
 			this.isShowAuth = e;
 		},
-		/**
-		 * 分享打开
-		 *
-		 */
-		listenerActionSheet () {
-			this.currentPage = false
-
-		},
 		// 分享关闭
 		listenerActionClose: function () {
 			this.posters = false;

+ 31 - 26
pages/index/diy/components/latestGroupBuying.vue

@@ -11,8 +11,9 @@
 				<view class="home">
 					<view class="count">共{{ e.goodsTotal }}个</view>
 					<scroll-view scroll-x class="navscroll"> <!-- 设置滚动条方向为横向 -->
-						<view style="width: 108rpx;height: 108rpx; margin-right: 20rpx; padding: 0;     display: inline-block;" class="item"
-							v-for="item in e.goodsImage">
+						<view
+							style="width: 108rpx;height: 108rpx; margin-right: 20rpx; padding: 0;     display: inline-block;"
+							class="item" v-for="item in e.goodsImage">
 							<!-- 通过for循环生成view -->
 							<image style="width: 108rpx;height: 108rpx;" :src="item" mode="scaleToFill" />
 						</view>
@@ -59,10 +60,10 @@
 					</view>
 					<view class="a-m">
 						<view class="am1">
-							<view class="am1-1">{{e.selfTake.name}}
+							<view class="am1-1">{{ e.selfTake.name }}
 							</view>
 							<view class="am1-2">
-								距您{{e.selfTake.distanceDesc}}
+								距您{{ e.selfTake.distanceDesc }}
 								<image src="http://www.gzzzyd.com/groupon/order_details/距离@2x.png" mode="scaleToFill" />
 							</view>
 						</view>
@@ -83,7 +84,7 @@
 				</view>
 			</view>
 			<view class="btn-area" v-if="currentId == 0">
-				<button class="share">
+				<button class="share" open-type="share" :data-groupon="e">
 					<image src="http://www.gzzzyd.com/groupon/home_slices/分享@2x.png" mode="scaleToFill" />
 					<text>分享有礼</text>
 				</button>
@@ -108,9 +109,9 @@ export default {
 	},
 	name: 'promotionList',
 	props: {
-		grouponData:{
-			type:Array,
-			default(){
+		grouponData: {
+			type: Array,
+			default() {
 				return []
 			}
 		},
@@ -136,7 +137,7 @@ export default {
 		},
 		currentId: {
 			type: String | Number,
-			default(){
+			default() {
 				return 0
 			}
 		}
@@ -144,7 +145,7 @@ export default {
 	watch: {
 
 	},
-	data () {
+	data() {
 		return {
 			timestamp: 86400,
 			navigationList2: [],
@@ -166,11 +167,11 @@ export default {
 			loadTitle: this.$t(`加载更多`), //提示语
 		};
 	},
-	created () {
+	created() {
 
 	},
 	methods: {
-		goToDetail(item){
+		goToDetail(item) {
 			uni.navigateTo({
 				url: `/pages/groupbuying_details/index?id=${item.id}&selfTakeId=${item.selfTake.id}&organizerUserId=${item.organizerUserId}`
 			})
@@ -180,11 +181,12 @@ export default {
 </script>
 
 <style lang="scss">
-.list-box{
+.list-box {
 	background: white;
 
 	padding-bottom: 20px;
 }
+
 .index-product-wrapper {
 
 	&.on {
@@ -317,7 +319,7 @@ export default {
 	.countdown-l {
 		flex: 1;
 		display: flex;
-    align-items: center;
+		align-items: center;
 	}
 
 	.countdown-r {
@@ -345,13 +347,14 @@ export default {
 		vertical-align: super;
 	}
 
-/deep/.yellow,.u-count-down  {
-		font-size: 24rpx ;
-		font-weight: 400 ;
-		color: #FF9600 ;
-		line-height: 80rpx ;
-		margin: 0 10rpx ;
-		vertical-align: super ;
+	/deep/.yellow,
+	.u-count-down {
+		font-size: 24rpx;
+		font-weight: 400;
+		color: #FF9600;
+		line-height: 80rpx;
+		margin: 0 10rpx;
+		vertical-align: super;
 	}
 
 	image {
@@ -381,10 +384,11 @@ export default {
 	margin: 20rpx 0;
 	display: flex;
 	justify-content: space-between;
-	image{
-	 width: 36rpx;
-	 height: 36rpx;
-	 vertical-align: middle;
+
+	image {
+		width: 36rpx;
+		height: 36rpx;
+		vertical-align: middle;
 	}
 }
 
@@ -404,6 +408,7 @@ export default {
 	padding: 0 30rpx;
 	padding-bottom: 20rpx;
 	min-height: 60rpx;
+
 	.am1 {
 		display: flex;
 		justify-content: space-between;
@@ -500,7 +505,7 @@ export default {
 	}
 
 	button {
-		flex:1;
+		flex: 1;
 
 		text-align: center;
 		margin: auto;

+ 63 - 82
pages/index/index.vue

@@ -5,88 +5,69 @@
 </template>
 
 <script>
-	import diyC from './diy/index_mall.vue'
-	export default {
-		data() {
-			return {
-				isDiy: uni.getStorageSync('is_diy'),
-				shareInfo: {}
-			}
-		},
-		components: {
-			diyC
-		},
-		onShow() {
-			uni.$on('is_diy', (data) => {
-				this.isDiy = data
-			})
-			this.setOpenShare();
-		},
-		onHide() {
-			// this.isDiy = -1
-		},
-		onPullDownRefresh() {
-			this.$refs.diy.pullResh();
-			// uni.stopPullDownRefresh()
-		},
-		methods: {
-			// 微信分享;
-			setOpenShare: function() {
-				let that = this;
-				// getShare().then((res) => {
-				// 	let data = res.data;
-				// 	this.shareInfo = data;
-				// 	// #ifdef H5
-				// 	let url = location.href;
-				// 	if (this.$store.state.app.uid) {
-				// 		url =
-				// 			url.indexOf("?") === -1 ?
-				// 			url + "?spread=" + this.$store.state.app.uid :
-				// 			url + "&spread=" + this.$store.state.app.uid;
-				// 	}
-				// 	if (that.$wechat.isWeixin()) {
-				// 		let configAppMessage = {
-				// 			desc: data.synopsis,
-				// 			title: data.title,
-				// 			link: url,
-				// 			imgUrl: data.img,
-				// 		};
-				// 		that.$wechat.wechatEvevt(
-				// 			["updateAppMessageShareData", "updateTimelineShareData"],
-				// 			configAppMessage
-				// 		);
-				// 	}
-				// 	// #endif
-				// });
+import diyC from './diy/index_mall.vue'
+export default {
+	data() {
+		return {
+			isDiy: uni.getStorageSync('is_diy'),
+			shareInfo: {}
+		}
+	},
+	components: {
+		diyC
+	},
+	onShow() {
+		uni.$on('is_diy', (data) => {
+			this.isDiy = data
+		})
+	},
+	onHide() {
+		// this.isDiy = -1
+	},
+	onPullDownRefresh() {
+		this.$refs.diy.pullResh();
+		// uni.stopPullDownRefresh()
+	},
+	methods: {
+	},
+	// onReachBottom: function() {
+	// 	if (this.isDiy) {
+	// 		this.$refs.diy.onsollBotton()
+	// 	}
+	// },
+	//#ifdef MP
+	//发送给朋友
+	onShareAppMessage: function (option) {
+		console.log(option)
+		let groupon = option.target.dataset.groupon;
+		let userInfo = this.$Cache.get("USER_INFO", true)
+		let that = this;
+		return {
+			title: groupon.mainTitle,
+			imageUrl: groupon.slideshow[0],
+			path: `/pages/groupbuying_details/index?id=${groupon.id}&selfTakeId=${that.selfTakeId}&organizerUserId=${that.organizerUserId}&inviteUserId=${userInfo.userId}`,
+			success(res) {
+				uni.showToast({
+					title: '分享成功'
+				})
 			},
-		},
-		// onReachBottom: function() {
-		// 	if (this.isDiy) {
-		// 		this.$refs.diy.onsollBotton()
-		// 	}
-		// },
-		// #ifdef MP
-		//发送给朋友
-		onShareAppMessage(res) {
-			// 此处的distSource为分享者的部分信息,需要传递给其他人
-			let that = this;
-			return {
-				title: this.shareInfo.title,
-				path: "/pages/index/index",
-				imageUrl: this.shareInfo.img,
-			};
-		},
-		//分享到朋友圈
-		onShareTimeline() {
-			return {
-				title: this.shareInfo.title,
-				imageUrl: this.shareInfo.img,
-			};
-		},
-		// #endif
-	}
+			fail(res) {
+				uni.showToast({
+					title: '分享失败',
+					icon: 'none'
+				})
+			}
+		};
+	},
+	//分享到朋友圈
+	// onShareTimeline() {
+	// 	return {
+	// 		title: this.shareInfo.title,
+	// 		imageUrl: this.shareInfo.img,
+	// 	};
+	// },
+	//#endif
+}
 </script>
 
-<style>
-
-</style>
+<style></style>