<template>
	<view>
		<view class="w100 bg-blue  plr-36 ptb-40">
			<view class="flex">
				<view class="white">
					<view class="size-28">
						账户余额（元）
					</view>
					<view class="size-28 mt-20">
						￥{{userInfo.money}}
					</view>
					<view class="size-28 mt-20">
						可提金额：￥{{money}}
					</view>
				</view>
				<view class="cash text-center blue bg-white" @click="goCash"  v-if="userInfo.ts_status==1">
					提现
				</view>
			</view>
		</view>
		<view class="">
			<view class="plr-36 blue flex size-26" style="background:#f3f0ff;height: 60rpx;">
				平台将收取30%服务费
			</view>
			<view class="ml-36 size-32 bold mt-40">
				余额明细
			</view>
			<empty v-if="list.length==0" top="150" text="暂无记录"></empty>
			<view class="flex ml-36 mt-30 pr-36 pb-30 bb" v-for="(item,i) in list" :key="i">
				<view class="">
					<view class="size-32">
						{{item.msg}}
					</view>
					<!-- <view class="size-28 mt-10">
						招银大厦--翰林国际城
					</view> -->
					<view class="size-26 mt-10 gray-2">
						{{item.createtime}}
					</view>
				</view>
				<view class="size-32" style="color: #08ab90;" v-if="item.fluctuate_type==1">
					+{{item.amount}}
				</view>
				<view class="size-32" style="color: #d64b62;" v-if="item.fluctuate_type==2">
					-{{item.amount}}
				</view>
			</view>
		</view>
		<u-loadmore v-if="list.length>9" :status="status" icon-type="flower" bg-color="#fff" :load-text="loadText" margin-top="30" margin-bottom="30"/>
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				money:'',//可提现金额
				list:[],
				page:1,
				status: 'nomore',
				loadText: {
					loadmore: '上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
			}
		},
		computed:{
			...mapState(['userInfo'])
		},
		onLoad() {
			this.$store.dispatch('updateUserInfo')
		},
		onShow() {
			this.page = 1
			this.list = []
			this.getmoney()
			this.init()
		},
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			
			this.init()
		},
		methods: {
			goCash(){
				uni.navigateTo({
					url:'/pages/my/cash?money=' + this.money
				})
			},
			// 我的收入
			getmoney() {
				this.$http('/addons/ddrive/user/userIncome', "POST").then(data => {
					console.log(data);
					this.money = data.withdraw_money
				})
			},
			// 账单
			init(){
				this.status = "loading";
				this.$http('/addons/ddrive/user/assets',"POST").then(data=>{
					console.log(data);
					if(data.data.length < 10){
						this.status = "nomore"
					}else{
						this.page = this.page + 1
						this.status = "loadmore"
					}
					this.list = this.list.concat(data.data)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cash{
		width: 144rpx;
		height: 70rpx;
		line-height: 70rpx;
	}
</style>
