<template>
	<view>
		<u-navbar back-text="文章详情" :share="share" back-icon-size="28" back-icon-color="#ffffff"
			:background="{backgroundColor: '#2795FD',}" :back-text-style="{color: '#ffffff'}"></u-navbar>
		<view class="main">
			<!-- 标题 -->
			<view class="title">
				{{form.title}}
			</view>
			<!-- 其他信息 -->
			<view class="infos">
				<view class="photo">
					<u-avatar class="avatar" 
						:src="photo != null ? photo : '@/assets/img/headPortrait.png'" size="48">
					</u-avatar>
				</view>
				<view class="name">
					{{form.author}}
				</view>
				<view class="date" v-if="form.createTime != null">
					{{form.createTime.slice(0,10)}}
				</view>
				<view class="tag1" v-if="form.type == '1'">
					急需用工
				</view>
				<view class="tag2" v-if="form.type == '2'">
					资源共享
				</view>
			</view>
			<u-line color="#CFD2D5" />
			<!-- 文章内容 -->
			<view class="content news-content" v-html="form.content">
				 
			</view>
			<!-- 图片 -->
			<view class="picture">
				<!-- <img src="@/assets/img/articlePicture.png" alt=""> -->
			</view>
		</view>
	</view>
</template>

<script>
	import * as API_packages from '@/apis/pagejs/packages.js'
	
	export default {
		data() {
			return {
				form: {
					id: ''
				},
				photo: '',
				share:0,
			}
		},
		onShareTimeline(){
			return {
				title: "荆州经开区共享用工平台",
			}
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				//.log(res.target)
			}
			return {
				title: this.form.title,
				path: '/pages/packages/shareEmployment/articleDetail?shareMP=1&id=' + this.form.id
			}
		},
		onLoad(op) {
			if (op.shareMP) {
				this.share = op.shareMP
			}
			if(op.id) {
				this.form.id = op.id;
				this.getShareWorksDetail();
			}
		},
		methods: {
			getShareWorksDetail() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API_packages.shareWorksDetail({id: this.form.id}).then((res) => {
					
					var newsDetail=res.data.shareWorksInfo;
					if(newsDetail.content){
						var reg=new RegExp('alt','gi');
						newsDetail.content=newsDetail.content.replace(reg,'width="100%" height="100%" /> <p')						
					}
					this.form=newsDetail
					if(res.data.personInfo)	{
						this.photo = res.data.personInfo.photo;
					}	
					
					
					uni.hideLoading();
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.main {
		padding: 40rpx 32rpx;

		// 标题
		.title {
			color: rgba(16, 16, 16, 1);
			font-size: 36rpx;
		}

		// 其他信息
		.infos {
			display: flex;
			align-items: center;
			margin-top: 24rpx;
			margin-bottom: 36rpx;

			.photo {
				width: 48rpx;
				height: 48rpx;
				border-radius: 50px;

				img {
					width: 48rpx;
					height: 48rpx;
				}
			}

			.name {
				color: rgba(16, 16, 16, 1);
				margin-left: 8rpx;
			}

			.date {
				color: rgba(119, 119, 119, 1);
				margin-left: 32rpx;
			}

			.tag1 {
				flex: 1;
				color: rgba(39, 149, 253, 1);
				text-align: right;
			}
			
			.tag2 {
				flex: 1;
				color: rgba(0, 185, 98, 1);
				text-align: right;
			}

		}
		// 文章内容
		.content{
			color: rgba(16, 16, 16, 1);
			line-height: 56rpx;
			img{
				width: 100%;
				height: 100%;
			}
			// text-align: j;
		}
		// 图片
		.picture{
			margin-top: 24rpx;
			border-radius: 4px;
			width: 100%;
			height: 400rpx;
			img{
				width: 100%;
				height: 100%;
			}
		}
	}
</style>
r