goodlist.vue 8.1 KB
<template>
	<view class="container">
		<view class="goodlist">
			<view class="goodlistitem flex" v-for="(item,index) in zhigoodlist" :key="index" @click="entergood(item)">
				<view class="goodlistimg">
					<image :src="item.image" mode=""></image>
				</view>
				<view class="goodlistright">
					<view class="goodrighttop flextwo">
						<view class="goodname">{{item.name}}</view>
						<view class="shareimg">
							<image src="../static/share.png" mode="" class="sharebtn"></image>
							<button open-type="share" class="shartype"></button>
						</view>
					</view>
					<view class="zhibo flextwo">
						<view class="zhiboleft" @click.stop="gozhubo(item.anchor.id)">{{item.anchor.name}}{{item.anchor.platform}}</view>
						<view class="kaibo">{{item.anchor_time.time}}开播</view>
					</view>
					<view class="zhiboprice">
						直播价 ¥<text class="pricege">{{item.live_price}}</text>
					</view>
					<view class="cankao flextwo">
						<view class="cankaoleft">参考价(京东¥{{item.r_price}}元)</view>
						<view v-if="item.status_data==1">
							<view v-if="item.user_goods==0">
								<view class="canlaoright flexone" v-if="item.share==true" >
									<image src="../static/naoling.png" mode="" class="naoling"></image>
									提醒我
									<button open-type="share" class="sharebtnk"  @click.stop="sharefriend(index,item.id,item.share)"></button>
								</view>
								<view class="canlaoright flexone" v-else @click.stop="tixing(index,item.id)">
									<image src="../static/naoling.png" mode="" class="naoling"></image>
									提醒我
								</view>
							
							</view>
							<view class="canceltixing" v-else @click.stop="canceltixing(index,item.id)">
								取消提醒
							</view>	
						</view>
						<view v-if="item.status_data==2">
							<view class="canlaoright flexone">
								已上架
							</view>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		<!-- 弹出层 -->
		<view class="register" v-if="noshow" @click="hideding">
			<view class="registerwrap">
				<view class="title">何时提醒我?</view>
				<view class="titletext">在主播开始介绍商品时就提醒您</view>
				<view class="title">如何提醒我</view>
				<view class="titletext">在你允许消息通知后,届时会给您发送微信消息提醒</view>
				<view class='noti flexone' @click.stop="notibtn">
					<image src="../static/selectzhong.png" mode="" class="selectxuan" v-if="noti"></image>
					<image src="../static/select.png" mode="" class="selectxuan" v-else></image>
					不再提示
				</view>
				<button class="buzai" @click.stop="know" v-if="share==true" open-type="share">我知道了</button>
				<view class="buzai" @click.stop="know" v-else>我知道了</view>
			</view>
		</view>
	
	</view>
</template>

