<template>
	<view>
		<u-navbar v-show="false" ref="refNavbar" >
			
		</u-navbar>
		
		<view class="header">
			<!-- 导航 -->
			<view :class="flag?'sticky':'navbar'">
				<view class="back" style="font-size: 32rpx;" @click="back()">
					<u-icon name="arrow-left" size="40"></u-icon>返回
				</view>
				<view class="title">
					个人主页
				</view>
				<view class="camera" @click="issueMethod()" >
					<u-icon name="camera-fill" size="48"></u-icon>
				</view>
			</view>
			<!-- 个人信息 -->
			<view class="person-infos">
				 <view class="photo">
				 	
					<img v-if="userInfo.headImg" :src="userInfo.headImg" alt="">
					
					<u-avatar  v-else  size="120" ></u-avatar>
				 </view>
				<view class="infos">
					<view class="name">
						{{userInfo.name}}
					</view>
					<view class="department-position">
						<view class="department" v-if="userInfo.orgName">
							<view class="icon">
								<img src="../../assets/img/department2.png" alt="">
							</view>
							<view class="text">
								{{userInfo.orgName}}
							</view>
						</view>
						<view class="position">
							<text class="icon">
								<img src="../../assets/img/position2.png" alt="">
							</text>
							<text class="text">
								员工
							</text>
						</view>
					</view>
				</view>
			</view>
			
			<view class="grid">
				<view class="item">
					<view class="amout">
						{{plusInfo.userShare}}
					</view>
					<view class="text">
						发布
					</view>
				</view>
				<view class="item">
					<view class="amout">
						{{plusInfo.userNewsLike}}
					</view>
					<view class="text">
						点赞
					</view>
				</view>
				<view class="item">
					<view class="amout">
						{{plusInfo.userNewsComment}}
					</view>
					<view class="text">
						评论
					</view>
				</view>
				
			</view>
		</view>
		<!-- 分享 -->
		<view class="share">
			<view class="item"  v-for="(item,i) in list" :key="i" >
				<view class="date">
					<view class="day">
						{{day(item.createTime)}}
					</view>
					<view class="year-month">
						{{yearmonth(item.createTime)}}
					</view>
				</view>
				<view class="content">
					<view class="title">
						<textarea placeholder="记录点滴生活..." :auto-height="true"
						v-model="item.synopsis" readonly maxlength="200"
						 name="" id="" ></textarea>
					</view>
					<view class="photos">
						<template v-for="(pic,i2) in item.listShareFiles"  v-if="pic.url">
							<img   v-if="pic.isPic" :key="i2"
							@click="previewImage(item.listShareFiles,i2)"
							:src="pic.url" alt="">
							
							<video v-else :key="i2" :src="pic.url"
							                    enable-danmu danmu-btn controls></video>
						</template>
					</view>
				</view>
				
			</view>
		</view>
		<u-divider  :isnone="list.length==0" nonetext="没有找到相关内容" border-color="#CFD2D5">已经到底了</u-divider>
		
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/user.js'
	import * as API_share from '@/apis/pagejs/share.js'
	
	export default {
		data() {
			return {
				flag: false,
				scrollTop: "",
				plusInfo:{},
				userInfo:{},
				listForm:{
					pageIndex:1,
					pageSize:20,
					queryStatus:1
				},
				list:[],
				recordsTotal:0,
			}
		},
		onLoad() {
			this.carhelp.set("addShare",0);
			this.init()
			this.getList()
		},
		onShow(){
			this.findByOpenId()
			if(	this.carhelp.get("addShare")){
				this.listForm.pageIndex=1;
				this.getList()
			}
		},
		onReachBottom() {
			if (this.list.length < this.recordsTotal) {			
				this.myLoadmore();
			}
		},
		methods: {
			day(time){
				if(time){
					
					return time.substring(8,10)
				}else
				return''
			},
			yearmonth(time){
				if(time){
					
					return time.substring(0,7).replace('-','.')
				}else
				return''
			},
			issueMethod(id){
				
				this.gotoUrl('pages/mine/issue?nic=1')
			},
			init(){
				this.plusInfo=this.carhelp.getPersonInfoPlus();
				this.userInfo=this.carhelp.getPersonInfo();
				
			},
			findByOpenId(){
				API.findByOpenId({
					noerror:true,
					openId: this.carhelp.getOpenId(),
					
				}).then((response) => {
					
					this.carhelp.setPersonInfo(response.data.regUser);
					this.carhelp.setPersonInfoPlus(response.data)
					this.init();
				}).catch(error => {
					uni.hideLoading();
					
				})
			},
			back(){
				this.$refs.refNavbar.goBack()
			},
			onPageScroll(e) {
				this.scrollTop = e.scrollTop;
				console.log(this.scrollTop);
				
				if (this.scrollTop >=44) {
					this.flag = true;
				} else {
					this.flag = false;
				}
			
			
			},previewImage(img,i) {
				let imgs = [];
				img.forEach(it=>{
					imgs.push(it.url)
				})
				
				
				uni.previewImage({
					indicator:"default",
					loop:true,
					urls: imgs,
					current: i
				})
			},getList(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				API_share.pageList(this.listForm).then((res) => {
					this.carhelp.set("addShare",0);
					uni.hideLoading();
					//this.list=response.data.data
					if(this.listForm.pageIndex==1){
						this.list = res.data.data;
					}else{
						this.list = [
							...this.list,
							...res.data.data
						];
					}
					this.recordsTotal = res.data.recordsTotal;
					
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			myLoadmore(){
				this.listForm.pageIndex += 1;
				this.getList();
			},
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #fff;
		padding-bottom: 50px;
		font-family: 'Regular';
	}
	.header{
		padding: 0 0 48rpx 0;
		background: linear-gradient(180deg, rgba(183,208,255,1) 0%,rgba(244,244,246,1) 100%);
		.navbar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 44px;
			padding: 0 32rpx;
			.title{
				font-size: 16px;
				color: rgba(16, 16, 16, 1);
			}
		}
		.sticky{
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 44px;
			padding: 0 32rpx;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			.title{
				font-size: 16px;
				color: rgba(16, 16, 16, 1);
			}
			
		}
		// 个人信息
		.person-infos{
			margin-top: 32rpx;
			padding: 0 48rpx;
			display: flex;
			align-items: center;
			margin-bottom: 48rpx;
			.photo {
				box-shadow: 0px 2px 8px 0px rgba(35, 72, 75, 15);
				border: 2px solid rgba(255, 255, 255, 1);
				border-radius: 50px;
				width: 120rpx;
				height: 120rpx;
				overflow: hidden;
				img {
				     vertical-align: middle;
					border-radius: 50px; 
					width: 120rpx;
					height: 120rpx;
				}
			
			}
			
			.infos {
				margin-left:32rpx;
			
				.name {
					line-height: 28px;
					font-size: 20px;
					font-family: 'Medium';
				}
			
				.department-position {
					display: flex;
					margin-top: 16rpx;
			       color: rgba(119, 119, 119, 1);  
			
					.icon {
						margin-right: 8rpx;
			
						img {
							width: 28rpx;
							height: 28rpx;
							
						}
					}
					
			
					.department {
						display: flex;
						
			           .text{
			           	line-height: 16px;
			           }
			           
					}
			
					.position {
						display: flex;
						
						margin-left: 24rpx;
			.text{
				line-height: 16px;
			}
					}
				}
			}
		}
	
	.grid {
		width: 100%;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		align-items: center;
		margin-top: 24rpx;
	  justify-content: space-between;
		.item {
			width: 33.3%;
			text-align: center;
	
			.amout {
				font-size: 48rpx;
				line-height: 64rpx;
	
			}
	
			.text {
				font-size: 32rpx;
				line-height: 44rpx;
			}
		}
	}
	}
    
	.share{
		padding: 32rpx;
		.item{
			margin-bottom: 48rpx;
			display: flex;
			.date{
				.day{
					color: rgba(51, 51, 51, 1);
					font-size: 18px;
					font-weight:bold;
					line-height: 25px;
					font-family: 'Medium';
				}
				.year-month{
					color: rgba(51, 51, 51, 1);

				}
			}
			.content{
				margin-left: 52rpx;
				border-bottom: 1px solid rgba(232, 232, 232, 1);
				padding-bottom: 32rpx;
				 .title{
					 color: rgba(51, 51, 51, 1);
					 font-size: 16px;
					 margin-bottom: 16rpx;
					 line-height: 22px;
				 }
				 .photos{
					 
					 img{
						 width: 248rpx;
						 height: 248rpx;
						 border-radius: 16rpx;
						 margin-right: 16rpx;
					 }
				 }
			}
			
		}
		.item:last-of-type{
			.content{
				border: none;
			}
		}
	}
</style>
