<template>
	<view>
		
		<view class="padding bg-themeRed">
			<view class="text-center padding-tb">
				<view class="text-sl padding-bottom-xs">{{redmoneyarr.status0}}</view>
				<view>累计获得奖励（积分）</view>
			</view>
			<view class="flex solid-bottom padding-top justify-between">
				<view>待发放：<text>{{redmoneyarr.status2}}</text> 积分</view>
				<view>已发放：<text>{{redmoneyarr.status3}}</text> 积分</view>
			</view>
		</view>
		
		<scroll-view scroll-x class="bg-white nav solid-bottom">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="status==0?'text-red cur':''" @tap="tabSelect" data-status="0">全部</view>
				<view class="cu-item flex-sub" :class="status==1?'text-red cur':''" @tap="tabSelect" data-status="1">未入职</view>
				<view class="cu-item flex-sub" :class="status==2?'text-red cur':''" @tap="tabSelect" data-status="2">已入职</view>
				<view class="cu-item flex-sub" :class="status==3?'text-red cur':''" @tap="tabSelect" data-status="3">已发放</view>
			</view>
		</scroll-view>

		<view class="cu-list menu-avatar">
			<view class="cu-item" v-for="(item,index) in plist" :key="index">
				<view class="cu-avatar round lg" :style="'background-image:url('+item.user.avatar+');'"></view>
				<view class="content">
					<view class="text-grey">{{item.user.nickname}}</view>
					<view class="text-gray text-sm flex">{{item.createtime}}</view>
				</view>
				<view class="action" v-if="item.status>=2">
					<view class="text-red text-lg">{{item.redmoney}}积分</view>
				</view>
			</view>
		</view>
		
		<uni-load-more :status="pstatus"></uni-load-more>
		
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				userinfo: {},
				redmoneyarr: [],
				
				status: 0,
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(){
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/myteam");
			if (_this.userinfo===false){
				return false;
			}
			_this.$req.ajax({
				path: "my/myteam",
				data: {
					userid: _this.userinfo.id 
				}
			}).then((data) => {
				_this.redmoneyarr = data.redmoneyarr;
				
				console.log(": " + JSON.stringify(_this.redmoneyarr));
				
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			getMore: function() {
				_this.$req.ajax({
					path: "my/getteam",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						userid: _this.userinfo.id,
						status: _this.status
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			tabSelect: function(e) {
				_this.status = e.currentTarget.dataset.status;
				_this.pageRefresh();
			},
		}
	}
</script>

<style>
</style>
