<template>
	<view class="myPost" v-if="load" :style="{ height: phoneHight }">
		<far-bottom></far-bottom>
		<!-- 顶部导航栏 -->
		<view class="topNav">
			<view @click="changeType(-1)">
				<view :class="type == -1 ? 'check' : ''"><span>{{languageStatus!=1?'全部':'전체'}}</span></view>
			</view>
			<view @click="changeType(0)">
				<view :class="type == 0 ? 'check' : ''"><span>{{languageStatus!=1?'显示中':'표시중'}}</span></view>
			</view>
			<view @click="changeType(1)">
				<view :class="type == 1 ? 'check' : ''"><span>{{languageStatus!=1?'审核中':'심사중'}}</span></view>
			</view>
			<view @click="changeType(2)">
				<view :class="type == 2 ? 'check' : ''"><span>{{languageStatus!=1?'未通过':'미통과'}}</span></view>
			</view>
		</view>
		<!-- 顶部导航栏 -->

		<!-- 填充层 -->
		<view class="full"></view>
		<!-- 填充层 -->

		<noneMores v-if="total == 0"></noneMores>
		<!-- 列表区域 -->
		<postManage :postList.sync="postList" :scollHeight="scollHeight" @loadTips="loadTips" :isMore="isMore" :source="source"
		 @shareInfo="setshare" @check="check" @delet="delet" @refresh="refresh" v-else ref="postmanage"></postManage>
		<!-- 列表区域 -->
		<view class="full"></view>

		<TabBars :tabBarAct="0" :pageType="'9'" />
	</view>
</template>

<script>
	import postManage from '@/components/template/postManage';
	import App from '@/common/js/app.js';
	import TabBars from '@/components/template/tabBar';

	// #ifdef H5
	import wxApi from '@/common/js/wxApi.js';
	// #endif
	import noneMores from '@/components/template/nonemores.vue';

	export default {
		components: {
			postManage,
			TabBars,
			noneMores
		},
		data() {
			return {
				type: -1,
				postList: [],
				scollHeight: null,
				scdpText: '',
				loadTip: null,
				page: 1,
				total: null,
				isMore: false,
				source: 1,
				phoneHight: null,
				fullHeight: null,
				load:true
			};
		},
		onLoad(e) {
			// #ifdef MP-WEIXIN
			wx.hideShareMenu();
			// #endif
			if(e.type){
				// debugger
				this.type = e.type;
			}
			this.init();
		},
		onShow() {
			this.init();
		},
		mounted() {
			let _this = this;
			uni.createSelectorQuery()
				.select('.full')
				.boundingClientRect(data => {
					_this.fullHeight = data.height;
				})
				.exec();
			uni.getSystemInfo({
				success(res) {
					_this.scollHeight = res.windowHeight - _this.fullHeight * 2 + 'px';
					_this.phoneHight = res.windowHeight + 'px';
				}
			});
		},
		watch: {
			loadTip: {
				handler() {
					let _this = this;
					if (_this.page >= _this.total) {
						_this.isMore = true;
						return false;
					}
					_this.getUserPostList(++_this.current_page, true)
				}
			}
		},
		methods: {
			refresh(id){
				let _this = this;
				let obj = {};
				this.postList.map((item,index)=>{
					if(item.id == id){
						obj = item;
						this.postList.splice(index,1);
						this.postList.unshift(obj);
					}
				});
				uni.showToast({
					icon: 'none',
					title: '刷新成功',
					duration: 2000
				});
				this.load = !this.load;
				this.load = !this.load;
			},
			delet(id){
				let _this = this;
				// console.log(this.$refs.postmanage.postList);
				this.postList.map((item,index)=>{
					if(item.id == id){
						
						this.postList.splice(index,1);
						// debugger
						// item.check  = true;
						// _this.$set(item,'check',true);
						// console.log(item.check)
					}
				});
				this.load = !this.load;
				this.load = !this.load;
			},
			check(items){
				let _this = this;
				// console.log(this.$refs.postmanage.postList);
				this.postList.map((item,index)=>{
					if(item.id == items){
						item.check  = true;
						_this.$set(item,'check',true);
						console.log(item.check)
					}
				});
				this.load = !this.load;
				this.load = !this.load;
			},
			init() {
				let _this = this;
				_this.getUserPostList();
			},
			// 切换类型
			changeType(type) {
				let _this = this;
				_this.postList = [];
				_this.type = type;
				_this.page = 1;
				_this.getUserPostList();
			},
			// 获取我的帖子列表
			getUserPostList(page = 1, isPage = false) {
				let _this = this,
					data = {
						page,
						status: _this.type
					};
				App._post_form('&p=pocket&do=userList', data, res => {
					if (isPage) {
						if (res.data.list.length > 0) {
							_this["postList"].push(...res.data.list);
							console.log(_this.postList);
						} else {
							_this.isMore = true;
						}
					} else {
						_this.setData({
							current_page: 1,
							postList: res.data.list,
							total: res.data.total,
							isMore: res.data.list.length === 0 || _this.page === res.data.total
						})
					};
					_this.postList.forEach(item=>{
						item.check = false;
					})
				});
			},
			loadTips(e) {
				let _this = this;
				_this.loadTip = e;
				console.log(e)
			}

			
		},
		onShareAppMessage(e) {
			let _this = this;
			_this.$refs.postmanage.show = false;
			let agencyData = uni.getStorageSync('agencyData');
			console.log(_this.$refs.postmanage.items.id);
			if (e.from === 'button') {
				// 来自页面内分享按钮
				let data = {
					id: _this.$refs.postmanage.items.id
				};
				App._post_form('&p=pocket&do=shareNum', data, res => {
					_this.$refs.postmanage.items.share++;
					console.log('shareNum2222')
					uni.showToast({
						icon: 'none',
						title: '分享成功',
						duration: 2000
					});
				});
			}

			return {
				title: _this.$refs.postmanage.items.share_title,
				path: 'pages/subPages/postDetails/postDetails?id=' + _this.$refs.postmanage.items.id + '&aid=' + agencyData.aid,
				desc: _this.$refs.postmanage.items.content,
				imageUrl: _this.$refs.postmanage.items.shareimg
			};
		}
	};
</script>

<style lang="less" scoped>
	.full {
		height: 100upx;
	}

	.check {
		border-bottom: 7upx solid rgba(255, 68, 68, 1) !important;

		>span {
			color: rgba(255, 68, 68, 1) !important;
		}
	}

	.topNav {
		z-index: 2;
		position: fixed;
		top: 0upx;
		width: 750upx;
		height: 99upx;
		background: rgba(255, 255, 255, 1);

		>view {
			text-align: center;
			display: inline-block;
			width: 25%;
			vertical-align: middle;

			>view {
				height: 92upx;
				margin: auto;
				width: 90upx;
				border-bottom: 7upx solid rgba(0, 0, 0, 0);

				>span {
					line-height: 99upx;
					font-size: 28upx;

					color: rgba(153, 153, 153, 1);
				}
			}
		}
	}

	.myPost {
		font-size: 0;
		background: #f8f8f8;
	}

	page {}
</style>
