<template>
	<view class="center">
		<view>
			<u-navbar bgColor="#1FCA7C" placeholder="true" @leftClick="open">
				<view style="display: flex;align-items: center;font-size: 32rpx;color: #fff;" slot="left">
					<image src="/static/icon_home_dw1.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"
						mode=""></image>
					<text>{{address}}</text>
					<image src="/static/icon_xsj.png" style="width: 30rpx;height: 8.5rpx;margin-left: 8rpx;"
						mode="widthFix"></image>
				</view>
			</u-navbar>
		</view>
		<view style="background: linear-gradient( 180deg, #1FCA7C 0%, #F2F2F2 100%);height: 800rpx;"></view>
		<view class="mlr-24" style="margin-top: -800rpx;">
			<u-swiper :list="list1" radius="6"></u-swiper>
		</view>
		<view class="mtb-20 mlr-24 br-12" style="background-color: white;">
			<view class="mar-20 fs-32 fw-600" style="text-align: left;">常用服务</view>
			<view>
				<view class="grid-container">
					<view @click="onClick(index)" class="grid-item" v-for="(item, index) in listService" :key="index">
						<image class="w-86 h-86" :src="item.img"></image>
						<text class="fs-32 fw-600 mtb-20">{{item.title}}</text>
						<text class="fs-24" style="color: #999999;">{{item.describe}}</text>
					</view>
				</view>
			</view>
		</view>

		<u-popup :show="show" mode="center" @close="close" @open="open" round="20">
			<view class="flex-column mlr-50" style="width:600rpx;">
				<text class="fs-32 fw-600 mtb-20">选择小区</text>
				<scroll-view scroll-y class="h-400">
					<view v-for="(item, index) in listXq" :key="index" @click="onSelect(index)">
						<view class="fs-24 pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text
								:style="selectIndex==index?'color: #1FCA7C;':'color: #000000;'">{{item.communityName}}</text>
						</view>
					</view>
				</scroll-view>
				<view class="mt-40" @click="onSubmit()">
					<text class="plr-80 ptb-12 br-12" style="background:#1FCA7C;color: #fff;">下一步</text>
				</view>
			</view>
		</u-popup>
		<u-popup :show="showHh" mode="center" @close="closeHh" @open="openHh" round="20">
			<view class="flex-column mlr-50" style="width:600rpx;">
				<text class="fs-32 fw-600 mtb-20">楼栋号/单元号/户号</text>
				<scroll-view scroll-y class="h-400">
					<view v-for="(item, index) in listHh" :key="index" @click="onSelectHh(index)">
						<view class="fs-24 pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text :style="selectHhIndex==index?'color: #1FCA7C;':'color: #000000;'">{{item.room}}</text>
						</view>
					</view>
				</scroll-view>
				<view class="mt-40" @click="onSubmitHh()">
					<text class="plr-80 ptb-12 br-12" style="background:#1FCA7C;color: #fff;">完成</text>
				</view>
			</view>
		</u-popup>
		<!-- <view class="v-top-popup">
			<u-popup :show="show" @close="close" @open="open" mode="top" :style="{ top: 100 + 'px' }">
				<view class="flex-column">
					<text class="fs-24 mtb-20 text-left ml-30">当前小区：{{address}}</text>
					<scroll-view scroll-y>
						<view v-for="(item, index) in listXq" :key="index" @click="onSelect(index)">
							<view class="fs-24 pad-30 text-left" style="border-bottom: 1rpx solid #E9E9E9;">
								<text>{{item.communityName}}</text>
							</view>
						</view>
					</scroll-view>
				</view>
			</u-popup>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//选择小区用到的字段
				address: '请选择',
				show: false,
				selectIndex: -1,
				listXq: [],
				communityId: '', //小区ID
				//选择小区户号用到的字段
				showHh: false,
				selectHhIndex: -1,
				listHh: [],
				proprietorId: '', //户号id
				list1: [
					"https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2023%2F0826%2F07b46817j00rzyq1h000kd000hs00alp.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
					"https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2023%2F0826%2F07b46817j00rzyq1h000kd000hs00alp.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
					"https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2023%2F0826%2F07b46817j00rzyq1h000kd000hs00alp.jpg&thumbnail=660x2147483647&quality=80&type=jpg",
				],
				listService: [{
						img: "/static/icon_home_1.png",
						title: "访客",
						describe: "请点击输入访客信息"
					},
					{
						img: "/static/icon_home_2.png",
						title: "报修报事",
						describe: "保修报事一键即发"
					},
					{
						img: "/static/icon_home_3.png",
						title: "生活缴费",
						describe: "水费电费在线缴纳"
					},
					{
						img: "/static/icon_home_4.png",
						title: "常用电话",
						describe: "随时查找常用电话"
					},
					{
						img: "/static/icon_home_5.png",
						title: "停车缴费",
						describe: "输入车牌在线缴费"
					},
					{
						img: "/static/icon_home_6.png",
						title: "投诉表扬",
						describe: "投诉表扬线上发布"
					}

				],
			};
		},
		onShow() {
			this.userInfo()
			this.getXqList()
			//获取小区信息
			const addressItem = uni.getStorageSync("addressItem")
			this.address = addressItem.communityName
		},
		methods: {
			open() {
				this.show = true
			},
			close() {
				this.show = false
			},
			onSelect(index) {
				this.selectIndex = index
			},
			onSubmit() {
				this.show = false
				this.address = this.listXq[this.selectIndex].communityName
				this.communityId = this.listXq[this.selectIndex].communityId
				uni.setStorageSync('addressItem', this.listXq[this.selectIndex])
				this.getHhList()
			},
			//获取小区数据
			getXqList() {
				const params = {
					url: '/api/community/listAll',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					console.log(res.data)
					this.listXq = res.data
				})
			},

			openHh() {
				this.showHh = true
			},
			closeHh() {
				this.showHh = false
			},
			onSelectHh(index) {
				this.selectHhIndex = index

			},
			onSubmitHh() {
				this.showHh = false
				this.proprietorId = this.listHh[this.selectHhIndex].proprietorId
				this.upHh()
			},
			//获取户号数据
			getHhList() {
				const params = {
					url: '/api/community/room/listAllByCommunityId/' + this.communityId,
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					console.log(res.data)
					this.listHh = res.data
					//打开户号选择的弹框
					this.openHh()
				})
			},
			upHh() {
				const params = {
					url: '/api/community/cut/' + this.communityId + "/" + this.proprietorId,
					data: {}
				}
				this.$request(params).then(res => {
					this.$wskj.toast("设置成功")
				})
			},
			userInfo() {
				const params = {
					url: '/api/login/userInfo',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					uni.setStorageSync('userInfo', res.data)
				})
			},


			onClick(index) {
				if (index == 0) {
					this.$wskj.to("/pagesMain/pages/fkdj")
					return
				}
				if (index == 1) {
					this.$wskj.to("/pagesMain/pages/bxbs")
					return
				}
				if (index == 2) {
					this.$wskj.to("/pagesMain/pages/shjf")
					return
				}
				if (index == 3) {
					this.$wskj.to("/pagesMain/pages/cydh")
					return
				}
				if (index == 4) {
					this.$wskj.toast("敬请期待")
					return
				}
				if (index == 5) {
					this.$wskj.to("/pagesMain/pages/tsby")
					return
				}
			}
		}
	};
</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: 49%;
		height: 300rpx; // 宫格高度
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		border-bottom: 1rpx solid #f5f5f5;
		border-right: 1rpx solid #f5f5f5;
	}

	.v-top-popup /deep/ .u-popup__content {
		border-radius: 0 0 24rpx 24rpx;
		margin-top: 20%;
	}
</style>