<template>
	<view class="news">
		<!-- tab栏 -->
		<view class="cartop">
			<view class="tabtop flexc">
				<view class="tabt" :class="tabval==ite.val?'act':''" v-for="(ite,idx) in tablist" :key="idx" @click="getTabFn(ite.val)">{{ite.tit}}</view>
			</view>
		</view>
		<box-list :datainfo="list" :wtdt="wtdt" :tabval="tabval" type="wdhd" @getDetail='getDetail'></box-list>
	<loading></loading>	
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import boxList from "@/mine/components/box/list.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {mycommentStars,mycommentLikes,mycommentIndex} from "@/api/work/news.js"
	export default{
		components:{boxList},
		data(){
			return{
				hrimg:require('@/static/logo.png'),
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				tabval:'mypl',
				userId:this.$store.state.user.userId,
				tablist:[{tit:"评论",val:'mypl'},{tit:"点赞",val:'mydz'},{tit:"收藏",val:'mysc'},]
			}
		},
		onUnload() {
			uni.$off('partyNewsList')
		},
		onLoad: function() {
			uni.$on('partyNewsList',(res)=>{
				this.getrefreshData()
			})
			this.getDataFn()
		},
		onPageScroll(e) {
			var scrollTop = Number(e.scrollTop);
			// var listTop=Number(this.listTop)-Number(this.nvaHeight)
			if(scrollTop>2){
				this.scroflag=true
			}else{
				this.scroflag=false
			}
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			// getNextFn(){
			// 	this.$tab.navigateTo("/work/pages/business/add")
			// },
			getDetail(data){
				var info=JSON.parse(JSON.stringify(data))
				var type=this.tabval;
				var targetType=info.targetType;//1：社区 2：党建 
				if(type=='mypl'){
					var id=info.commentId;
					this.$tab.navigateTo("/news/pages/news/detail?id="+id)
				}else{
					var id=info.targetId;
					if(targetType==1){
						this.$tab.navigateTo("/news/pages/news/detail?id="+id)
					}else if(targetType==2){
						this.$tab.navigateTo("/news/pages/news/djdetail?id="+id)
					}
				}
			},
			getDelFn(id){
				var that=this;
				// reservDel(data).then(res=>{
				// 	if(res.code==200){
				// 		this.$toast("删除成功");
				// 		setTimeout(function(){
				// 			that.getrefreshData()
				// 		},1500)
				// 	}
				// })
			},
			getTabFn(val){
				this.tabval=val;
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getSh(data){
				var that=this;
				var params=JSON.parse(JSON.stringify(data))
				commentContentPut(params).then(res=>{
					if(res.code==200){
						this.$toast('审核成功')
						setTimeout(function() {
							that.getrefreshData()
						}, 1500);
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					userId:this.userId
				}
				var tabval=this.tabval
				if(tabval=='mypl'){
					mycommentIndex(params).then(res=>{
						if(res.code==200){
							if (res.rows.length < this.pageSize) {
								this.reachflag = false
								this.wtdt = '到底了~';
							} else {
								var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
								if (num < res.total) {
									this.reachflag = true
									this.wtdt = ''
								} else {
									this.reachflag = false
									this.wtdt = '到底了~';
								}
							}
							var newArr=JSON.parse(JSON.stringify(res.rows))
							newArr.forEach(ite=>{
								ite.right=0;
							})
							if (this.pageNum == 1) {
								this.list = newArr;
							} else {
								this.list = this.list.concat(newArr)
							}
							
						}else{
							this.$toast(res.msg)
						}
					})
				}else if(tabval=='mydz'){
					mycommentLikes(params).then(res=>{
						if(res.code==200){
							if (res.rows.length < this.pageSize) {
								this.reachflag = false
								this.wtdt = '到底了~';
							} else {
								var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
								if (num < res.total) {
									this.reachflag = true
									this.wtdt = ''
								} else {
									this.reachflag = false
									this.wtdt = '到底了~';
								}
							}
							var newArr=JSON.parse(JSON.stringify(res.rows))
							newArr.forEach(ite=>{
								ite.right=0;
							})
							if (this.pageNum == 1) {
								this.list = newArr;
							} else {
								this.list = this.list.concat(newArr)
							}
						}else{
							this.$toast(res.msg)
						}
					})
				}else{
					mycommentStars(params).then(res=>{
						if(res.code==200){
							if (res.rows.length < this.pageSize) {
								this.reachflag = false
								this.wtdt = '到底了~';
							} else {
								var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
								if (num < res.total) {
									this.reachflag = true
									this.wtdt = ''
								} else {
									this.reachflag = false
									this.wtdt = '到底了~';
								}
							}
							var newArr=JSON.parse(JSON.stringify(res.rows))
							newArr.forEach(ite=>{
								ite.right=0;
							})
							if (this.pageNum == 1) {
								this.list = newArr;
							} else {
								this.list = this.list.concat(newArr)
							}
						}else{
							this.$toast(res.msg)
						}
					})
				}
				console.log(this.list)
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.news{padding:124rpx 18rpx 12rpx;}
.cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
	.toptit{display: flex;justify-content: center;font-weight: 500;font-size: 26rpx;color: #8592AA;height: 70rpx;align-items: center;
background: #E4EDFF;
		text{font-size: 32rpx;color: #0156FE;padding: 0 10rpx;}
		image{width: 28rpx;height: 26rpx;flex: 0 0 auto;margin-right: 12rpx;}
	}
	.tabtop{padding-bottom: 40rpx;padding-top: 14rpx;
		.tabt{font-weight: 500;font-size: 32rpx;color: #666666;position: relative;line-height: 56rpx;padding: 0 40rpx;
			&.act{font-weight: bold;font-size: 32rpx;color: #272727;
			&::after{content: '';width: 40rpx;height: 10rpx;background: #0156FE;border-radius: 6rpx;position: absolute;left: 50%;margin-left: -20rpx;bottom: -10rpx;}
			}
		}
	}
}
</style>