<template>
	<view class="postDetail">
		<navbar leftClick @leftClick="$utils.navigateBack" title="动态详情" />

		<view class="swipe">
			<uv-swiper :list="item.image &&
			item.image.split(',')" indicator height="420rpx"></uv-swiper>
		</view>

		<view class="box">

			<view class="title">
				{{ item.title }}
			</view>

			<view class="createBy">
				<view class="">
					发布人：{{ item.userId }}
				</view>
				<view class="">
					发布时间：{{ $dayjs(item.createTime).format('YYYY-MM-DD') }}
				</view>
			</view>


			<view class="content">
				<uv-parse :content="item.content"></uv-parse>
			</view>
			
			<view class="controls">
				<contentControls
				:type="2"
				:up="isThumbs_up"
				:down="isThumbs_down"
				@loadData="getData"
				:detail="item"/>
			</view>


		</view>

	</view>
</template>

<script>
	import contentControls from '@/components/content/contentControls.vue'
	export default {
		components: {
			contentControls
		},
		data() {
			return {
				list: [
				],
				item: {},
				isThumbs_up: undefined,//是否点赞
				isThumbs_down: undefined,//是否踩
				id : 0,
			}
		},
		onLoad(options) {
			// this.$route.query的参数
			console.log(options)
			this.id = options.id
		},
		onPullDownRefresh(){
			this.getData()
		},
		onShow() {
			this.getData()
		},
		onShareAppMessage(res) {
		    // if (res.from === 'button') {// 来自页面内分享按钮
		    //   console.log(res.target)
		    // }
		    return {
				title: this.item.title,
				desc: this.item.content && this.item.content.slice(0, 30),
				path: '/pages/publish/postDetail?id=' + this.id
		    }
		},
		//2.分享到朋友圈
		onShareTimeline(res) {
		    return {
				title: this.item.title,
				desc: this.item.content && this.item.content.slice(0, 30),
				path: '/pages/publish/postDetail?id=' + this.id
		    }
		},
		methods: {
			getData() {
				this.$api('indexGetTrendsDetail', {
					id : this.id
				}, res => {
					uni.stopPullDownRefresh()
					if (res.code == 200) {
						this.item = res.result.details
						this.isThumbs_up = res.result.isThumbs_up//是否点赞
						this.isThumbs_down = res.result.isThumbs_down//是否踩
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.postDetail {
		.box {
			padding: 20rpx;
			width: 100vw;

			.title {
				font-size: 34rpx;
				font-weight: 600;
				color: #000;
			}

			.createBy {
				display: flex;
				margin-top: auto;
				margin-bottom: 10rpx;
				font-size: 24rpx;
				margin-top: 20rpx;
				color: #555;

				&>view {
					display: flex;
					align-items: center;
					justify-content: center;
					padding-right: 20rpx;
				}
			}

			.controls {
				margin-top: 30rpx;
			}

			.content {
				margin-top: 30rpx;
				font-size: 28rpx;
			}
		}
	}
</style>