<template>
	<view 
		class="msgList"
	>
		<view class="mt30">
			<view class="msgItem" v-for="(item,index) in msgList" :key="index" @click="toPromiseInfo(item)">
				<view class="msgItemLeft">
					<image class="fixedTitle" src="/static/router_3.jpg"></image>
				</view>
				<view class="msgItemRight">
					<text class="msgItemTitle">我的承诺书</text>
					<text>{{item.created_at}}</text>
				</view>
			</view>
		</view>
		<view class="loading" v-if="isMore">没有更多数据了</view>
	</view>
</template>

<script>
	
	import { promiseList } from "../../api/index.js"
	
	export default {
		data(){
			return {
				msgList:[],
				isMore:false,
				page_index:1,
				page_size:10,
				scrollType:true
			}
		},
		onShow() {
			this.create({
				page_index:1,
				page_size:10,
			})
		},
		onPullDownRefresh:function(){
			this.scrollType=true
			this.create({
				page_index:1,
				page_size:this.page_index*this.page_size,
			});
		},
		onReachBottom:function(){
			if(!this.isMore){
				this.page_index++;
				this.scrollType=false
				if(!this.loading){
					this.create({
						page_index:this.page_index,
						page_size:10
					})
				}
			}
		},
		methods:{
			create(params){	
				const that = this
				this.$nextTick(function(){
					promiseList(params).then(res=>{
						uni.stopPullDownRefresh();  //停止下拉刷新动画
						const { error_code } = res
						if(error_code===200){
							const { data } = res
							if(data.length<1 || data.length<that.page_size){
								that.isMore=true
							}
							if(that.scrollType){
								that.msgList=data
							}else{
								that.msgList=that.msgList.concat(data)
							}
						}
					})
				})
			},
			toPromiseInfo(item){
				this.$store.commit("change_promise",{
					url:item.imageUrl,
					time:item.created_at
				})
				uni.navigateTo({
					url:`/pages/promiseInfo/promiseInfo`
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		width: 100%;
		height: 100%;
		background: $uni-bg-color-normal;
	}
	.msgList{
		width: 100%;
		height: 100%;
	}
	.mt30{
		padding-top: 30rpx;
	}
	.msgItem{
		width: 100%;
		height: 156rpx;
		background-color: $uni-bg-color;
		position: relative;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}
	.msgItem::after,.msgItem::before{
		content: "";
		display: block;
		width: 42rpx;
		height: 42rpx;
		border-radius: 50%;
		position: absolute;
		background: $uni-bg-color-normal;
		left: 138rpx;
	}
	.msgItem::before{
		top: 0;
		margin-top: -21rpx;
	}
	.msgItem::after{
		bottom: 0;
		margin-bottom: -21rpx;
	}
	.fixedTitle{
		display: block;
		width: 72rpx;
		height: 72rpx;
		background-size: 100% 100%;
	}
	.msgItemLeft{
		width: 159rpx;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
	}
	.msgItemLeft::after{
		content: "";
		display: block;
		width: 6rpx;
		height: 90rpx;
		background: url(../../static/border_circle.jpg);
		background-size: 100% 100%;
		position: absolute;
		top: 50%;
		right: 0;
		margin-top: -45rpx;
		margin-right: -3rpx;
	}
	.msgItemRight{
		width: calc(100% - 159rpx - 89rpx - 57rpx);
		padding: 0 89rpx 0 57rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		font-size: 24rpx;
		color: #999999;
	}
	.msgItemTitle{
		font-size: 28rpx;
		color: #323332;
		margin-bottom: 10rpx;
		display: block;
	}
	.loading{
		font-size: 24rpx;
		text-align: center;
		padding-bottom: 10px;
	}
</style>
