<template>
	<view class="center">
		<view style="background: linear-gradient( 180deg, #1FCA7C 0%, #F2F2F2 100%);">
			<u-navbar bgColor="transparent" placeholder="true" @leftClick="onXz">
				<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 class="h-300 flex flex-row-between v-center  ml-60 mr-35">
				<view class="flex-column" style="color: #FFFFFF;">
					<text class="fs-52" style="text-align: left;">便民服务</text>
					<text class="fs-30">洗衣清洁 | 超市送水~</text>
				</view>
				<image class="w-280 h-216" src="/static/icon_bmfw.png"></image>
			</view>
		</view>
		<view class="overflow-y mlr-25" style="background: white;border-radius: 20rpx;margin-top: -20rpx;">
			<scroll-view scroll-y style="height: 100%;">
				<view class="mlr-25" style="align-items: left;">
					<view class="flex">
						<text class="fs-32 fw-700 mt-30 mb-10">便民服务</text>
					</view>

					<view class="flex-column">
						<view class="banner">
							<u-swiper :list="bannerList1" radius="6" indicator indicatorMode="line" height="120"
								keyName="image"></u-swiper>
							<view class="banner_text">
								<text class="t1">洗衣服务</text>
								<text class="t2">{{bannerList1[0].title}}</text>
								<text class="t3">预约热线:{{bannerList1[0].bookPhone}}</text>
							</view>
						</view>
						<view class="banner">
							<u-swiper :list="bannerList2" radius="6" indicator indicatorMode="line" height="120"
								keyName="image"></u-swiper>
							<view class="banner_text">
								<text class="t1">清洁服务</text>
								<text class="t2">{{bannerList2[0].title}}</text>
								<text class="t3">预约热线:4{{bannerList2[0].bookPhone}}</text>
							</view>
						</view>
						<view class="banner">
							<u-swiper :list="bannerList3" radius="6" indicator indicatorMode="line" height="120"
								keyName="image"></u-swiper>
							<view class="banner_text">
								<text class="t1">超市服务</text>
								<text class="t2">{{bannerList3[0].title}}</text>
								<text class="t3">预约热线:{{bannerList3[0].bookPhone}}</text>
							</view>
						</view>
						<view class="banner">
							<u-swiper :list="bannerList4" radius="6" indicator indicatorMode="line" height="120"
								keyName="image"></u-swiper>
							<view class="banner_text">
								<text class="t1">送水服务</text>
								<text class="t2">{{bannerList4[0].title}}</text>
								<text class="t3">预约热线:{{bannerList4[0].bookPhone}}</text>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<u-popup :show="show" mode="center" @close="close" @open="open" round="20">
				<view class="flex-column mlr-50 ptb-30 vh-center" 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 @click="onSubmit()" class="w-250 h-60 lh-60 br-12 mt-20"
						style="background:#1FCA7C;color: #fff;">
						完成
					</view>
				</view>
			</u-popup>
		</view>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				address: '请选择',
				userInfo: '',
				show: false,
				selectIndex: -1,
				listXq: [],
				communityId: '', //小区ID
				bannerList1: [],
				bannerList2: [],
				bannerList3: [],
				bannerList4: [],

			};
		},
		onLoad(options) {
			this.getBannerList();
			this.getUserInfo();
			this.getXqList();
			this.getHouseList();
		},
		methods: {
			//轮播图列表
			getBannerList() {
				const than = this;
				const params = {
					url: '/api/converienceService/list',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					than.bannerList = [];
					res.rows.forEach(function(item, index) {

						if (item.serviceType == 1) {
							let images = item.serviceBanner.split(',');
							for (var i = 0; i < images.length; i++) {
								let data = {
									image: images[i],
									title: item.description,
									bookPhone: item.bookPhone,
								}
								than.bannerList1.push(data)
							}
						} else if (item.serviceType == 2) {
							let images = item.serviceBanner.split(',');
							for (var i = 0; i < images.length; i++) {
								let data = {
									image: images[i],
									title: item.description,
									bookPhone: item.bookPhone,
								}
								than.bannerList2.push(data)
							}
						} else if (item.serviceType == 3) {
							let images = item.serviceBanner.split(',');
							for (var i = 0; i < images.length; i++) {
								let data = {
									image: images[i],
									title: item.description,
									bookPhone: item.bookPhone,
								}
								than.bannerList3.push(data)
							}
						} else if (item.serviceType == 4) {
							let images = item.serviceBanner.split(',');
							for (var i = 0; i < images.length; i++) {
								let data = {
									image: images[i],
									title: item.description,
									bookPhone: item.bookPhone,
								}
								than.bannerList4.push(data)
							}
						}
					});
				})
			},
			onXz() {
				console.log(this.userInfo.userPermission)
				//非业主 弹出选择小区框
				if (parseInt(this.userInfo.userPermission) > 1) {
					this.open()
					return
				}
				//业主和家人 选择房屋信息
				if (parseInt(this.userInfo.userPermission) < 2) {
					this.$wskj.to("/pagesMine/pages/fwxx?type=1")
					return
				}
			},
			open() {
				this.show = true
			},
			close() {
				this.show = false
			},
			onSelect(index) {
				this.selectIndex = index
			},
			onSubmit() {
				if (this.selectIndex == -1) {
					this.$wskj.toast('请选择')
					return
				}
				this.show = false
				this.address = this.listXq[this.selectIndex].communityName
				uni.setStorageSync('addressItem', this.listXq[this.selectIndex])
			},
			onClick(inder) {
				this.$wskj.toast('敬请期待')
			},
			getUserInfo() {
				const params = {
					url: '/api/login/userInfo',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					uni.setStorageSync('userInfo', res.data)
					this.userInfo = res.data
					//用户类型（0=业主，1= 家庭成员，2=访客，3=保洁，4=保安）
					if (parseInt(this.userInfo.userPermission) < 2) {
						const fwInfo = uni.getStorageSync("fwInfo")
						this.address = fwInfo.communityName
					} else {
						//获取小区信息
						const addressItem = uni.getStorageSync("addressItem")
						this.address = addressItem.communityName
					}

				})
			},
			//获取小区数据
			getXqList() {
				const params = {
					url: '/api/community/listAll',
					method: 'GET',
					data: {}
				}
				this.$request(params).then(res => {
					console.log(res.data)
					this.listXq = res.data
				})
			},
			getHouseList() {
				uni.showLoading({
					title: ''
				})
				const than = this;
				const params = {
					url: '/api/community/myRoomListAll',
					method: 'GET',
				}
				than.$request(params).then(res => {
					if (than.$wskj.isNull(res.data)) {
						uni.hideLoading()
						return
					}
					than.houseList = res.data
					than.houseList.forEach(function(item, index) {
						if (item.room == than.userInfo.room) {
							than.selecteIndex = index
						}
					});
					//默认绑定房屋信息
					than.setHouse()
				})
			},
			setHouse() {
				const params = {
					url: '/api/community/cut/' + this.houseList[this.selecteIndex].communityId + "/" + this.houseList[
						this.selecteIndex].proprietorId,
				}
				this.$request(params).then(res => {
					uni.hideLoading()
					uni.setStorageSync('fwInfo', res.data)
					this.address = res.data.communityName
				})
			},

		}
	};
</script>

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

	.item {
		width: 100%;
		height: 200rpx;
		margin-top: 20rpx;
	}

	.banner {
		position: relative;
		margin-top: 20rpx;
	}

	.banner_text {
		position: absolute;
		top: 20rpx;
		left: 20rpx;
		right: 200rpx;
		bottom: 0;
		display: flex;
		flex-direction: column;
		color: white;
		text-align: left;
		font-size: 26rpx;
	}

	.t1 {
		font-size: 30rpx;
		font-weight: 700;
	}

	.t2 {
		margin: 10rpx 0;
	}

	.t3 {}
</style>