<template>
	<!--pages/suggestList/suggestList.wxml-->
	<view style="padding-bottom: 10px;">
	    <!-- 建议列表 -->
	    <view class="suggestContainer">
	        <view class="suggest" @click="toSuggestDetail(item)" v-for="(item, index) in suggestion" :key="item">
	            <view class="suggestion">
	                <view class="suggestHead">
	                    <view>标题</view>
	                    <view class="suggestTitle">{{item.adviseTitle}}</view>
	                </view>
	                <view class="suggestBody">
	                    <view>日期</view>
	                    <view class="suggestContent">{{item.fistDatetime}}</view>
	                </view>
	            </view>
	            <view>
	                <view class="dispose">{{item.status}}</view>
	            </view>
	       
			</view>
	    											
		</view>

		<view v-if="isShow" class="toWriteSuggestion">
		        <text class="writeSuggestion" @click="headPage()">首页</text>	    
			
			
			    <text class="writeSuggestion" @click="frontPage()">上一页</text>	    
			
				<text style=" font-size: 35rpx; color: black;margin-left: 5px;padding-top: 5px;"> {{obj.pageNum}}/{{Math.ceil(total/obj.pageSize)}} </text>
			
			
				<text class="writeSuggestion" @click="nextPage()">下一页</text>	    
				
			
				<input  v-model="search" style="border: lawngreen 1px solid;
											   width: 30px;
											   float: right;
											   margin-left: 5px;
											   height: 27px;
											   text-align: center;
											   background-color: #ffffff;
											   "/>
											   
				<text class="writeSuggestion"  @click="goalPage()"  style="float: right;margin-right: 10px;">跳转</text>
				
														
		</view>
		
	</view>

</template>

<script>
	
	export default {
		data() {
			return {
				suggestion: [],
				obj: {
					pageSize: 6,
					pageNum: 1
				},
				total: 0,
				currentList: [],
				search: '',
				isShow: false
			};
		},
		
		onPullDownRefresh() {
			this.obj.pageNum = 1;
			this.init();
			uni.stopPullDownRefresh();
		},
		
	/* 	onReachBottom() {
			// 判断是否有下一页的数据
			if (this.obj.pageNum * this.obj.pageSize >= this.total)
			
			return uni.$showMsg('已经是最后一页数据了!')
			
			this.obj.pageNum += 1
			this.init()
			
		}, */
		
		onShow(){
			this.obj.pageNum = 1;
			this.init();
		},
		created(){
			this.obj.pageNum = 1;
			this.init();
		},
		
		methods:{
			async init(){
										
				const { data: result } =await uni.$http.get('/education/my-suggestion/findAllAdvise',this.obj)
								
				this.suggestion = result.data.data;
			
				this.total = result.data.count;
				
				
				
				if(this.obj.pageNum==1){
					this.currentList = this.suggestion;
				}
				else{
					
					for(var item of this.suggestion) 
					{
						this.currentList.push(item);
					}
					
				}
				
				this.isShow = true;
				
			},
			
			// 点击建议列表，跳转到对应的建议详情页
				
			toSuggestDetail(item){
				let suggestion = JSON.stringify(item)
				uni.navigateTo({
					url: '/subpkg/allsuggestionDetail/allsuggestionDetail?item=' + suggestion
				})
			},
			
			headPage(){
				this.obj.pageNum = 1;
				this.init();
				this.search = "";
			},
			frontPage(){
				if(this.obj.pageNum==1){		
					uni.$showMsg('已经是第一页了')
				}else{
					this.obj.pageNum = this.obj.pageNum - 1;
					this.init();
					console.log("front",this.obj);
				
				}
				
			},
			nextPage(){
				if(this.obj.pageNum== Math.ceil(this.total/this.obj.pageSize)){
						uni.$showMsg('已经是最后一页了')
				}else{
					this.obj.pageNum = this.obj.pageNum + 1;
					this.init();
					console.log("next",this.obj);
				
				}
			},
			goalPage(){
				
					
				if(this.search.length==0){
					uni.$showMsg('请输入页码!')
				}
				
				else if(!/^\d+$/.test(this.search))
				{
				  uni.$showMsg('请输入合法的页码!')
				  
				 }
				
				
				
				
				else{
					let current = parseInt(this.search);
					
					console.log("num",current);
					
					if(current < 1){
						uni.$showMsg('该页码不存在!')
					}
					else if(current > Math.ceil(this.total/this.obj.pageSize)){
						uni.$showMsg('超出页码范围!')
					}
					else{
						this.obj.pageNum = current;
						this.init();
						this.search = "";
					}
					
				}
				

			}
			
		}
	}
</script>
<style lang="scss"scoped>
	/* pages/suggestList/suggestList.wxss */
	
	.toWriteSuggestion{
	    display: flex;
	    position: relative;
	    justify-content: center;		
	}
	
	/* 页面背景 */
	page{
	    /* height: 100%; */
	    /* height: auto !important; */
	    background-color: #E2F0D9;
	}
	
	/* 建议列表区 */
	.suggestContainer{
	    height: 100%;
	    padding-bottom: 10rpx;
		
	}
	
	/* 单条建议的背景 */
	.suggest{
	    display: flex;
	    padding: 20rpx;
	    margin: 20rpx 10rpx;
	    height: 140rpx;
	    border-radius: 30rpx;
	    background-color: #FFF2CC;
	}
	
	/* 单条建议左侧标题和内容摘要 */
	.suggestion{
	    width: 75%;
	}
	
	/* 标题和内容摘要布局 */
	.suggestHead,
	.suggestBody{
	    display: flex;
	}
	
	/* 摘要 */
	.suggestBody{
	    margin-top: 10rpx;
	}
	
	/* 标题详情和内容详情左边距 */
	.suggestTitle,
	.suggestContent{
	    margin-left: 20rpx;
	}
	
	/* 标题内容详情 */
	.suggestTitle{
	    width: 65%;
	    white-space: nowrap;
	    overflow: hidden;
	    text-overflow: ellipsis;
	}
	
	/* 内容摘要详情 */
	.suggestContent{
	    width: 80%;
	    overflow: hidden;
	    text-overflow: ellipsis;
	    display: -webkit-box;
	    -webkit-box-orient: vertical;
	    -webkit-line-clamp: 2;
	}
	
	/* 处理状态 */
	.dispose{
	    font-weight: bold;
	    color: red;
	    margin-left: 30rpx;
	}
	
	/* 写建议按钮 */
	.toWriteSuggestion{
	    display: flex;
	    position: relative;
	    justify-content: center;
	}
	
	.writeSuggestion{
	    background-color: #ffffff;
	    font-size: 35rpx;
	    color: gray;
		border: lawngreen solid 1px;
		padding: 10rpx 20rpx;
		margin-left: 6px;
	}

</style>