<template>
	<view class="car">
		<view class="cartop">
			<view class="tabtop flexc">
				<view class="tabt" :class="ttopval==ite.val?'act':''" v-for="(ite,idx) in ttoplist" :key="idx" @click="getTabtop(ite.val)">{{ite.tit}}</view>
				<view class="numbox" @click="getCount">
					阅读统计
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="carlists">
			<car-list :datainfo="list" :wtdt="wtdt" :type='ttopval' @getDetail="getDetail" @getReadlist="getReadlist"></car-list>
		</view>
		<view class="rfbtn" @click="getAddFn" v-if="ttopval=='ystv'">发布图文</view>
		<view class="rfbtn" @click="getAddvideoFn" v-else>发布视频</view>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import carList from "@/manage/components/car/list.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{carList},
		data(){
			return{
				cxrq:"",
				text:'',
				list:[{tit:'皖A IC520',type:1,right:0},{tit:'晋E KD783',type:2,right:0},],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				ttopval:'ystv',
				ttoplist:[{tit:'图文',val:'ystv'},{tit:'视频',val:'ygsp'}]
			}
		},
		onLoad: function() {
		
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getAddFn(){
				this.$tab.navigateTo("/manage/pages/community/newsadd")
			},
			getAddvideoFn(){
				this.$tab.navigateTo("/manage/pages/community/newsaddvideo")
			},
			getReadlist(){
				this.$tab.navigateTo("/manage/pages/community/readlist")
			},
			getCount(){
				this.$tab.navigateTo("/manage/pages/community/readcount")
			},
			getTabtop(val){
				this.ttopval=val
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getTabFn(val){
				this.tabval=val
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.cxrq=val;
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				params.noticeType=this.tabidx
				getNoticeList(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;
						})
						// console.log(newArr,555)
						if (this.pageNum == 1) {
							this.list = newArr;
						} else {
							this.list = this.list.concat(newArr)
						}
					}else{
						this.$toast(res.msg)
					}
				})
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding: 148rpx 0 110rpx;}
.cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
	.tabtop{padding:28rpx 200rpx 40rpx 0;position: relative;
		.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;}
			}
		}
		.numbox{width: 152rpx;height: 58rpx;background-color: #FFD5C1;border-radius: 29rpx 0 0 29rpx;font-weight: 500;font-size: 26rpx;color: #FE5A0E;display: flex;align-items: center;justify-content: center;position: absolute;right: 0;
			text{height: 20rpx;min-width: 20rpx;padding: 0 8rpx;box-sizing: border-box;line-height: 20rpx;margin-left: 10rpx;font-weight: bold;
font-size:16rpx;
color: #FCF9F1;

background: #D32C26;
border-radius: 5px;}
		}
	}
}
.carlists{padding: 0 18rpx;}
</style>