<template>
	<view class="userpost userIndex" :class="$store.state.AppStyle" style="background-color: #f6f6f6;">
		<view class="header" :style="[{height:CustomBar + 'px'}]" :class="scrollTop>40?'goScroll':''">
			<view class="cu-bar" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px'}">
				<view class="action" @tap="back">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content text-bold" :style="[{top:StatusBar + 'px'}]">
					<block v-if="scrollTop>40">
						{{name || "未知圈子"}}
					</block>
				</view>
				<!--  #ifdef H5 || APP-PLUS -->
				<view class="action">
					<text class="cuIcon-more" @click="show = true"></text>
					<tn-popup v-model="show" mode="bottom" :closeBtn="true"
						:height="myPurview>0&&group=='administrator'?'30%':'20%'" :borderRadius="20">
						<view class="center-container tn-margin-top-xxl" style="color: #333;">
							<view v-if="group=='administrator'||myPurview==5"
								class="tn-padding-sm tn-radius bg-flex-shadow popup-content sy-text-lg"
								@tap="toEdit(parent,id,name),show=false">
								<text class="tn-icon-write" style="margin-right: 5px;"></text>编辑圈子
							</view>
							<view v-if="group=='administrator'||myPurview==5"
								class="tn-padding-sm tn-radius bg-flex-shadow popup-content sy-text-lg"
								@tap="moderator(id),show=false">
								<text class="tn-icon-team" style="margin-right: 5px;"></text>管理圈主
							</view>
							<view v-if="group=='administrator'||myPurview==5"
								class="tn-padding-sm tn-radius bg-flex-shadow popup-content sy-text-lg"
								@tap="setModerator(id,name),show=false">
								<text class="tn-icon-my-add" style="margin-right: 5px;"></text>添加圈主
							</view>
							<view class="tn-padding-sm tn-radius bg-flex-shadow popup-content sy-text-lg"
								v-if="isFollow==0" @tap="sectionFollow(1),show=false">
								<text class="tn-icon-add-circle" style="margin-right: 5px;"></text>加入圈子
							</view>
							<view class="tn-padding-sm tn-radius bg-flex-shadow popup-content sy-text-lg" v-else
								@tap="sectionFollow(0),show=false">
								<text class="tn-icon-close-circle" style="margin-right: 5px;"></text>退出圈子
							</view>

						</view>
					</tn-popup>

				</view>
				<!--  #endif -->
			</view>
		</view>
		<view class="all-box" style="margin-top:-10upx">
			<view class="section-info" :style="'padding-top:'+NavBar+'px;'">
				<view class="section-info-bg">
					<image :src="bg" mode="aspectFill" v-if="bg&&bg!=''"></image>
					<image src="/static/forum-bg.jpg" mode="aspectFill" v-else></image>
				</view>
				<view class="section-info-main">
					<view class="section-info-content">
						<view class="section-info-full">
							<view class="section-info-ico" :class="{
								  'img-border-radius-10': radiusBoxStyle == 1,
								  'img-border-radius-32 ': radiusBoxStyle == 2,
								  'img-border-radius-50': radiusBoxStyle == 3
								}">
								<!-- <image src="../../static/h5/owo/img/paopao/E985B7_2x.png"></image> -->
								<image :src="pic" mode="aspectFill" v-if="pic&&pic!=''"></image>
								<image src="https://starimg.illlt.com/upload/2024/1/27/51139d81-1c5b-4568-a50b-79dae4656a31.png" mode="aspectFill" v-else></image>
							</view>
							<view class="section-info-intro grid col-2" style="height: 70px;margin: auto;">
								<view>
									<view class="section-info-title text-content-1">{{name || "未知圈子"}}</view>
									<view class="text-content-2">{{text}}</view>
								</view>
								<view class="section-info-value"
									style="display: flex;align-items: center;justify-content: flex-end">
									<block v-if="isFollow==0">
										<view class="cu-btn text-blue"
											style="background-color: #fff;border-radius: 10px;padding: 0 10px;font-size: 12px;height: 30px;color: #333;"
											@tap="sectionFollow(1)">
											<text class="tn-icon-add-circle margin-right-xs"></text>加入
										</view>
									</block>
									<block v-else>
										<view class="cu-btn text-blue"
											style="background-color: #fff;border-radius: 10px;padding: 0 10px;font-size: 12px;height: 30px;color: #333;"
											v-if="isClock==0" @tap="sectionClock()"><text
												class="tn-icon-calendar margin-right-xs"></text>签到</view>
										<view class="cu-btn bg-blue"
											style="background-color: #fff;border-radius: 10px;padding: 0 10px;font-size: 12px;height: 30px;color: #333;"
											v-else><text class="tn-icon-success-circle margin-right-xs"></text>已签到
										</view>
									</block>

								</view>
							</view>
						</view>
						<view class="section-info-moderator grid col-2">
							<view class="section-info-moderator" @tap="goModerators(id)">
								<tn-avatar-group :lists="moderators" :dsof="false"
									:badge="false" badgeBgColor="white" txNum="7"></tn-avatar-group>
							</view>
							<view class="section-info-clock"
								style="display: flex;align-items: center;justify-content: flex-end;font-size: 12px;">
								<view>
									<view class="tn-padding-right-sm" style="margin-bottom: 15upx;"><text
											class="tn-icon-inventory" style="margin-right: 10upx;"></text>帖子 {{postNum}}
										条</view>
									<view class="tn-padding-right-sm" style="margin-bottom: 15upx;"><text
											class="tn-icon-calendar" style="margin-right: 10upx;"></text>签到 {{clockNum}}
										人</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="forum-list">

			<view class="forum-list-type ">
				<tn-tabs class="bg-white" :list="titlePostList" :isScroll="true" :current="current" name="tab-name"
					@change="change"></tn-tabs>
			</view>
			<view class="forum-list-top" v-if="topList.length > 0"
				style="margin: 10upx 20upx 0upx 20upx;border-radius: 20upx;box-shadow: 0upx 0upx 50upx 0upx rgba(0, 0, 0, 0.075);">
				<view class="forum-top-box" v-for="(item,index) in topList" @tap="goInfo(item.id)" :key="index">
					<view class="forum-top-i">
						<text class="text-red" v-if="item.isTop=='1'">置顶</text>
						<text class="text-red" v-if="item.isTop=='2'">全局</text>
					</view>
					<view class="forum-top-text">
						{{item.title}}
					</view>
				</view>
			</view>

			<view class="forum-list-main">
				<view class="no-data" v-if="postList.length==0">
					<text class="cuIcon-text"></text>暂时没有数据
				</view>
				<block v-for="(item,index) in postList" :key="index">
					<forumItem :item="item" :myPurview="myPurview"></forumItem>
				</block>
				<view class="load-more" @tap="loadMore" v-if="dataLoad&&postList.length>0">
					<text>{{moreText}}</text>
				</view>
			</view>
		</view>
		<view v-if="scrollTop>40" class="forum-post-btn-2 tn-main-gradient-orange box-shadow-2" @tap="refresh()">
			<text class="tn-icon-refresh-simple"></text>
		</view>
		<view v-if="scrollTop<=40" class="forum-post-btn-1 tn-main-gradient-orange box-shadow-2" @tap="refresh()">
			<text class="tn-icon-refresh-simple"></text>
		</view>
		<view v-if="scrollTop>40" class="forum-post-btn-1 tn-main-gradient-blue box-shadow-1" @tap="totop()">
			<text class="tn-icon-totop"></text>
		</view>
		<view class="forum-post-btn tn-main-gradient-indigo" @tap="addPost()">
			<text class="tn-icon-edit-write"></text>
		</view>
		<!--加载遮罩-->
		<view class="loading" v-if="isLoading==0">
			<view class="loading-main">
				<image src="../../static/loading.gif"></image>
			</view>
		</view>
		<!--加载遮罩结束-->
		<view class="full-noLogin" v-if="isuserlogin">
			<view class="full-noLogin-main">
				<view class="full-noLogin-text">
					您需要登录后才可以查看内容哦！
				</view>
				<view class="full-noLogin-btn">
					<view class="cu-btn bg-blue" @tap="goLogin()">
						立即登录
					</view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import {
		localStorage
	} from '../../js_sdk/mp-storage/mp-storage/index.js'
	// #ifdef APP-PLUS
	import owo from '../../static/app-plus/owo/OwO.js'
	// #endif
	// #ifdef H5
	import owo from '../../static/h5/owo/OwO.js'
	// #endif
	// #ifdef MP
	var owo = [];
	// #endif
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar: this.StatusBar + this.CustomBar,
				AppStyle: this.$store.state.AppStyle,
				scrollTop: 0,
				id: 0,
				parent: 0,
				name: '',
				show: false,
				pic: '',
				isuserlogin:false,
				bg: '',
				slug: '',
				group: "",
				text: '',
				restrict: 0,
				postNum: 0,
				clockNum: 0,
				moderators: [],
				current: 1,
				titlePostList: [{
						order: "recommend",
						name: "精华",
						parent: 0
					},{
						order: "created",
						name: "最新",
						parent: 0
					}, 
					{
						order: "replyTime",
						name: "回复",
						parent: 0
					},
					{
						order: "views",
						name: "最热",
						parent: 0
					},
					{
						order: "likes",
						name: "获赞",
						parent: 0
					}

				],
				orderKey: "created",
				isFollow: 0,
				isClock: 0,
				token: "",
				radiusBoxStyle: 0, 
				postList: [],
				topList: [],
				dataLoad: false,
				userInfo: null,
				page: 1,
				moreText: "加载更多",
				isLoading: 0,
				isHuaWei: this.$API.isHuaWei(),
				isTy: false,
				myPurview: 0,
				isvip:0,
				submitStatus1:false,
				submitStatus2:false,
				operateShow: false
			}
		},
		onPageScroll(res) {
			var that = this;
			that.scrollTop = res.scrollTop;
		},
		onPullDownRefresh() {
			var that = this;
			that.page = 1;
			that.getSectionInfo();
			that.getPostList(false);
			that.getTopList();
			var timer = setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000)

		},
		onReachBottom() {
			//触底后执行的方法，比如无限加载之类的
			var that = this;
			if (that.isLoad == 0) {
				that.loadMore();
				
			}
		},
		onLoad(res) {
			var that = this;
			if (res.id) {
				that.id = res.id;
				that.getSectionInfo();
				that.getPostList(false);
				that.getTopList();
			}
			if(localStorage.getItem('userinfo')){
				var userInfo = JSON.parse(localStorage.getItem('userinfo'));
				that.isvip = userInfo.isvip;
			}
			that.userPurview();
			// #ifdef APP-PLUS || MP
			that.NavBar = this.CustomBar;
			// #endif
			that.page = 1;
			that.getSectionInfo();
		},
		onShow() {
			var that = this;
			
			uni.$emit('tOnLazyLoadReachBottom');

			if (localStorage.getItem('userinfo')) {
				that.userInfo = JSON.parse(localStorage.getItem('userinfo'));
				that.group = that.userInfo.group;
			} else {
				that.userInfo = null;
			}
			if (localStorage.getItem('token')) {

				that.token = localStorage.getItem('token');
			} else {
				that.token = "";
			}
			that.getSet();
			
			// #ifdef APP-PLUS

			//plus.navigator.setStatusBarStyle("dark")
			// #endif

		},
		mounted() {
			// #ifdef APP-PLUS
			this.initStatusBarStyle();
			// #endif
		},
		methods: {
			getSet() {
				var that = this;
				uni.request({
					url: that.$API.SPset(),
					method: 'GET',
					dataType: "json",
					success(res) {
						that.radiusBoxStyle = res.data.radiusStyle;
					},
					fail(error) {
					}
				})
			
			},
			// #ifdef APP-PLUS
			initStatusBarStyle() {
				var that = this;
				if (uni.getSystemInfoSync().platform === 'android') {
					plus.navigator.setStatusBarStyle('light'); // Android 平台
				} else {
					plus.navigator.setStatusBarStyle('light'); // iOS 平台

				}

			},
			onPageScroll(event) {
				this.scrollTop = event.scrollTop;
				if (this.scrollTop > 40) {
					if (uni.getSystemInfoSync().platform === 'android') {
						plus.navigator.setStatusBarStyle('dark'); // Android 平台
					} else {
						plus.navigator.setStatusBarStyle('dark'); // iOS 平台
					}
				} else {
					if (uni.getSystemInfoSync().platform === 'android') {
						plus.navigator.setStatusBarStyle('light'); // Android 平台
					} else {
						plus.navigator.setStatusBarStyle('light'); // iOS 平台
					}
				}
			},
			// #endif
			refresh() {
			      uni.startPullDownRefresh({
			        success: () => {
			        },
			      });
			      setTimeout(() => {
			        uni.stopPullDownRefresh({
			          success: () => {
			          },
			        });
			      }, 2000);
			    },
			totop() {
				// 返回顶部操作
				// #ifdef APP-PLUS
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				// #endif
				// #ifdef H5

				window.scrollTo({
					top: 0,
					behavior: 'smooth', // Optional: add smooth scrolling behavior
				});
				// #endif

			},
			// #ifdef APP-PLUS
			//权限检测
			showTC(){
				var that = this;
				var tc1 = false;
				let _permissionID = 'android.permission.WRITE_EXTERNAL_STORAGE';
				let _permissionID2 = 'android.permission.CAMERA';
				plus.android.checkPermission(_permissionID2,
					granted => {
						if (granted.checkResult == -1) {
							console.log('无相机权限');
							uni.showModal({
								title: '权限申请说明',
								content: '我们将申请获取相机权限和访问相册权限，便于您使用拍照上传您的照片/视频及用于更换头像、意见反馈、保存相册、发布动态等场景。',
								cancelText: "取消",
								confirmText: "同意",
								showCancel: true,
								confirmColor: '#000',
								cancelColor: '#666',
								success: (res) => {
									if (res.confirm) {
										console.log('弹窗同意');
										tc1 = true;
										that.requestPermissions();
									}else{
										console.log('弹窗取消');
										that.isTy = false
										tc1 = true;
									}
								}
							})
							//还未授权当前查询的权限，打开权限申请目的自定义弹框
							that.$nextTick(() => {
								setTimeout(() => {
									that.ani = 'uni-' + that.type
								},30)
							})
						}
					},
					error => {
						console.log(error.message);
					}
				);
				plus.android.checkPermission(_permissionID,
					granted => {
						if (granted.checkResult == -1) {
							console.log('无相册权限');
							if(!tc1){
								uni.showModal({
									title: '权限申请说明',
									content: '我们将申请获取相机权限和访问相册权限，便于您使用拍照上传您的照片/视频及用于更换头像、意见反馈、保存相册、发布动态等场景。',
									cancelText: "取消",
									confirmText: "同意",
									showCancel: true,
									confirmColor: '#000',
									cancelColor: '#666',
									success: (res) => {
										if (res.confirm) {
											console.log('弹窗同意');
											return that.requestPermissions();
										}else{
											console.log('弹窗取消');
											that.isTy = false
										}
									}
								})
							}
							
							//还未授权当前查询的权限，打开权限申请目的自定义弹框
							that.$nextTick(() => {
								setTimeout(() => {
									that.ani = 'uni-' + that.type
								},30)
							})
						}
					},
					error => {
						console.log(error.message);
					}
				);
				
			},
			requestPermissions() {
				let _this = this;
			
					let _permissionID = 'android.permission.WRITE_EXTERNAL_STORAGE';
					let _permissionID2 = 'android.permission.CAMERA';
					
					plus.android.checkPermission(_permissionID2,
						granted => {
							if (granted.checkResult == -1) {
								//还未授权当前查询的权限，打开权限申请目的自定义弹框
								
								_this.$nextTick(() => {
									setTimeout(() => {
										_this.ani = 'uni-' + _this.type
									},30)
								})
							}
						},
						error => {
							console.log(error.message);
						}
					);
					plus.android.requestPermissions([_permissionID2],
						(e) => {
							//关闭权限申请目的自定义弹框
							_this.ani = '';
							_this.$nextTick(() => {
								
							})
							console.log(e,'kkkkk')
							if (e.granted.length > 0) {
								//当前查询权限已授权
								console.log('1已同意');
								plus.android.checkPermission(_permissionID,
									granted => {
										if (granted.checkResult == -1) {
											//还未授权当前查询的权限，打开权限申请目的自定义弹框
											
											_this.$nextTick(() => {
												setTimeout(() => {
													_this.ani = 'uni-' + _this.type
												},30)
											})
										}
									},
									error => {
										console.log(error.message);
									}
								);
								plus.android.requestPermissions([_permissionID],
									(e) => {
										//关闭权限申请目的自定义弹框
										_this.ani = '';
										_this.$nextTick(() => {
											
										})
										console.log(e,'kkkkk')
										if (e.granted.length > 0) {
											//当前查询权限已授权
											console.log('2已同意');
											_this.isTy = true
										}
										if (e.deniedAlways.length > 0) {
											//当前查询权限已被永久禁用，此时需要引导用户跳转手机系统设置去开启
											uni.showModal({
												title: '温馨提示',
												content: '您没有给予访问相册权限，不给予权限将无法使用该功能，立即去设置开启？',
												cancelText: "取消",
												confirmText: "去设置",
												showCancel: true,
												confirmColor: '#000',
												cancelColor: '#666',
												success: (res) => {
													if (res.confirm) {
														_this.goSetting();
													}else{
														_this.isTy = false
													}
												}
											})
										}
									})
							}
							if (e.deniedAlways.length > 0) {
								//当前查询权限已被永久禁用，此时需要引导用户跳转手机系统设置去开启
								uni.showModal({
									title: '温馨提示',
									content: '您没有给予使用相机权限，不给予权限将无法使用该功能，立即去设置开启？',
									cancelText: "取消",
									confirmText: "去设置",
									showCancel: true,
									confirmColor: '#000',
									cancelColor: '#666',
									success: (res) => {
										if (res.confirm) {
											_this.goSetting();
										}else{
											_this.isTy = false
										}
									}
								})
							}
						})
				
			},
			//跳转手机系统设置
			goSetting() {
					var Intent = plus.android.importClass("android.content.Intent");
					var Settings = plus.android.importClass("android.provider.Settings");
					var Uri = plus.android.importClass("android.net.Uri");
					var mainActivity = plus.android.runtimeMainActivity();
					var intent = new Intent();
					intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
					var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
					intent.setData(uri);
					mainActivity.startActivity(intent);
			},
			// #endif
			
			userStatus() {
				var that = this;
				that.$Net.request({

					url: that.$API.userStatus(),
					data: {
						"token": that.token
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 0) {

							if (that.userInfo != null) {
								that.isLoginShow = true;
							}
							localStorage.removeItem('userinfo');
							localStorage.removeItem('token');

							that.userInfo = null;
						} else {

							if (localStorage.getItem('userinfo')) {

								var userInfo = JSON.parse(localStorage.getItem('userinfo'));
								if (res.data.data.group) {
									userInfo.group = res.data.data.group;
								}
								localStorage.setItem('userinfo', JSON.stringify(userInfo));
								// if(res.data.data.avatar){
								// 	that.userInfo = res.data.data.avatar;
								// }

							}

						}
					},
					fail: function(res) {
						uni.showToast({
							title: "网络开小差了哦",
							icon: 'none'
						})
					}
				})
			},
			change(index) {
				var that = this;
				if (index == 2) {
					that.orderKey = 'created';
					that.current = index;
					that.orderKey = that.titlePostList[that.current].order;
					console.log(that.orderKey + index);
					that.page = 1;
					that.getPostList(false);
				} else {
					that.current = index;
					that.orderKey = that.titlePostList[that.current].order;
					console.log(that.orderKey + index);
					that.page = 1;
					that.getPostList(false);
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				});
			},
			formatDate(datetime) {
				var datetime = new Date(parseInt(datetime * 1000));
				// 获取年月日时分秒值  slice(-2)过滤掉大于10日期前面的0
				var year = datetime.getFullYear(),
					month = ("0" + (datetime.getMonth() + 1)).slice(-2),
					date = ("0" + datetime.getDate()).slice(-2),
					hour = ("0" + datetime.getHours()).slice(-2),
					minute = ("0" + datetime.getMinutes()).slice(-2);
				//second = ("0" + date.getSeconds()).slice(-2);
				// 拼接
				var result = year + "-" + month + "-" + date + " " + hour + ":" + minute;
				// 返回
				return result;
			},
			loadMore() {
				var that = this;
				that.moreText = "正在加载中...";
				that.isLoad = 1;
				that.getPostList(true);

			},
			goLogin() {
				uni.navigateTo({
					url: '/pages/user/login'
				});
			},
			getSectionInfo() {
				var that = this;
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				}
				that.$Net.request({

					url: that.$API.sectionInfo(),
					data: {
						"id": that.id,
						"token": token
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 1) {
							that.name = res.data.data.name;
							that.pic = res.data.data.pic;
							that.bg = res.data.data.bg;
							that.parent = res.data.data.parent;
							that.slug = res.data.data.slug;
							that.text = res.data.data.text;
							that.restrict = res.data.data.restrictKey;
							that.moderators = res.data.data.moderators;
							that.postNum = res.data.data.postNum;
							that.clockNum = res.data.data.clockNum;
							that.isFollow = res.data.data.isFollow;
							that.isClock = res.data.data.isClock;
						}

					},
					fail: function(res) {
						uni.showToast({
							title: "网络开小差了哦",
							icon: 'none'
						})
					}
				})
			},
			sectionFollow(type) {
				var that = this;
				uni.showLoading({
					title: "加载中"
				});
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				}
				var data = {
					"sectionId": that.id,
					"token": token,
					"type": type
				}
				that.$Net.request({
					url: that.$API.sectionFollow(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 1) {
							that.getSectionInfo();
						}

					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: "网络开小差了哦",
							icon: 'none'
						})
					}
				})
			},
			sectionClock() {
				var that = this;
				uni.showLoading({
					title: "加载中"
				});
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				}
				var data = {
					"sectionId": that.id,
					"token": token
				}
				that.$Net.request({
					url: that.$API.sectionClock(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 1) {
							that.getSectionInfo();
						}

					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: "网络开小差了哦",
							icon: 'none'
						})
					}
				})
			},
			addPost() {
				var that = this;

				if (!localStorage.getItem('token') || localStorage.getItem('token') == "") {
					uni.showToast({
						title: "请先登录哦",
						icon: 'none'
					})
					return false;
				}
				if(that.isTy==false&&that.isHuaWei==1){
					that.showTC()
				}
				uni.navigateTo({
					url: '/pages/edit/addPost?section=' + that.name + "&sectionid=" + that.id
				});
				// uni.navigateTo({
				// 	url: '/pages/forum/addPost?section='+that.name+"&sectionid="+that.id
				// });
			},
			moderator(id) {
				var that = this;
				if (!localStorage.getItem('token') || localStorage.getItem('token') == "") {
					uni.showToast({
						title: "请先登录哦",
						icon: 'none'
					})
					return false;
				}
				uni.navigateTo({
					url: '/pages/manage/moderator?id=' + id
				});
			},
			setModerator(id, name) {
				var that = this;
				if (!localStorage.getItem('token') || localStorage.getItem('token') == "") {
					uni.showToast({
						title: "请先登录哦",
						icon: 'none'
					})
					return false;
				}
				uni.navigateTo({
					url: '/pages/manage/setModerator?id=' + id + '&resOf=true&name=' + name
				});
			},
			getTopList() {
			    var that = this;
			    var token = "";
			    if (localStorage.getItem('userinfo')) {
			        var userInfo = JSON.parse(localStorage.getItem('userinfo'));
			        token = userInfo.token;
			    }
			
			    var globalData = {
			        "status": "1",
			        "isTop": '2'
			    };
			
			    that.$Net.request({
			        url: that.$API.postList(),
			        data: {
			            "searchParams": JSON.stringify(that.$API.removeObjectEmptyKey(globalData)),
			            "limit": 5,
			            "page": 1,
			            "token": token
			        },
			        header: {
			            'Content-Type': 'application/x-www-form-urlencoded'
			        },
			        method: "post",
			        dataType: 'json',
			        success: function(globalRes) {
			            if (globalRes.data.code == 1) {
			                var globalTopList = globalRes.data.data.map(item => {
			                    item.isTop = '2';
			                    return item;
			                });
			
			                var sectionData = {
			                    "section": that.id,
			                    "status": "1",
			                    "isTop": '1'
			                };
			
			                that.$Net.request({
			                    url: that.$API.postList(),
			                    data: {
			                        "searchParams": JSON.stringify(that.$API.removeObjectEmptyKey(sectionData)),
			                        "limit": 5,
			                        "page": 1,
			                        "token": token
			                    },
			                    header: {
			                        'Content-Type': 'application/x-www-form-urlencoded'
			                    },
			                    method: "post",
			                    dataType: 'json',
			                    success: function(sectionRes) {
			                        if (sectionRes.data.code == 1) {
			                            var sectionTopList = sectionRes.data.data.map(item => {
			                                item.isTop = '1';
			                                return item;
			                            });
			
			                            that.topList = globalTopList.concat(sectionTopList);
			
			                        }
			                    },
			                    fail: function(sectionRes) {
			                       
			                    }
			                });
			            }
			        },
			        fail: function(globalRes) {
			            
			        }
			    });
			},

			toEdit(parent, id, name) {
				var that = this;
				uni.navigateTo({
					url: '/pages/manage/sectionEdit?parent=' + parent + '&sort=section&type=edit' + '&id=' + id +
						'&name=' + name
				});
			},
			getPostList(isPage,isLogin) {
				var that = this;
				var page = that.page;
				if(that.submitStatus1){
					return false;
				}
				that.submitStatus1 = true;
				var token = "";
				if(!isLogin){
					localStorage.setItem('isbug','1');
				}
				
				
				if (isPage) {
					page++;
				}
				var data = {
					"section": that.id,
					"status": "1",
					"isTop": '0',
				}
				var order = that.orderKey;
				if (order == 'recommend') {
					data.isrecommend = 1;
					that.orderKey = 'created'
				} else {
					data.order = order;
				}
				that.$Net.request({
					url: that.$API.postList(),
					data: {
						"searchParams": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"limit": 10,
						"page": page,
						"order": that.orderKey,
						"token": token
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if(!isLogin){
							localStorage.removeItem('isbug');
						}
						that.submitStatus1 = false;
						that.isLoad = 0;
						if (res.data.code == 1) {
							var list = res.data.data;
							if (list.length > 0) {
								var num = res.data.data.length;
								var rand = Math.floor(Math.random() * num);
								var pushAdsInfo = null;
								// #ifdef APP-PLUS || H5
								if(that.isvip==0){
									if(localStorage.getItem('pushAds')){
										var pushAds = JSON.parse(localStorage.getItem('pushAds'));
										var adsNum = pushAds.length;
										if(adsNum>0){
											var adsRand = Math.floor(Math.random()*adsNum);
											pushAdsInfo = pushAds[adsRand];
											pushAdsInfo.isAds = 1;
										}
									}
								}
								// #endif
								var postList = [];
								for (var i in list) {

									list[i].isAds = 0;
									postList.push(list[i]);
									// #ifdef APP-PLUS || H5
									var isAds = Math.round(Math.random());
									if (isAds == 1) {
										if (i == rand && pushAdsInfo != null) {
											postList.push(pushAdsInfo);
										}
									}
									// #endif
								}
								if (isPage) {
									that.page++;
									that.postList = that.postList.concat(postList);
								} else {
									that.postList = postList;
								}
							} else {
								if (isPage) {
									that.moreText = "没有更多数据了";
								} else {
									that.postList = [];
								}

							}
						} else {
							if (res.data.msg == "用户未登录或Token验证失败") {
								if (isLogin) {
									that.isuserlogin = true
								}else{
									that.getPostList(isPage, true);
								}
							}
						}
						var timer = setTimeout(function() {
							that.isLoading = 1;
							clearTimeout('timer')
						}, 300)
						that.isLoading = 1;
					},
					fail: function(res) {
						if(!isLogin){
							localStorage.removeItem('isbug');
						}
						that.submitStatus1 = false;
						that.isLoad = 0;
						that.moreText = "加载更多";
						var timer = setTimeout(function() {
							that.isLoading = 1;
							clearTimeout('timer')
						}, 300)
						that.isLoading = 1;
					}
				})
			},
			userPurview() {
				var that = this;
				var uid = 0;
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					uid = userInfo.uid;
				}
				var data = {
					"uid": uid,
				}
				that.$Net.request({
					url: that.$API.userPurview(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {


						if (res.data.code == 1) {
							var list = res.data.data;
							if (list.length > 0) {
								for (var i in list) {
									if (list[i].sectionId == that.id) {
										that.myPurview = list[i].purview;
									}
								}

							}
							if (localStorage.getItem('userinfo')) {
								var myInfo = JSON.parse(localStorage.getItem('userinfo'));
								if (myInfo.group == 'administrator' || myInfo.group == 'editor') {
									that.myPurview = 5;
								}

							}


						}
					},
					fail: function(res) {

					}
				})

			},
			toSearch() {
				var that = this;

				uni.redirectTo({
					url: '/pages/contents/search'
				});
			},
			goInfo(id) {
				var that = this;
				uni.navigateTo({
					url: '/pages/forum/info?id=' + id
				});
			},
			goModerators(id){
				var that = this;
				uni.navigateTo({
					url: '/pages/forum/moderators?id='+id
				});
			}

		}
	}
</script>

<style>
	.forum-post-btn-1 {
		position: fixed;
		z-index: 888;
		bottom: 200upx;
		right: 60upx;
		width: 90upx;
		height: 90upx;
		font-size: 40upx;
		color: #fff;
		border-radius: 50%;
		text-align: center;
		line-height: 90upx;
	}

	.forum-post-btn-2 {
		position: fixed;
		z-index: 888;
		bottom: 300upx;
		right: 60upx;
		width: 90upx;
		height: 90upx;
		font-size: 40upx;
		color: #fff;
		border-radius: 50%;
		text-align: center;
		line-height: 90upx;
	}
	.box-shadow-1 {
		box-shadow: 0 0 10upx #31C9E8bf;
	}
	.box-shadow-2 {
		box-shadow: 0 0 10upx #Ff9700bf;
	}

	.text-content-1 {
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.text-content-2 {
		font-size: 22upx;
		overflow: hidden;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}

	.img-border-radius-10 image {
		border-radius: 20upx;
	}

	.img-border-radius-32 image {
		border-radius: 44upx;
	}

	.img-border-radius-50 image {
		border-radius: 50%;
	}

	.tn-margin-top-xxl {
		margin-top: 60upx;
	}

	.center-container {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>