<template>
	<view class="container">
		<view class="page" v-if="payList.length">
			<view class="property">
				<view class="list">
					<view class="item" @click="toDetail(item.id)" v-for="item in payList" :key="item.id">
						<view class="title">
							<view class="name">{{item.chargeTypeName}}：<view class="cost">¥{{item.totalAmount}}</view>
							</view>
							<view class="tag">已付款</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'
	let chargeTypeCode = ''
	export default {
		components: {noData},
		data() {
			return {
				isFinish: false,
				pageNo: 1,
				payList: []
			}
		},
		methods: {
			async getList(flag) {
				let {result} = await communityPaymentApi({
					paymentStatus: 'paid',
					chargeTypeCode,
					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
				}
			},
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/myPaycostDetails/index?id=' + id
				});
			}
		},
		onLoad(option) {
			chargeTypeCode = option.code
			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 30rpx 90rpx;
		background-color: #F8F6F9;
	}

	.property {

		.list {
			.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: 28rpx;
						color: #9D9CA6;
						display: flex;

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

					}

					.tag {
						height: 36rpx;
						line-height: 36rpx;
						font-size: 22rpx;
						padding: 4rpx 20rpx;
						color: #B6B6BA;
						background-color: #F8F8F8;
						border: 1px solid #B6B6BA;
						border-radius: 36rpx;
					}
				}


				.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>