<template>
	<view>
		<ujp-navbar title="充值记录"></ujp-navbar>
		<view class="rechargeTime oldTextjp2" oldstyle="font-size: 18px;" @click="show = true">
			<u-picker mode="time" v-model="show" :params="params" @confirm="confirmTime" @cancel="cancelTime"></u-picker>
			<span>{{month}}月</span>
			<u-icon name="arrow-down-s-fill" custom-prefix="custom-icon" color="#B3B3B3" size="32"></u-icon>
		</view>
		<view class="carNone" v-if="accountList.length == 0">
			<img src="@/assets/static/img/暂无数据-缺省页.png" alt="">
			<p class="oldTextjp2" oldstyle="font-size: 18px;">暂无充值记录</p>
		</view>
		<view class="rechargeList" v-if="accountList.length > 0">
			<view class="rechargeList-item" v-for="(item,index) in accountList" :key="item.id" @click="gotoUrl('pages/user/finance/rechargeDet?type='+item.type+'&id=' + item.id)">
				<view class="rechargeList-row">
					<span class="oldTextjp" oldstyle="font-size: 18px;">{{item.remark}}</span>
					<h4 class="oldTextjp2" oldstyle="font-size: 20px;">{{item.amount?item.amount.toFixed(2):0}}元</h4>
				</view>
				<view class="rechargeList-row">
					<p class="oldTextjp2" oldstyle="font-size: 14px;"></p>
					<p class="oldTextjp2" oldstyle="font-size: 14px;">{{item.createTime}}</p>
				</view>
			</view>
		</view>
		<u-divider  v-if="accountList.length == recordsTotal && recordsTotal != 0" style="margin-top: 10px;background-color: #F2F4F4;">已经到底了</u-divider>
	</view>
</template>

<script>
	import * as API from '@/apis/index.js'
	
	export default {
		data() {
			return {
				userId: '',
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false,
					timestamp: true,
				},
				show: false,
				month: '',
				dateMonth: '',
				accountList: [],
				pageIndex: 1,
				recordsTotal: 0,
				elderStatus: false,
			}
		},
		onReady() {			
			if(this.carhelp.getPersonInfo()) {
				this.userId = this.carhelp.getPersonInfo().id;
				
				if(this.carhelp.get("getElderModeClass") == "长辈模式") {
					this.elderStatus = true;
				} else {
					this.elderStatus = false;
				}
			}
			
			var date = new Date();
			this.month = date.getMonth() + 1;
			
			var year = date.getFullYear();
			var monthN = this.month;
			if(monthN >= 1 && monthN <= 9) {
				monthN = "0" + monthN;
			}
			this.dateMonth = year + '-' + monthN + '-01';
					
			this.getAccountRecordData();
		},
		onReachBottom() {
			if (this.accountList.length < this.recordsTotal) {			
				this.myLoadmore();
			}
		},
		methods: {
			myLoadmore(bl) {
				this.pageIndex += 1;
				this.getAccountRecordData()
			},
			getAccountRecordData(bl) {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				if (bl) {
					this.accountList = [];
					this.pageIndex = 1;
				}
				API.rechargeAmountRecordList({
					pageIndex: this.pageIndex,
					queryDate: this.dateMonth,
				}).then((res) => {
					uni.hideLoading();
					
					this.accountList = [
						...this.accountList,
						...res.data.data
					];
					this.recordsTotal = res.data.recordsTotal;
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
			confirmTime(params) {
				this.dateMonth = params.year + '-' + params.month + '-01';
				if(params.month.slice(0,1) == '0') {
					this.month = params.month.slice(1);
				} else {
					this.month = params.month;
				}
				this.getAccountRecordData(true);
				this.show = false;
			},
			cancelTime() {
				this.show = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.carNone{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		img{
			width: 100%;
			height: 100%;
		}
		p{
			margin-top: -60px;
		}
	}
	.rechargeTime{
		background-color: #fff;
		height: 44px;
		display: flex;
		align-items: center;
		padding: 12px 16px;
		border-bottom: 1px solid #f7f7f7;
		span{
			margin-right: 4px;
		}
	}
	.rechargeList{
		background-color: #fff;
		padding-left: 16px;
		.rechargeList-item{
			padding: 12px 16px 12px 0;
			border-bottom: 1px solid #f7f7f7;
			&:last-child{
				border-bottom: none;
			}
		}
		.rechargeList-row{
			display: flex;
			align-items: center;
			justify-content: space-between;
			h4{
				font-size: 16px;
			}
			p{
				font-size: 12px;
				margin-top: 4px;
				color:#888;
			}
		}
	}
</style>
