<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>停车管理费</text>
		</view>
		<view class="flex-column br-12" style="margin-top: -50rpx;background:white;">
			<view class="flex-column">
				<view class="flex-column br-12 fs-28" style="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}}</text>
					</view>
					<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
						<text>住址信息</text>
						<text>{{userinfo.room}}</text>
					</view>
					<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;" @click="open">
						<text>车位号</text>
						<view class="flex v-center">
							<text>{{carNumber==''?"请选择":carNumber}}</text>
							<image class="w-25 h-30 ml-10" src="/static/icon_r.png"></image>
						</view>
					</view>
				</view>
				<view class="flex">
					<view @click="onTabClick(index)" class="h-50 flex-column flex-between-center fs-28 pad-30"
						style="flex: 1;" :style="{ color: index==indexTab?'#333333':'#999999'}"
						v-for="(item, index) in 3" :key="index">
						<text>{{index==0?"费用预存":index==1?"待缴查看":index==2?"缴费记录":""}}</text>
						<view v-if="index==indexTab" style="background: #27CC81;height: 1rpx;width: 77rpx;">
						</view>
						<view v-else style="background: #FFFFFF;height: 1rpx;width: 77rpx;">
						</view>
					</view>
				</view>
				<text v-if="indexTab==1" class="fs-30 fw-700 ">未缴金额\n￥{{money}}</text>
			</view>
		</view>
		<view class="overflow-y" style="background: white;">
			<scroll-view scroll-y style="height:100%;">
				<view v-if="indexTab==1&&djList.length!=0" v-for="(item, index) in djList" :key="index"
					@click="onClick(index)">
					<view class="flex-column fs-24 mar-20 pb-20" style="border-bottom: 1rpx solid #E9E9E9;">
						<view class="flex v-center fs-28">
							<text>{{item.month}}</text>
							<text style="color: #EE0101;">￥{{item.money}}</text>
							<image style="width: 20rpx;height: 20rpx;" src="/pagesMain/static/icon_zksq_1.png">
							</image>
						</view>
						<view v-if="indexNumber==index" class="flex-column mt-20 fs-24"
							style="color: #999999;text-align: left;">
							<text>缴费项目：车位管理费</text>
							<text>单价/月：￥{{item.price}}</text>
							<text>金额：{{item.money}}</text>
						</view>
					</view>
				</view>
				<view v-if="indexTab==1&&djList.length==0" style="padding-top: 100rpx;">
					<u-empty mode="data"></u-empty>
				</view>
				<view v-if="indexTab==2&&jfjlList.length==0" v-for="(item, index) in jfjlList" :key="index"
					@click="onClick(index)">
					<view class="flex-column fs-24 mb-20" style="text-align: left;">
						<text class="fs-28 h-80 lh-80 plr-25"
							style="background:#F2F2F2;">{{item.updateTime.slice(0, 7)}}</text>
						<view class="flex-row-between plr-25 mtb-20">
							<text style="color: #999999;">缴费渠道：线上缴费</text>
							<text>{{item.payAmount}}</text>
						</view>
						<text class="plr-25" style="color: #999999;">{{item.updateTime.slice(5)}}</text>
					</view>
				</view>
				<view v-if="indexTab==2&&jfjlList.length==0" style="padding-top: 100rpx;">
					<u-empty mode="data"></u-empty>
				</view>
			</scroll-view>
			<u-picker :show="show" :columns="listCar" closeOnClickOverlay="true" @cancel="close" @close="close"
				@confirm="confirm"></u-picker>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexTab: 1,
				indexNumber: 0,
				type: 0,
				show: false,
				carNumber: '',
				userinfo: '',
				jfjlList: [],
				djList: [],
				carportId: '',
				money: 0,
				listCar: [
					[]
				],
				list: [],

			};
		},
		onLoad(options) {
			this.type = options.type
			this.userinfo = uni.getStorageSync("userInfo")
			this.getListCar()
			this.getJfjlList()
		},
		methods: {
			onTabClick(index) {
				if (index == 0) {
					this.$wskj.to("/pagesMain/pages/jnzd_tcf")
					return
				}
				this.indexTab = index
				if (index == 1) {
					this.getDjList()
					return
				}
				if (index == 2) {
					this.getJfjlList()
					return
				}
			},
			onClick(index) {
				this.indexNumber = index
			},
			open() {
				this.show = true
			},
			close() {
				this.show = false
			},
			confirm(e) {
				this.show = false
				this.carNumber = e.value[0]
				this.carportId = this.list[e.indexs[0]].carportId
				this.getDjList()
			},
			getListCar() {
				const params = {
					url: '/api/carport/listByType?type=1',
					method: 'GET',
				}
				this.$request(params).then(res => {
					if (this.$wskj.isNull(res.data)) {
						return
					}
					this.list = res.data
					res.data.forEach(item => {
						this.listCar[0].push(item.carportNumber)
					})
					//默认第一个车位
					this.carNumber = res.data[0].carportNumber
					this.carportId = res.data[0].carportId
				})
			},
			//类型（1电费 2水费 3物业费 4车位管理费 5车位出租费 6储藏室出租 7其他费用）
			getDjList() {
				const params = {
					url: '/api/liveBill/listAll?type=4&carportId=' + this.carportId,
					method: 'GET',
				}
				this.$request(params).then(res => {
					let money = 0
					this.djList = res.data
					res.data.forEach(item => {
						money = money + parseFloat(item.money)
					})
					this.money = money.toFixed(2)
				})
			},
			getJfjlList() {
				const params = {
					url: '/api/payRecord/listAll?type=4',
					method: 'GET',
				}
				this.$request(params).then(res => {
					this.jfjlList = res.data
				})
			},
		}
	};
</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>