<template>
	<view class="waterfall-wrap">
		<u-waterfall v-model="list" ref="uWaterfall">
			<template v-slot:left="{ leftList }">
				<view @click="jump(item)" v-for="(item, index) in leftList" :key="item.id" class="post-item post-left">
					<u-lazy-load v-if="item.story_type == 2" loading-img="/static/img-load.png" threshold="100" border-radius="10" :image="item.story_file[0]" :index="item.id"></u-lazy-load>
					<view class="video-wrap" v-if="item.story_type == 4" >
						
						<image v-if="(item.story_file[0])" :lazy-load="true" :src="item.story_file[0]" mode="widthFix"></image>
						<image v-else :lazy-load="true" :src="item.story_video + '?x-oss-process=video/snapshot,t_0,f_jpg'" mode="widthFix"></image>
						<image class="pay-icon" :lazy-load="true" src="@/static/images/play.png"></image>
					</view>
					<view class="post-title">{{ item.story_title}}</view>
					<view class="footer">
						<block  v-if="(IsLoginUser && type == 'publish')">
							<view class="operation" @click.stop="showPopup(item)"><uni-icons type="more-filled" size="19" /></view>
						</block>
						<block v-else>
							<image class="avatar" :lazy-load="true" :src="item.user_avatar" mode="aspectFill"></image>
							<text class="username">{{ item.user_nickname}}</text>
							<text class="thumb-num">{{ item.story_like_count }}</text>
							<uni-icons class="thumb-icon" type="heart" :size="19" color="#999"></uni-icons>
						</block>
						
			
					 </view>
				</view>
			</template>
			<template v-slot:right="{ rightList }">
				<view @click="jump(item)" v-for="(item, index) in rightList" :key="item.id" class="post-item post-right">
					<u-lazy-load v-if="item.story_type == 2" threshold="100" loading-img="/static/img-load.png" border-radius="10" :image="item.story_file[0]" :index="item.id"></u-lazy-load>
					<view class="video-wrap" v-if="item.story_type == 4">
						<image v-if="(item.story_file[0])" :lazy-load="true" :src="item.story_file[0]" mode="widthFix"></image>
						<image v-else  :lazy-load="true" :src="item.story_video + '?x-oss-process=video/snapshot,t_0,f_jpg'" mode="widthFix"></image>
						<image class="pay-icon" :lazy-load="true" src="@/static/images/play.png"></image>
					</view>
					<view class="post-title">{{ item.story_title}}</view>
					<view class="footer">
						<block  v-if="(IsLoginUser && type == 'publish')">
							<view class="operation" @click.stop="showPopup(item)"><uni-icons type="more-filled" size="19" /></view>
						</block>
						<block v-else>
							<image class="avatar" :lazy-load="true" :src="item.user_avatar" mode="aspectFill"></image>
							<text class="username">{{ item.user_nickname}}</text>
							<text class="thumb-num">{{ item.story_like_count }}</text>
							<uni-icons class="thumb-icon" type="heart" :size="19" color="#999"></uni-icons>
						</block>
					</view>
				</view>
			</template>
		</u-waterfall>
		<!-- 选择分享弹窗 -->
		<uni-popup ref="popup" background-color="#fff"  type="bottom">
			<view class="share-wrap">
				<view class="share-item" @click="del()">
					<text>{{ __('删除') }}</text>
				</view>
				<button class="mini-btn" type="warn" style="margin-top: 20rpx;" @click="cancel">
					<text>{{__('取消')}}</text>
				</button>
			</view>
		</uni-popup>
		<!-- 加载状态 -->
		<!-- <view style="margin: 30rpx 0;"><u-loadmore :status="loadStatus" /></view> -->
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
import Uwaterfall from '@/components/u-waterfall/u-waterfall.vue';
import ULazyLoad from '@/components/u-lazy-load/u-lazy-load.vue';
export default {
	name: 'q-post-waterfall',
	props: {
		list: Array,
		loadStatus: {
			type: String,
			default: 'loadmore'
		},
		type: {
			type: String,
			default: 'publish'
		},
		IsLoginUser: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			row:{}
		};
	},
	computed: mapState(['Config', 'StateCode', 'notice', 'plantformInfo', 'shopInfo', 'userInfo', 'hasLogin']),
	components: {
		Uwaterfall,
		ULazyLoad,
	},
	methods: {
			...mapMutations(['login', 'logout', 'getPlantformInfo', 'forceUserInfo', 'getUserInfo']),
		showPopup: function(item) {
			this.row = item;
			this.$refs.popup.open();
		},
		cancel: function(item) {
			this.row = {};
			this.$refs.popup.close();
		},
		del: function(e) {
			let that = this;
			this.$.showModal({
				title: '提示',
				content: '是否确定此信息?',
				success: function(res) {
					if (res.confirm) {
						var params = {
							story_id: that.row.story_id,
						}
						that.$.request({
							url: that.Config.URL.sns.story_remove,
							data: params,
							success: function(data, status, msg, code) {
								if(status == 200)
								{
									that.$emit('onRenew', {});
									that.$.alert(msg);
								
								}
								else
								{
									that.$.alert(msg);
								}
							}
						})
					}
				}
			});
		},
	
		remove(id) {
			this.$refs.uWaterfall.remove(id);
		},
		clear() {
			this.$refs.uWaterfall.clear();
		},

	
		jump(item) {
			
			let url = '/community/community/detail?id=' + item.story_id;
			
			if (item.story_type == 4) {
				// #ifdef APP-PLUS
				url = '/community/index/index?id=' + item.story_id + '&uid='+item.user_id;
				// #endif
			
				// #ifdef H5 || MP-WEIXIN
				url = '/community/nvueSwiper/nvueSwiper?id=' + item.story_id + '&uid='+item.user_id;
				// #endif
			}
			this.$.navigateTo({
				url: url
			})
			
			
		}
	}
};
</script>

<style lang="scss" scoped>
.waterfall-wrap {
	padding: 30rpx;
	background-color: #fff;
}
.post-left {
	margin-right: 15rpx;
}

.post-right {
	margin-left: 15rpx;
}
.post-item {
	margin-bottom: 50rpx;
	
	.cover-img {
		width: 100%;
		max-height: 600rpx;
		border-radius: 10rpx;
	}

	.video-wrap {
		position: relative;
		image {
			width: 100%;
			max-height: 600rpx;
			border-radius: 10rpx;
		}
		.pay-icon {
			position: absolute;
			right: 30rpx;
			top: 30rpx;
			width: 50rpx;
			height: 50rpx;
		}
	}
	.post-title {
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}

	.footer {
		display: flex;
		align-items: center;
		font-size: 20rpx;
		color: #999;
		.avatar {
			width: 30rpx;
			height: 30rpx;
			border-radius: 50%;
			margin-right: 10rpx;
		}
		.thumb-num {
			margin-left: auto;
			margin-right: 10rpx;
		}
	}
}

// 分享弹窗
.share-wrap {
	padding: 30rpx;
	margin: 0 auto;
	background-color: #fff;
	
	.share-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding: 0rpx 40rpx;
		

		image {
			width: 100rpx;
			height: 100rpx;
		}

		text {
			font-size: 30rpx;
			margin-top: 20rpx;
			
		}
	}
}
</style>
