<template>
	<view>
		<view class='bill-details'>
			<view class='nav acea-row'>
				<view class='item' :class='type=="all" ? "on":""' @click='changeType("all")'>全部</view>
				<view class='item' :class='type=="recharge" ? "on":""' @click='changeType("recharge")'>充值</view>
				<view class='item' :class='type=="consumption" ? "on":""' @click='changeType("consumption")'>消费</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' v-if="item.code=='recharge'">+{{item.v}}</view>
								<view class='num font-color' v-else>-{{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 {
		recordList
	} from '@/api/api.js';
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				loadTitle: '加载更多',
				loading: false,
				loadend: false,
				page: 1,
				limit: 10,
				type: 'all',
				recordList: []
			};
		},
		computed: mapGetters(['isLogin']),
		onLoad: function(options) {
			this.type = options.type || 'all';
			if (this.isLogin) {
				this.getRecordList();
			} else {
				toLogin();
			}
		},
		onReachBottom: function() {
			this.getRecordList();
		},
		methods: {
			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 = '加载更多';
				});
			},
			changeType: function(type) {
				this.type = type;
				this.loadend = false;
				this.page = 1;
				this.$set(this, 'recordList', []);
				this.getRecordList();
			}
		}
	}
</script>

<style scoped lang='scss'>
	.bill-details .nav {
		background-color: #fff;
		height: 90rpx;
		width: 100%;
		line-height: 90rpx;
		margin-bottom: 2rpx;
	}

	.bill-details .nav .item {
		flex: 1;
		text-align: center;
		font-size: 30rpx;
		color: #282828;
	}

	.bill-details .nav .item.on {
		color: #e93323;
		border-bottom: 3rpx solid #e93323;
	}
	.font-color {
		color: #e93323!important;	
	}
</style>
