<template>
	<view class="container">
		<view class="page">
			<view class="paycost">
				<view>
					<uni-datetime-picker v-model="range" type="daterange" start-placeholder="缴费开始日期"  end-placeholder="缴费结束日期" @change="onDateChange" />
				</view>

				<view class="list" v-if="payList.length">
					<view class="item" @click="toDetail(item.id)" v-for="item in payList" :key="item.id">
						<view class="title">
							<view class="name">{{item.chargeTypeName}}</view>
							<view class="cost">¥{{item.totalAmount}}</view>
						</view>
						<view class="content">
							<view class="text">
								<view class="name">缴费人</view>
								<view class="detail">{{item.residentName}}</view>
							</view>
							<view class="text">
								<view class="name">缴费人号码</view>
								<view class="detail">{{item.residentPhone}}</view>
							</view>
							<view class="text">
								<view class="name">缴费时间</view>
								<view class="detail">{{item.paymentTime}}</view>
							</view>
							<view class="text">
								<view class="name">缴费地址</view>
								<view class="detail">{{item.buildingName}}{{item.unitName}}{{item.roomName}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<no-data :show="payList.length === 0" text="暂无缴费记录"></no-data>
	</view>
</template>

<script>
	import {
		communityPaymentApi
	} from '@/config/api.js'
	import noData from '@/components/no-data/no-data'
	export default {
		components: {noData},
		data() {
			return {
				isFinish: false,
				pageNo: 1,
				range: ['', ''],
				payList: []
			}
		},
		methods: {
			async getList(flag) {
				let {result} = await communityPaymentApi({
					paymentStatus: 'paid',
					payStartTime: this.range[0] || '',
					payEndTime: this.range[1] || '',
					pageNo: this.pageNo,
					pageSize: 10
				})
				if(this.pageNo === 1) {
					this.payList = [].concat(result.records)
				} else {
					this.payList = this.payList.concat(result.records)
				}
				if(flag) { uni.stopPullDownRefresh(); }
				if(this.payList.length >= result.total) {
					this.isFinish = true
				} else {
					this.pageNo += 1
				}
			},
			onDateChange(value) {
				this.pageNo = 1
				this.range = value
				this.getList()
			},
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/myPaycostDetails/index?id=' + id
				});
			}
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh() {
			this.pageNo = 1
			this.isFinish = false
			this.getList(true)
		},
		onReachBottom() {
			if(this.isFinish) return
			this.getList()
		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx;
		background-color: #F8F6F9;
	}

	.paycost {
		.list {
			margin-top: 30rpx;
			.item {
				background-color: #ffffff;
				border-radius: 16rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;

				.title {
					height: 40rpx;
					line-height: 40rpx;
					margin-bottom: 30rpx;
					display: flex;
					justify-content: space-between;

					.name {
						font-size: 32rpx;
						color: #373737;
						display: flex;
						font-weight: bold;
					}

					.cost {
						font-size: 36rpx;
						color: #6A59F2;
						font-weight: bold;
					}
				}


				.content {
					border-top: 1px solid #F0F0F2;
					padding-top: 20rpx;

					.text {
						display: flex;
						height: 60rpx;
						line-height: 60rpx;

						.name {
							width: 180rpx;
							font-size: 28rpx;
							color: #9D9CA6;
						}

						.detail {
							font-size: 28rpx;
							color: #373737;
						}
					}
				}

			}
		}
	}
</style>