<template>
	<view>
		<view class="grxx">
			<view class="grxxItem" v-for="(item,index) in messageList" :key="index" @click="info(item)">
				<view class="ygxm">
					<text>注册消息</text>
					<text>{{item.createTime}}</text>
				</view>
				<view class="sfzhm">
					{{item.content}}
				</view>
			</view>
		</view>
		<view class="ydd" v-if="isReachBottom">
			~<没有了>~
		</view>
	</view>
</template>

<script>
	import {
		postRequest,
		getRequest
	} from '../../api/api.js'
	export default {
		data() {
			return {
				//为true时，停止下拉加载
				isReachBottom: false,
				//总list
				messageList: [],
				listData: {
					current: 1,
					isRead: "",
					orders: [{
						asc: true,
						column: ""
					}],
					size: 10,
					type: "",
					userId: ""
				},
				total: 0
			}
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			if (this.isReachBottom) {
				return
			} else {
				this.listData.current++;
				let list = this.messageList;
			    this.getList();
			}
		},
		methods: {
			info(item) {
				//记录已读状态
				postRequest('/sysMessage/updateReadStatus',{id:item.id}).then(res=>{
					
				})
				uni.navigateTo({
					url:item.url+'?businessId='+item.businessId+'&msgId='+item.id
				})
			},
			getList() {
				postRequest('/sysMessage/findAllMsgByUser', this.listData).then(res => {
					if (res.code == '200' && res.data != null) {
						if (this.messageList.length < 0) {
							this.messageList = res.data.records;
							this.total = res.data.total;
						} else {
							let list = []
							list = res.data.records;
							if (list.length > 0) {
								console.log(list)
								list.forEach(item => {
									this.messageList.push(item)
								})
							}
						}
						if (this.listData.current == res.data.pages) {
							this.isReachBottom = true
						}
					}
				})
			}
		}
	}
</script>

<style>
	.grxx {
		padding: 5%;
	}

	.grxxItem .sfzhm {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px;
		font-size: 84%;
		color: #999999;
		position: relative;
	}

	.grxxItem .mdd {
		justify-content: left;
	}

	.grxxItem .mdd input {
		width: 70%;
		margin-left: 10px;
	}

	.hxx {
		position: absolute;
		color: red;
		left: 3px;
		top: 25%;
	}


	.grxxItem {
		margin: 14px 0;
		border-radius: 5px;
		overflow: hidden;
		box-shadow: 0px 2px 15px 3px rgba(0, 0, 0, 0.1);
	}

	.grxxItem .ygxm {
		padding: 10px;
		background-color: #caccceab;
		display: flex;
		justify-content: space-between;
	}

	.grxxItem .ygxm text:last-of-type {
		color: #8d8888;
		font-size: 14px;
	}

	.ydd {
		text-align: center;
		padding: 5px;
		color: #cac5c5;
	}
</style>
