<template>
	<view class="container">
		<view class="page">
			<view class="property">
				<view class="details">
					<view class="title">
						<view class="name">
							<view class="cost">{{payDetail.totalAmount}}</view>元
						</view>
						<view class="tag" :class="{'pay': payDetail.paymentStatus === 'unPaid'}">{{payDetail.paymentStatus === 'paid' ? '已付款' : '未付款'}}</view>
					</view>
					<view class="content">
						<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.meterReadingTime}}</view>
						</view>
						<view class="text">
							<view class="name">缴费类型</view>
							<view class="detail">{{payDetail.chargeTypeName}}</view>
						</view>
						<!-- <view class="text">
							<view class="name">支付方式</view>
							<view class="detail">微信支付</view>
						</view> -->
						<view class="text">
							<view class="name">缴费单位</view>
							<view class="detail">{{payDetail.propertyName}}</view>
						</view>
					</view>
				</view>

				<view v-if="payDetail.paymentStatus === 'unPaid'" class="form-submit" @click="onSubmit">支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		payOrderApi,
		communityPaymentDetailApi
	} from '@/config/api.js'
	export default {
		data() {
			return {
				payDetail: {}
			}
		},
		methods: {
			async getDetail(id) {
				let res = await communityPaymentDetailApi({id})
				this.payDetail = res.result
			},
			async onSubmit() {
				// uni.requestPayment({
				// 	provider: 'alipay',
				// 	orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
				// 	success: function (res) {
				// 		console.log('success:' + JSON.stringify(res));
				// 	},
				// 	fail: function (err) {
				// 		console.log('fail:' + JSON.stringify(err));
				// 	}
				// });
				payOrderApi({id: this.payDetail.id}).then(res=> {
					uni.navigateTo({
						url: `/pages/payStatus/index?id=${this.payDetail.id}&type=1&price=${this.payDetail.totalAmount}`
					});
				}).catch(err=> {
					uni.navigateTo({
						url: `/pages/payStatus/index?id=${this.payDetail.id}&type=0&price=${this.payDetail.totalAmount}`
					});
				})
			}
		},
		onLoad(option) {
			this.getDetail(option.id)
		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 30rpx 30rpx 90rpx;
	}

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

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

				}

				.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;
					justify-content: space-between;

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

					.detail {
						font-size: 28rpx;
						color: #373737;
					}
				}
			}
		}
		.form-submit {
			height: 80rpx;
			line-height: 80rpx;
			background-color: #6A59F2;
			border-radius: 80rpx;
			width: 100%;
			text-align: center;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
</style>