<script>
	import app from "../App.vue"
	export default {
		// noting  是否显示不再提示 1 不再显示  空是显示
		props: ["zhigoodlist","notixing","dingyuenum"],
		data() {
			return {
				goods_id: '',
				noti: false, //提示和不提示按钮
				noshow: false, //提示我弹出层ss
				goodindex: '',
				share:'',
				
			}
		},
		onLoad() {

		},
		onShow() {
		},
		onShareAppMessage(res) {
			let that = this;
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '早直播',
				path: '/pages/xinyuan/xinyuan'
			}
		},
		methods: {
			// 订阅消息
			tixing(index, id) {
				console.log(99)
				let that = this;
				if (uni.getStorageSync("token")) {
					if (that.notixing == '') {
						that.noshow = true
					} else {
						that.noshow = false
					}
					that.goodindex = index;
					this.goods_id = id;
					 // that.dingyue()
					wx.getSetting({
						// withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
						success(res) {
							if (res.authSetting['scope.subscribeMessage']) {
								uni.openSetting({ // 打开设置页
									success(res) {
										console.log(res.authSetting, 88888)
									}
								});
							} else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
								uni.requestSubscribeMessage({
									tmplIds: ["XrIccvxDK3IfW3DrnLtKAtKS-pL63BrG3W0Du9l7BrU"], // 
									success(res) {
										// 去订阅
										that.dingyue()
									}
								})
							}
						}
					})
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
					setTimeout(function() {
						uni.switchTab({
							url: '/pages/mine/mine'
						})
					}, 1500)
				}

			},
			// 取消订阅
			canceltixing(index, id) {
				this.goods_id = id;
				this.goodindex = index;
				this.dingyue()
			},
			// 订阅
			dingyue() {
				let that = this;
				let url = "goods/addUserGoods";
				let param = {
					goods_id: that.goods_id
				}
				console.log('参数', param)
				app.post(url, param, "post").then(r => {
					console.log(r, that.goodindex, '订阅')
					let newdingyuenum=that.dingyuenum;
					
					if (that.zhigoodlist[that.goodindex].user_goods == 0) {
						that.zhigoodlist[that.goodindex].user_goods = 1;
						if(newdingyuenum.indexOf(that.zhigoodlist[that.goodindex].id)==-1){
							newdingyuenum.push(that.zhigoodlist[that.goodindex].id)
						}
						
						uni.showToast({
							title: '订阅成功',
							icon: "none"
						})

					} else {
						that.zhigoodlist[that.goodindex].user_goods = 0;
						newdingyuenum.forEach(function(value,index,array){
							if(value==that.zhigoodlist[that.goodindex].id){
								newdingyuenum.splice(index,1)
							}
						})
							
						uni.showToast({
							title: '取消订阅成功',
							icon: "none"
						})
					}
					// 直播个数超过10个 显示false
					  that.zhigoodlist.forEach(function(value,index,array){
						
						if(newdingyuenum.length>=10){
							if(value.user_goods ==0){
								value.share=true
							}
						}else{
							if(value.user_goods ==0){
								value.share=false
							}
						}
					})
					that.zhigoodlist = that.zhigoodlist;
					that.$forceUpdate();
					that.$emit('tixing', that.zhigoodlist)
				}).catch(err => {
					console.log(err)
				})
			},


			// 不再提醒
			notibtn() {
				this.noti = !this.noti;
				if (this.noti == true) {
					uni.setStorageSync("notixing", 1);
					this.notixing=1
				} else {
					uni.setStorageSync("notixing", '');
					this.notixing=''
				}
			},
			// 我知道了
			know() {
				this.noshow = false
			},
			// 取消订阅
			hideding() {
				this.noshow = false
			},
			// 分享给好友
			sharefriend(index,id,share) {
				console.log(4398489)
				let that = this;
				if (uni.getStorageSync("token")) {
					let notixing = uni.getStorageSync("notixing");
					this.notixing = notixing;
					if (that.notixing == '') {
						that.noshow = true
					} else {
						that.noshow = false
					}
					that.goodindex = index;
					that.goods_id = id;
					that.share=share;
					 // that.dingyue()
					wx.getSetting({
						// withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
						success(res) {
							if (res.authSetting['scope.subscribeMessage']) {
								uni.openSetting({ // 打开设置页
									success(res) {
										console.log(res.authSetting, 88888)
									}
								});
							} else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
								uni.requestSubscribeMessage({
									tmplIds: ["XrIccvxDK3IfW3DrnLtKAtKS-pL63BrG3W0Du9l7BrU"], // 
									success(res) {
										// 去订阅
										that.dingyue()

									}
								})
							}
						}
					})
				} else {
					uni.showToast({
						title: '请先登录',
						icon: 'none'
					})
					setTimeout(function() {
						uni.switchTab({
							url: '/pages/mine/mine'
						})
					}, 1500)
				}
			},
			// 进入链接页面
			entergood(item){
				uni.navigateTo({
					url:"/pages/xinyuan/goodlianjie?code="+item.code+'&platform='+item.platform
				})
			},
			// 进入主播页面
			gozhubo(id){
				uni.navigateTo({
					url:'/pages/xinyuan/zhibodetail?id='+id
				})
			}
		}

	}
</script>

<style>
	@import url("../style/goodlist");

	
</style>