<template>
	<view class="free-panel-title" style="padding-top: 4rpx; display: flex; justify-content: space-between;">
		<view class="free-WaterfallFlow" :style="{'display':datalist.length < 3?'flex':'','justify-content':datalist.length < 3?'space-between':''}">
		  <block v-for="(item,index) in datalist" :key="index">
			<view v-if="(index % 2 )== 0"  @click.stop="toDetail(item)" class="flex-wrap">
				<view class="position-r flex">
					<image mode="aspectFill"  v-if="item.pics || item.coverimg"  :src="item.pics ? item.pics[0]:item.coverimg"  ></image>
					<view style="width: 100%; height: 330rpx; line-height: 330rpx; " v-else >
						<view style="color: #ccc;">
							<text style="font-size: 100rpx; color: #ccc;" class="iconfont icon-tupianjiazaishibai"></text>
						</view>
					</view>
					<view class="del " v-if="navType && item.is_del == 1 && (recType == 3 || recType == 4)">
				<!-- 		<view class="bo-f position-a" v-if="navType == 'video'">
							<text class="iconfont icon-bofang"></text>
						</view> -->
						<view class="sold-out position-a">
							{{navType == 'note'  ? '笔记已删除':'视频已删除'}}
						</view>
					</view>
					<view class="position-a bf-btn position-center flex" v-else-if="navType == 'video' &&  navNoteType != '3'">
						<image class="bf-img" :src="event_rul + '/static/images/bl/bofang-ic.png'" mode="widthFix"></image>
					</view>
					
					<view class="z-smk" v-if="navNoteType == '3'" @tap="toEide(item)">
						<view class="play" v-if="item.binfo">
							<text class="iconfont icon-bofang"></text>
						</view>
						<view class="f-box">
							<text class="iconfont icon-bianji"></text>
							<text>点击编辑</text>
							<view class="tx-g">
								{{item.binfo? '有篇视频待发布': '有篇笔记待发布'}}
								<text class="iconfont icon-arrow-right"></text>
							</view>
						</view>
					</view>
				</view>


				<view class="title" :class="navNoteType == '3' ? 'font-w': ''">{{item.title ||item.name|| '无'}}</view>
				<view class="info">
					<view class="left" v-if="navNoteType != '3'" @click.stop="goto" :data-url="'/diary/info/info?id='+item.mid">
						<!-- v-if="item.headimg ||item.binfo.logo" @error='imgerr($event,item)' -->
						<image  :src="item.headimg ||item.binfo.logo" mode="aspectFill"></image>
						<!-- <text v-else class="iconfont icon-tupianjiazaishibai"></text> -->
						<text class="name">{{item.nickname ||item.binfo.name||''}}</text>
					</view>
					<view class="left" v-else>
						{{item.createtime}}
					</view>
					<view @click.stop="" v-if="navNoteType != '3'">
						<view class="right" @click="zan(item,index)">
							<text  v-if="!item.iszan" class="iconfont icon-aixin"></text>
							<text v-else style="color: red;" class="iconfont icon-aixin_shixin"></text>	
							<text>{{item.zan >= 10000 || item.zan_num >= 10000 ? ((item.zan / 10000).toFixed(1)+'万')||((item.zan_num / 10000).toFixed(1)+'万'): (item.zan || item.zan_num || 0)}}</text>
						</view>
					</view>
					<image v-else class="prodel-img" :src="event_rul + '/static/img/static/img/del.png'" @tap="delDrafts(item)" />
				</view>
			</view>
		  </block>
		</view>
	
	<view class="free-WaterfallFlow" :style="{'display':datalist.length < 3?'flex':'','justify-content':datalist.length < 3?'space-between':''}">
	  <block v-for="(item,index) in datalist" :key="index">
		<view v-if="(index % 2 ) != 0" @click="toDetail(item)" class="flex-wrap">
			<view class="position-r flex">
				<image mode="aspectFill"  v-if="item.pics || item.coverimg"  :src="item.pics ? item.pics[0] :item.coverimg"  ></image>
				<view style="width: 100%; height: 330rpx; line-height: 330rpx; " v-else >
					<view style="color: #ccc;">
						<text style="font-size: 100rpx; color: #ccc;" class="iconfont icon-tupianjiazaishibai"></text>
					</view>
				</view>
				<view class="del " v-if="navType && item.is_del == 1 && (recType == 3 || recType == 4) ">
					<view class="bo-f position-a" v-if="navType == 'video'">
						<text class="iconfont icon-bofang"></text>
					</view>
					<view class="sold-out position-a">
						{{navType == 'note'  ? '笔记已删除':'视频已删除'}}
					</view>
				</view>
				<view class="position-a bf-btn position-center flex" v-else-if="navType == 'video' &&  navNoteType != '3'">
					<image class="bf-img" :src="event_rul + '/static/images/bl/bofang-ic.png'" mode="widthFix"></image>
				</view>
				<view class="z-smk" v-if="navNoteType == '3'" @tap="toEide(item)">
					<view class="play" v-if="item.binfo">
						<text class="iconfont icon-bofang"></text>
					</view>
					<view class="f-box">
						<text class="iconfont icon-bianji"></text>
						<text>点击编辑</text>
						<view class="tx-g">
							{{item.binfo? '有篇视频待发布': '有篇笔记待发布'}}
							<text class="iconfont icon-arrow-right"></text>
						</view>
					</view>
				</view>
			</view>

			<view class="title" :class="navNoteType == '3' ? 'font-w': ''">{{item.title ||item.name|| '无'}}</view>
			<view class="info">
				<view class="left" v-if="navNoteType != '3'" @click.stop="goto" :data-url="'/diary/info/info?id='+item.mid">
					<image :src="item.headimg ||item.binfo.logo" mode=""></image>
					<text class="name">{{item.nickname ||item.binfo.name||''}}</text>
				</view>
				<view class="left" v-else>
					{{item.createtime}}
				</view>
				<view @click.stop="" v-if="navNoteType != '3'">
					<view class="right" @click="zan(item,index)">
						<text  v-if="!item.iszan" class="iconfont icon-aixin"></text>
						<text v-else style="color: red;" class="iconfont icon-aixin_shixin"></text>	
						<text>{{item.zan >= 10000 || item.zan_num >= 10000 ? ((item.zan / 10000).toFixed(1)+'万')||((item.zan_num / 10000).toFixed(1)+'万'): (item.zan || item.zan_num || 0)}}</text>
					</view>
				</view>
				<image v-else class="prodel-img" :src="event_rul + '/static/img/static/img/del.png'" @tap="delDrafts(item.id)" />
			</view>
		</view>
	  </block>
	</view>
		
	</view>
