<template>
	<view class="coach">
		<view class="coach-list">
			<view class="item" v-for="(a,i) in list" :key="i">
				<view class="info">
					<view class="name">{{a.remake}}<text>{{a.integral}}</text></view>
					<view class="desc">{{a.created_at}}</view>
				</view>
			</view>
			<view class="empty" v-if="total == 0">
				<image src="https://www.lijkj.cn/static/empty.png"></image>
				<view class="txt">暂无数据 ~</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				total: 0,
				page: 1,
				list: [],
				id: ""
			};
		},
		onLoad(o) {
			this.id = o.id;
			this.getList(2);
		},
		onReachBottom(){
			uni.showLoading({
				title: "加载中"
			})
			if(this.list.length <= this.total){
				this.page ++
				setTimeout(()=>{
					this.getList(1)
				},1000)
			}
		},
		methods: {
			//数组对象去重
			arrayUnique (arr, name) {
				var hash = {};
				return arr.reduce(function (item, next) {
					hash[next[name]]
						? ""
						: (hash[next[name]] = true && item.push(next));
					return item;
				}, []);
			},
			async getList(type) {
				if(type == 2){
					this.page = 1;
				}
				
				const { code, data, msg } = await this.$api.integralLog({
					page: this.page
				})
				if(code == 200){
					this.total = data.total;
					if(type == 2){
						this.list = data.list;
					}else{
						this.list = this.arrayUnique([...this.list,...data.list],"id");
						uni.hideLoading();
					}
				}
			},
		}
	}
</script>

<style lang="scss">
.coach{
	.search{
		width: 700rpx;
		height: 80rpx;
		background: #fff;
		border-radius: 80rpx;
		display: flex;
		align-items: center;
		margin: 0 auto;
		margin-top: 20rpx;
		image{
			width: 32rpx;
			height: 32rpx;
			margin-right: 20rpx;
			margin-left: 20rpx;
		}
		input{
			flex: 1;
			font-weight: 400;
			font-size: 30rpx;
			height: 60rpx;
			line-height: 60rpx;
			color: #999999;
			text-align: left;
		}
	}
	&-list{
		padding: 0 25rpx 25rpx;
		overflow: hidden;
		.item{
			background-color: #FFFFFF;
			overflow: hidden;
			padding: 20rpx;
			display: flex;
			align-items: flex-start;
			margin-top: 20rpx;
			border-radius: 20rpx;
			position: relative;
			.pic{
				width: 80rpx;
				height: 80rpx;
				margin-right: 20rpx;
				border-radius: 80rpx;
			}
			.info{
				flex: 1;
				.name{
					font-weight: 500;
					font-size: 28rpx;
					color: #333333;
					margin-top: 10rpx;
					image{
						width: 40rpx;
						height: 40rpx;
						float: right;
					}
					text{
						float: right;
					}
				}
				.desc{
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
					margin-top: 20rpx;
				}
			}
		}
	}
}
</style>
