<template>
	<view class="center plr-25">
		<view class="flex-column-center fs-30 mt-30 h-140 pb-30 br-12 plr-25"
			style="background: linear-gradient( 90deg, #5FE8A9 0%, #1FCA7C 100%);color: white;">
			<image class="w-42 h-42 mr-20" src="/pagesMain/static/icon_cz_img.png"></image>
			<text>{{type==1?"电费缴纳":"水费缴纳"}}</text>
		</view>
		<view class="flex-column br-12 fs-28" style="background: white;margin-top: -40rpx;color: #999999;">
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>户号信息</text>
				<text>{{$wskj.isNullStr(userinfo.name)}}</text>
			</view>
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>住址信息</text>
				<text>{{userinfo.communityName+userinfo.room}}</text>
			</view>
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>缴费单位</text>
				<text>河南利龙物业管理有限公司</text>
			</view>
		</view>
		<view class="flex-column br-12 fs-28 mt-20 pad-25" style="background: white;">
			<text class="fs-32 fw-700 mb-10" style="text-align: left;color: #000;">缴费金额</text>
			<view>
				<view class="grid-container">
					<view @click="onClickPrice(index)" class="grid-item"
						:style="index==indexTab? 'color:#ffffff;background: #1FCA7C;':'color:#000000;;background:#F2F2F2;'"
						v-for="(item, index) in 6" :key="index">
						<text class="fs-32 fw-600 mtb-20">{{(index+1)*20+'元'}}</text>
					</view>
				</view>
			</view>
			<view class="flex ptb-25" style="border-bottom: 1rpx solid #D9D9D9;">
				<text class="fs-32 fw-700 mr-30">￥</text>
				<input style="flex: 1;text-align: left;font-size: 30rpx;" placeholder="输入缴费金额" />
			</view>
			<view class="fullscreen-btn" style="margin: 0;margin-top: 60rpx;" @click="onSubmit()">
				立即缴费
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexTab: 0,
				type: 1,
				money: 20,
				userinfo: '',

			};
		},
		onLoad(options) {
			this.type = options.type
			this.userinfo = uni.getStorageSync("userInfo")

		},
		methods: {
			onClickPrice(index) {
				this.indexTab = index
				this.money = (index + 1) * 20
			},
			onSubmit() {
				this.onCjdd()
			},
			onCjdd() {
				const params = {
					url: '/api/liveBill/add',
					loadingTip: '',
					data: {
						money: this.money,
						type: this.type, //类型（1电费 2水费 3物业费 4车位管理费 5车位出租费 6储藏室出租 7其他费用）
					}
				}
				this.$request(params).then(res => {
					this.pay(res.data.billId)
				})
			},
			pay(orderId) {
				const params = {
					url: '/api/payRecord/pay',
					loadingTip: '',
					data: {
						orderId: orderId,
						amount: this.money,
						payBizCode: "PRESTORE",
					}
				}
				this.$request(params).then(res => {
					uni.requestPayment({
						provider: 'wxpay',
						appid: res.data.data.appId, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
						nonceStr: res.data.data.nonceStr, // 随机字符串
						package: res.data.data.package, // 固定值
						timeStamp: res.data.data.timeStamp, // 时间戳（单位：秒）
						paySign: res.data.data.paySign, // 签名，这里用的 MD5/RSA 签名
						signType: 'MD5',
						success: (res) => {

						},
						fail: (err) => {
							console.log(err);
						}
					});

				})
			}
		}
	};
</script>

<style>
	.center {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #F2F2F2;
	}

	.grid-container {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around; // 可以根据需求调整元素的水平排列方式，这里是均匀分布
		align-items: center; // 垂直方向居中对齐
	}

	.grid-item {
		width: 32%;
		height: 80rpx; // 宫格高度
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background: #F2F2F2;
		border-radius: 12rpx;
		margin-top: 10rpx;
	}
</style>