<template>
	<view>
		<view class='commission-details'>
			<view class='promoterHeader'>
				<view class='headerCon acea-row row-between-wrapper'>
					<view>
						<view class='name'>可提现余额</view>
						<view class='money'>¥<text class='num'>{{money}}</text></view>
					</view>
					<view class='iconfont icon-jinbi1'></view>
				</view>
			</view>
			<view class='sign-record'>
				<view class='list' v-for="(item,index) in recordList" :key="index">
					<view class='item'>
						<view class='listn'>
							<view class='itemn acea-row row-between-wrapper'>
								<view>
									<view class='name line1'>{{item.title}}</view>
									<view>{{item.time}}</view>
								</view>
								<view class='num font-color'>+{{item.v}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class='loadingicon acea-row row-center-wrapper' v-if="recordList.length>0">
					<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
				</view>
				<view v-if="recordList.length == 0">
					<emptyPage title='暂无佣金记录~'></emptyPage>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		account,
		recordList
	} from '@/api/api.js';
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				money: 0,
				loadTitle: '加载更多',
				loading: false,
				loadend: false,
				page: 1,
				limit: 10,
				type: 'income',
				recordList: []
			};
		},
		computed: mapGetters(['isLogin']),
		onLoad() {
			if (this.isLogin) {
				this.getAccount();
				this.getRecordList();
			} else {
				toLogin();
			}
		},
		methods: {
			getAccount: function() {
				account().then(res => {
					this.money = res.data.tx_money;
				});
			},
			getRecordList: function() {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = "";
				let data = {
					page: that.page,
					tabType: that.type
				}
				recordList(data).then(function(res) {
					let list = res.data.list,
					loadend = list.length < that.limit;
					that.recordList = that.$util.SplitArray(list, that.recordList);
					that.loadend = loadend;
					that.loading = false;
					that.loadTitle = loadend ? "哼~我也是有底线的~" : "加载更多";
					that.page = that.page + 1;
				}, function(res) {
					that.loading = false;
					that.loadTitle = '加载更多';
				});
			},
		},
		onReachBottom: function() {
			this.getRecordList();
		}
	}
</script>

<style scoped lang="scss">
	.commission-details .promoterHeader{
		background: #ff5c00;
	}
	
	.commission-details .promoterHeader .headerCon .money {
		font-size: 36rpx;
	}

	.commission-details .promoterHeader .headerCon .money .num {
		font-family: 'Guildford Pro';
	}
	.bg-color{
		background-color: #e93323!important;
	}
	.font-color,.font-color-red {
		color: #e93323!important;	
	}
</style>