<template>
	<view class="container">
		<view class="page">
			<view class="property">
				<view class="top">
					<view class="user">
						<view class="name">{{userName}} {{userPhone}}</view>
						<view class="add">{{platformName}}</view>
					</view>
					<view class="link">
						<view class="tit on" @click="toRecord(1)">历史缴费统计</view>
						<view class="tit" @click="toRecord(2)">缴费记录</view>
					</view>
				</view>
				<view class="list">
					<view class="item" v-for="item in payList" :key="item.id" @click="toDetail(item.id)">
						<view class="title">
							<view class="name">
								{{item.chargeTypeName}}：<view class="cost">¥{{item.totalAmount}}</view>
							</view>
							<view class="tag">{{item.paymentStatus === 'paid' ? '已缴费' : '去缴费'}}</view>
						</view>
						<view class="content">
							<view class="text">
								<view class="name">缴费周期</view>
								<view class="detail">{{item.chargeItem}}</view>
							</view>
							<view class="text">
								<view class="name">创建日期</view>
								<view class="detail">{{item.meterReadingTime}}</view>
							</view>
							<view class="text">
								<view class="name">缴费单位</view>
								<view class="detail">{{item.propertyName}}</view>
							</view>
						</view>
					</view>
				</view>
				<no-data :show="payList.length === 0" text="暂无缴费信息"></no-data>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		communityPaymentApi
	} from '@/config/api.js'
	import noData from '@/components/no-data/no-data'
	const freeType = [
		{code: 'SFLX00001', name: '物业费'},
		{code: 'SFLX00002', name: '水费'},
		{code: 'SFLX00003', name: '电费'},
		{code: 'SFLX00004', name: '燃气费'},
		{code: 'SFLX00005', name: '暖气费'}
	]
	let chargeTypeCode = ''
	export default {
		components: {noData},
		data() {
			return {
				isFinish: false,
				pageNo: 1,
				userName: '',
				userPhone: '',
				platformName: '',
				payList: []
			}
		},
		methods: {
			async getList(flag) {
				let {result} = await communityPaymentApi({
					paymentStatus: 'unPaid',
					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
				}
			},
			toRecord(type) {
				if(type == 1){
					let obj = freeType.find(item=>item.code === chargeTypeCode)
					if(obj) {
						uni.navigateTo({
							url: '/pages/payCostStatistical/index?code=' + chargeTypeCode + '&name=' + obj.name
						});
					} else {
						uni.navigateTo({
							url: '/pages/payCostStatistical/index?code=' + chargeTypeCode
						});
					}
				}else if(type == 2){
					uni.navigateTo({
						url: '/pages/payCostRecord/index?code=' + chargeTypeCode
					});
				}
			},
			toDetail(id) {
				uni.navigateTo({
					url: `/pages/payCostDetails/index?id=${id}`,
				});
			}
		},
		onLoad(option) {
			this.userName = uni.getStorageSync('user_name')
			this.userPhone = uni.getStorageSync('user_phone')
			this.platformName = uni.getStorageSync('platform_name')
			chargeTypeCode = option.code
			this.getList()
			let obj = freeType.find(item=>item.code === option.code)
			if(obj) {
				uni.setNavigationBarTitle({
					title: obj.name
				})
			}
		},
		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 {
		.top {
			border-radius: 16rpx;
			background-color: #E8E5FF;
			margin-bottom: 30rpx;

			.user {
				background-position: top center;
				background-repeat: no-repeat;
				background-size: cover;
				background-image: url('https://life.cloud.hjxbc.cn/sys/common/static/miniapp/bg_cost.png');
				border-radius: 16rpx;
				padding: 40rpx;

				.name {
					font-size: 32rpx;
					color: #ffffff;
					margin-bottom: 20rpx;
				}

				.add {
					font-size: 28rpx;
					color: #D5DCFF;
				}
			}

			.link {
				display: flex;
				padding: 24rpx 0;

				.tit {
					width: 49%;
					font-size: 28rpx;
					color: #6A59F2;
					text-align: center;
				}

				.on {
					border-right: 1px solid #D6D3EC;
				}
			}
		}

		.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: #FEFEFE;
						background-color: #6A59F2;
						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>