<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_dw.png" style="width: 40rpx;height: 40rpx;margin-right: 10rpx;"
						mode=""></image>
					<text>{{address}}</text>
					<image src="https://zhongqian.xnszz.com/1-images/home/20250213003.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>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				address: '请选择',
				show: false,
				selectIndex: 0,
				listXq: [],
				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.listAll()
		},
		methods: {
			open() {
				this.show = true
			},
			close() {
				this.show = false
				// console.log('close');
			},
			onSelect(index) {
				this.selectIndex = index
			},
			onSubmit() {
				this.show = false
				this.address = this.listXq[this.selectIndex].communityName
			},
			listAll() {
				const params = {
					url: '/api/community/listAll',
					loadingTip: '',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					console.log(res.data)
					this.listXq = 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;
	}
</style>