</template>


<script>
	var app = getApp();
export default{
	props:{
		datalist:{
			default: ()=>{
				return[]
			}
		},
		navNoteType: {
			type: String,
			default: '1'
		},
		navType: {
			type: String,
			default: ''
		},
		recType: {
			type: Number,
			default: 0
		}
	},
	data(){
		return{
			event_rul: app.globalData.event_url,
		}
	},
	methods:{
		editData(data) {
			let url = 'ApiLuntan/detail'
			let dataurl = '/diary/issue/issue?type=note'
			if(data.binfo) {
				url = 'ApiShortvideo/newDetail'
				dataurl = '/diary/issue/issue?type=video'
			}

			app.post(url, {
				id: data.id,
				isdraft: 1
			}, res => {
				if(res.status == 1) {
					if (data.binfo) {
						uni.navigateTo({
							url:dataurl+'&editId='+ data.id + '&detail='+JSON.stringify(res.video) + '&recordlist=' + JSON.stringify(res.proList)
						})
					}
					uni.navigateTo({
						url:dataurl+'&editId='+ data.id + '&detail='+JSON.stringify(res.detail) + '&recordlist=' + JSON.stringify(res.proList)
					})

				}
		
			})
		},
		toEide(data) {
			this.editData(data)
		},
		delDrafts(data) {
			let url = null
			if(data.binfo) {
				url = 'ApiShortvideo/delvideo'
			}else {
				url = 'ApiLuntan/deltie'
			}
			uni.showModal({
				title: '提示',
				content: '确认删除该草稿吗?',
				confirmColor: this.t('color1'),
				success:  (res) => {
					if (res.confirm) {
						app.get(url,{id:data.id},(res)=>{
							if(res.status == 1) {
								this.datalist.forEach((item,idx) => {
									if(data.id == item.id) {
										this.$emit('delDrafts', idx)
									}
								})
								app.error(res.msg)
							}else {
								app.error(res.msg)
							}
						})
					} else if (res.cancel) {
						
					}
				}
			});


		},
		imgerr(e,item){
			if(item.binfo){
				this.binfo.logo = ''
			}else{
				item.headimg = ''
				// this.datalist = JSON.parse(JSON.stringify(this.datalist))
			}
		},
		zan: function (item,index) {
		 if(item.is_del == 1 && recType == 3) {
			 return
		 }
		 var that = this
		 		
				if(item.binfo){
					app.post('ApiShortvideo/zan',{id:item.id},function(res){
						that.$emit('listZanFn',{index:index,show:!item.iszan?1:0,num:item.iszan?--item.zan_num:++item.zan_num})
						
					});
				}else{
					app.post("ApiLuntan/zan", {id: item.id}, function (res) {
					 that.$emit('listZanFn',{index:index,show:!item.iszan?1:0,num:item.iszan?--item.zan:++item.zan})
										
					});
				}
	
		},
		toDetail(item){
			if(this.navNoteType == '3') {
				return
			}
			let url = '/activity/luntan/detail?type=note'
			if(item.binfo){
				url = '/activity/shortvideo/detail?type=video'
			}
			if(this.navType && item.is_del == 1 && this.recType == 3) {
				this.$emit('shopdel',{show: true ,id:item.id, deltype: this.navType})
			}else {
				uni.navigateTo({
					url:url+'&id='+item.id
				})
			}

		},
	
	
	},
}
</script>
<style scoped lang="scss">
  	.free-WaterfallFlow{
  		width: 340rpx;
  	}
  	.free-WaterfallFlow .flex-wrap{
  		display: inline-block;
  		width:100%;
  		margin-bottom: 24rpx;	
		overflow: hidden;
		background-color: #fff;
		border-radius: 10rpx;
  	}
  	.flex-wrap image{
  		width:100%;
		height: 340rpx;
  	}
 	.flex-wrap .title{
  		font-size:28rpx;
		padding: 24rpx 20rpx 20rpx;
  		color:#333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		/* autoprefixer: ignore next; */
		-webkit-box-orient: vertical;
		text-align: justify;
		white-space: pre-wrap;
		word-break: break-all;
  	}
  	.flex-wrap .info{
	justify-content: space-between;
	padding:  0 16rpx 20rpx;
	display: flex;
	color: #999;
	align-items: center;
	.left{
		display: flex;
		align-items: center;
		font-size: 24rpx;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		flex: 1;
		image{
			width: 36rpx;
			height: 36rpx;
			border-radius: 36rpx;
			margin-right: 6rpx;
			border: 1px solid #cccc;
			flex-shrink: 0;
		}
		.name {
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			flex: 1;
		}
	}
	.right{
		flex-shrink: 0;
		margin-left: 10rpx;
		display: flex;
		align-items: center;
		color: #999;
		font-size: 24rpx; 
		.iconfont{
			margin-right: 4rpx;
		}
	}
	
	.prodel-img {
		width: 30rpx;
		height: 30rpx;
	}
  	}
	// 播放按钮
  	.bf-btn {
		
		.bf-img {
			width: 80rpx;
		}
	}
  	/* 回到顶部 */
  	.top {
  		position: relative;
  		display: none; /* 先将元素隐藏 */
  	} 
  	.topc {
  		height: 30px; 
  		width: 30px;
  		position: fixed;
  		right: 0;
  		top: 70%;
  	}
	
	.z-smk {
		width: 100%;
		height: 330rpx;
		color: #fff;
		background-color: rgba(0, 0, 0, .4);
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 33;
		
		.play {
			width: 40rpx;
			height: 40rpx;
			border-radius: 50%;
			background-color: rgba(0, 0, 0, .2);
			display: flex;
			justify-content: center;
			align-items: center;
			position: absolute;
			top: 16rpx;
			right: 16rpx;
			
			.icon-bofang {
				font-size: 20rpx;
				transform: translate(4rpx, -2rpx);
			}
		}
		.f-box {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			// line-height: 50rpx;
			font-family: serif;
			font-size: 24rpx;
				
			
			.icon-bianji {
				font-size: 48rpx;
				padding-bottom: 14rpx;
			}
			
			.tx-g {
				padding-top: 6rpx;
				display: flex;
				align-items: center;
				
				.icon-arrow-right {
					padding-left: 8rpx;
					font-size: 38rpx;
				}
			}
		}
	}
	.font-w{font-weight: bold;}
	.del {

		
		.bo-f {
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			width: 80rpx;
			height: 80rpx;
			border-radius: 200rpx;
			background-color: rgba(0, 0, 0, .4);
			.icon-bofang {
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-40%, -50%);
				font-size: 40rpx;
				color: #fff;
			}
		}

	}
	.sold-out{top:50%;left:50%;width: 190rpx;height:68rpx;line-height: 68rpx;text-align: center;  background-color: #999999;color: #fff; border-radius: 4rpx; transform: translate(-50%, -50%);}
</style>