<template>
	<view>
		
		<view class="padding bg-themeRed">
			<view class="text-center padding-top">
				<view class="text-sl padding-bottom-xs">{{userinfo.balance}}</view>
				<view>
					余额
				</view>
				<button class="cu-btn round" @tap="goPage('/pages/my/getmoney')">我要提现</button>
			</view>
			<view class="flex solid-bottom padding-top justify-between">
				<view>上月获得：<text>{{month_balance}}</text> 元</view>
				<view>累计已获：<text>{{userinfo.balance_total}}</text> 元</view>
			</view>
		</view>

		<view class="cu-list menu">
			<block v-for="(item,index) in plist" :key="index">
				<view class="cu-item">
					<view class="content padding-tb-sm padding-right-sm">
						<view>
							{{item.title}}
						</view>
						<view class="text-gray text-sm">{{item.createtime}}</view>
						<view class="text-gray text-sm">
							{{item.remark}}
						</view>
					</view>
					<view class="action text-red" v-if="item.value>0">+{{item.value}}元</view>
					<view class="action text-red" v-else>{{item.value}}元</view>
				</view>
			</block>
		</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: {},
				month_balance: 0,
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(){ 
			_this = this;
		},
		onShow: function() {
			_this.userinfo = _this.checkLogin("/pages/my/mybag");
			if (_this.userinfo===false){
				return false;
			}
			_this.myBag();
		},
		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/getbag",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						userid: _this.userinfo.id
					}
				}).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
					});
				});
			},
			
			myBag: function() {
				_this.$req.ajax({
					path: "my/mybag",
					data: {
						userid: _this.userinfo.id 
					}
				}).then((data) => {
					_this.userinfo = data.user;
					_this.month_balance = data.month_balance;
					_this.getMore();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			goPage: function(pageurl) {
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},
		}
	}
</script>

<style>
</style>
