<template>
	<view>
		<u-navbar title="充值记录">
		</u-navbar>
		<view class="chargeScreen">
			<view class="chargeScreen-item">
				<p>
				 <picker mode="date" :value="startDate"  :end="endDate"   @change="bindDateChange0">
				            <view class="uni-input">{{startDate}}</view>
				     </picker>
				</p>
				<u-icon name="arrow-down-fill" color="#999" size="24"></u-icon>
			</view>
			<span>至</span>
			<view class="chargeScreen-item">
				<p>
				<picker mode="date" :value="endDate" :start="startDate"   @change="bindDateChange1">
				           <view class="uni-input">{{endDate}}</view>
				    </picker>
				
				</p>
				<u-icon name="arrow-down-fill" color="#999" size="24"></u-icon>
			</view>
		</view>
		<view class="chargeList">
			<view v-for="(item ,index) in list" :key="item.id"
			 @click="gotoUrl('pages/user/rechargeDeatils?id='+item.id)"
			 class="chargeList-item" 
			 >
				<view class="chargeList-text">
					<p>余额充值</p>
					<h4>{{item.payNameStr}}</h4>
				</view>
				<view class="chargeList-right">
					<span>{{item.amount}}元</span>
					<h4>{{item.createTime}}</h4>
				</view>
			</view> 
			
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/index.js'
	import {parseUnixTime,beforeTimeStamp} from  '@/utils/index.js'
	export default {
		data() {
			return {
				form: {

				},
				startDate:'',
				endDate:'',
				pageIndex: 1,
				recordsTotal: 0,
				list: [],
			}
		},
		onReachBottom() {
			if (this.list.length < this.recordsTotal) {
				this.myLoadmore();
			}
		},
		methods: {
			  bindDateChange0: function(e) {
			            this.startDate= e.target.value
			            
						
						this.getList(true)
			  },
			  bindDateChange1: function(e) {
			          this.endDate= e.target.value
			          
			  						this.getList(true)
			  },
			myLoadmore() {

				this.pageIndex += 1;
				this.getList()
			},
			getList(bl) {
				
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				if (bl) {
					this.list = [];
					this.pageIndex = 1;
				}
				var data = {
					startDate:this.startDate,
					endDate:this.endDate,
					pageIndex: this.pageIndex
				};
				API.accountRecordData(data).then((res) => {

					this.list = [
						...this.list,
						...res.data.data
					];
					this.recordsTotal = res.data.recordsTotal
					uni.hideLoading()

				}).catch(error => {
					uni.showToast({

						title: error
					})
				})
			},
			onReady() {
				this.startDate=parseUnixTime(beforeTimeStamp(5),"{y}-{m}-{d}")
				this.endDate=parseUnixTime(new Date(),"{y}-{m}-{d}")
				
				this.getList()
				
			}
		}
	}
</script>
<style>
	page {
		background-color: #f7f7f7;
	}
</style>
<style lang="scss" scoped>
	.chargeScreen {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 10px 0;
		background-color: #fff;

		span {
			color: #777;
		}
	}

	.chargeScreen-item {
		display: flex;
		align-items: center;
		flex: 1;
		justify-content: center;

		p {
			color: #777;
			margin-right: 5px;
		}
	}

	.chargeList {
		margin-top: 10px;
	}

	.chargeList-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px;
		background-color: #fff;
		border-bottom: 1px solid #f7f7f7;

		h4 {
			font-weight: normal;
			color: #999;
			margin-top: 3px;
			font-size: 12px;
		}

		span {
			font-size: 14px;
			color: #1677FF;
			font-weight: bold;
		}
	}

	.chargeList-right {
		text-align: right;
	}
</style>
