<template>
	<view class="container">
		<view class="page">
			<view class="paycost">
				<view class="details">
					<view class="title">
						<view class="name">
							<view class="cost">{{payDetail.totalAmount}}</view>元
						</view>
						<view class="text">{{payDetail.propertyName}}</view>
					</view>
					<view class="content">
						<view class="text">
							<view class="name">费用类型</view>
							<view class="detail">{{payDetail.chargeTypeName}}</view>
						</view>
						<view class="text">
							<view class="name">订单编号</view>
							<view class="detail">{{payDetail.id}}</view>
						</view>
						<view class="text">
							<view class="name">创建时间</view>
							<view class="detail">{{payDetail.createTime}}</view>
						</view>
						<view class="text">
							<view class="name">缴费周期</view>
							<view class="detail">{{payDetail.chargeCycle | transChargeCycle}}</view>
						</view>
						<view class="text">
							<view class="name">支付时间</view>
							<view class="detail">{{payDetail.paymentTime}}</view>
						</view>
						<template v-if="payDetail.designFormulas === 2">
							<view class="text">
								<view class="name">建筑面积</view>
								<view class="detail">{{payDetail.floorSpace}}</view>
							</view>
							<view class="text">
								<view class="name">单价</view>
								<view class="detail">{{payDetail.unitPrice}}</view>
							</view>
						</template>
						<template v-if="payDetail.designFormulas === 3">
							<view class="text">
								<view class="name">上期度数（度）</view>
								<view class="detail">{{payDetail.lastDegrees}}</view>
							</view>
							<view class="text">
								<view class="name">本期度数（度）</view>
								<view class="detail">{{payDetail.currentDegrees}}</view>
							</view>
							<view class="text">
								<view class="name">用量（度）</view>
								<view class="detail">{{payDetail.useAmount}}</view>
							</view>
						</template>
						<view class="text">
							<view class="name">支付方式</view>
							<view class="detail">微信支付</view>
						</view>
					</view>
				</view>
				<!-- <view class="form-bounced" @click="receipt()">开收据</view>
				<view class="form-bounced" @click="receipt()">申请退款</view> -->
			</view>
		</view>
		<uni-popup ref="popup" type="dialog">
			<uni-popup-dialog type="error" cancelText="关闭" confirmText="同意" title="开收据" content="确定要开收据吗？!"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		communityPaymentDetailApi
	} from '@/config/api.js'
	import {CHARGING_CYCLE} from '@/utils/dictionary'
	export default {
		data() {
			return {
				payDetail: {}
			}
		},
		filters: {
			transChargeCycle(value) {
				let current = CHARGING_CYCLE.find(item=>item.value === value)
				return current ? current.label : ''
			}
		},
		methods: {
			async getDetail(id) {
				let res = await communityPaymentDetailApi({id})
				this.payDetail = res.result
				if(res.result.designFormulas === 3) {
					this.payDetail['useAmount'] = (res.result.currentDegrees - Number(res.result.lastDegrees)).toFixed(2)
				}
			},
			receipt() {
				this.$refs.popup.open()
			},
			dialogConfirm() {
				this.$refs.popup.close()
			},
			dialogClose() {
				this.$refs.popup.close()
			}
		},
		onLoad(option) {
			this.getDetail(option.id)
		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx 30rpx 90rpx;
	}

	.paycost {
		.details {
			background-color: #ffffff;
			border-radius: 16rpx;
			padding: 60rpx 30rpx;
			margin-bottom: 30rpx;

			.title {
				margin-bottom: 60rpx;
				display: flex;
				flex-direction: column;
				text-align: center;
				align-items: center;

				.name {
					height: 60rpx;
					line-height: 60rpx;
					font-size: 28rpx;
					color: #6A59F2;
					display: flex;
					margin-bottom: 25rpx;

					.cost {
						font-size: 60rpx;
						color: #6A59F2;
						font-weight: bold;
						margin-right: 20rpx;
					}

				}

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


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

				.text {
					display: flex;
					height: 60rpx;
					line-height: 60rpx;
					justify-content: space-between;

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

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

	.form-bounced {
		height: 80rpx;
		line-height: 80rpx;
		background-color: #ffffff;
		border: 1px solid #6A59F2;
		border-radius: 80rpx;
		width: 100%;
		text-align: center;
		font-size: 28rpx;
		color: #6A59F2;
		margin-bottom: 30rpx;
	}
</style>