<template>
	<view class="container">
		<navbar :config="config" backColor="#666"></navbar>
		<view class="detail" v-if="detail">
			<view class="title">
				{{detail.informationTitle}}
			</view>
			<view class="postMessage">
				<view class="message-info">
					<text>{{detail.informationAuthor}}</text>
					<view @click.stop="onFollow(detail)"
						:class="['follow-status', detail.followStatus ? 'is-follow' : '' ]">
						{{detail.followStatus ? '已关注' : '关注' }}
					</view>
				</view>
				<view class="message-time">{{detail.createTime}}</view>
			</view>
			<view class="content">
				<view class="ql-editor-box" v-html="detail.informationContent">
				</view>
				<!-- <u-parse :domain="$mConfig.imgURL" :html="detail.informationContent"></u-parse> -->
			</view>
			<view class="browse">
				<view class="collect-box look-box" @click.stop="onCollect(detail)">
					<text v-if="detail.collectStatus" class="look-icon is-ok iconfont_yige">&#xe8c3;</text>
					<text v-else class="collect-icon iconfont_yige">&#xe8ab;</text>
					<text class="look-name">{{detail.collectStatus ? '已收藏' : '收藏' }}</text>
				</view>
				<view class="look-box">
					<text class="iconfont_yige look-icon">&#xe6a2;</text>
					<text class="look-name">浏览量：{{detail.browseNum||0}}</text>
				</view>
			</view>
		</view>
		<!-- <view class="footer-box">
      <view class="btn" @click="openKongKim" v-if="detail.jumpType !== null || detail.jumpType !== undefined">
        <text v-if="detail.jumpType == 2">{{detail.resourceModelTitle || '一键前往'}}</text>
        <text v-else>一键前往</text>
      </view>
      <view class="footer-tools">
        <view>
          <text class="iconfont3 look-icon">&#xe63b;</text>
          <text>{{detail.browseNum||0}}</text>
        </view>
      </view>
    </view> -->
		<!-- <share ref="shares" :contentHeight="580"></share> -->
	</view>
</template>

<script>
	import {
		newsDetial,
		setUserFollow,
		setUserCollect
	} from '@/api/government.js';
	import share from "@/pages/public/share";
	import rate from "@/components/rate.vue"
	export default {
		components: {
			share,
			rate
		},
		data() {
			return {
				config: {
					back: true,
					title: '资讯详情',
					color: '#1A1A1A',
					backgroundColor: [1, "#fff"],
					statusBarFontColor: '#1A1A1A',
					leftSlot: true
				},
				detail: null,
				FollowLoad: false,
				CollectLoad: false,
			}
		},
		onLoad(options) {
			if (options && options.informationId) {
				this.getDetail(options.informationId)
			}
		},
		methods: {
			getDetail(id) {
				newsDetial(id).then(res => {
					if (res.code === 200) {
						this.detail = res.data
					}
				})
			},
			openKongKim() {
				this.$openPage(this.detail)
			},
			// 关注
			onFollow(info) {
				if (!info) return;
				if (this.FollowLoad) {
					return false;
				};
				this.FollowLoad = true;
				uni.showLoading({
					title: '',
					mask: false
				});
				setUserFollow({
					// followId: info.informationId,
					followSourceId: info.informationId,
					// followType: 0
				}).then(res => {
					uni.hideLoading();
					this.detail.followStatus = !this.detail.followStatus;
					uni.showToast({
						title: info.followStatus ? '关注成功' : '取消关注'
					})
				}).catch(err => {
					uni.hideLoading();
				}).finally(() => {
					setTimeout(() => {
						this.FollowLoad = false;
					}, 300)
				})
			},
			// 收藏
			onCollect(info) {
				if (!info) return;
				if (this.CollectLoad) {
					return false;
				};
				this.CollectLoad = true;
				setUserCollect({
					collectSourceId: info.resourceModelId,
				}).then(res => {
					uni.hideLoading();
					this.detail.collectStatus = !this.detail.collectStatus;
					uni.showToast({
						title: info.collectStatus ? '收藏成功' : '取消收藏'
					})
				}).catch(err => {
					uni.hideLoading();
				}).finally(() => {
					setTimeout(() => {
						this.CollectLoad = false;
					}, 300)
				})
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>

<style lang="scss" scoped>
	.container {
		// padding-bottom: 100rpx;
	}

	.detail {
		padding: 42rpx 30rpx 40rpx 30rpx;
		// margin: 30rpx;
		background-color: #fff;
		border-radius: 20rpx;

		.title {
			margin-bottom: 40rpx;
			font-size: 35rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #1a1a1a;
			line-height: 56rpx;
			letter-spacing: -0.7rpx;
		}

		.postMessage {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 0 10rpx;
			margin-bottom: 30rpx;
			font-size: 26rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			color: #999999;

			.message-info {
				width: 100%;
				display: flex;
				align-items: center;
				flex-wrap: wrap;
			justify-content: space-between;

				.follow-status {
					margin-left: 20rpx;
					flex-shrink: 0;
					padding: 5rpx 20rpx;
					background-color: #3CBACF;
					color: #fff;
					border-radius: 8rpx;
				}

				.is-follow {
					background-color: #ccc;
				}
			}

			.message-time {
				width: 100%;
				padding-top: 10rpx;
			}



			.mb20 {
				margin-bottom: 20rpx;
			}

			.icon-img {
				margin-right: 8rpx;
				color: #FA6138;
				font-size: 36rpx;
			}
		}

		.look-box {
			display: flex;
			align-items: center; 
			.collect-icon{
				font-size: 32rpx;
				margin-right: 8rpx;
			}
			.look-icon {
				font-size: 36rpx;
				margin-right: 8rpx;
			}
		 
		}

		* {
			word-break: break-all;
		}

		.content /deep/ img {
			max-width: 100%;
		}

		.content /deep/ .ql-align-center {
			text-align: center;
		}

		.content /deep/ .ql-align-right {
			text-align: right;
		}

		.content /deep/ blockquote {
			display: block;
			border-left: 8px solid #d0e5f2;
			padding: 5px 10px;
			margin: 10px 0;
			line-height: 1.4;
			font-size: 100%;
			background-color: #f1f1f1;
		}

		.content /deep/ .ql-indent-1 {
			margin-left: 60rpx;
		}

		.content /deep/ .ql-indent-2 {
			margin-left: 120rpx;
		}

		.content /deep/ .ql-indent-3 {
			margin-left: 180rpx;
		}

		.content /deep/ .ql-indent-4 {
			margin-left: 240rpx;
		}

		.content /deep/ .ql-indent-5 {
			margin-left: 300rpx;
		}

		.content {
			/deep/ .ql-editor-box {
				.ql-video {
					width: 100%;
					// height: 45vw;
				}
			}
		}

		.browse {
			margin-top: 30rpx;
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			color: #999999;
			display: flex;
			align-items: center;
			.collect-box {
				margin-right: 20rpx;

				// .look-icon {
				// 	margin-right: 10rpx;
				// }

				.is-ok {
					color: red;
				}
			}
		}

	}

	.footer-box {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		padding: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		box-shadow: 0 0 6rpx 6rpx rgba(0, 0, 0, .1);
	}

	.btn {
		max-width: 400rpx;
		padding: 0 20rpx;
		line-height: 60rpx;
		text-align: center;
		color: #fff;
		background-color: #3775F6;
		border-radius: 8rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.footer-tools {
		flex-shrink: 0;

		.look-icon {
			margin-right: 4rpx;
			font-size: 40rpx;
		}

		&>view {
			display: flex;
			align-items: center;
			font-size: 30rpx;
		}
	}
</style>