<template>
	<view class="page">
		<u-navbar title="WiFi选择" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='50' id="navbar">
		</u-navbar>
        <view class="list">
        	<view class="name">
        		WiFi列表
        	</view>
			<view class="list_wifi">
			   <!-- <view class="item_wifi" v-for="(item, index) in wifilist" @click="btnxz(item.wifiId)" :class="{ 'selected': selectedIds.includes(item.wifiId) }" :key="item.wifiId">
			        {{ item.wifi }}
			    </view> -->
				<view class="item_wifi" v-for="(item, index) in wifilist" @click="btnxz(item.wifiId)" :id="selectedIds == item.wifiId ? 'active' : ''" :key="item.wifiId">
				     {{ item.wifi }}
				 </view>
			</view>
        </view>
        <view class="anniu">
        	<view class="" @click="btnqr">
        		确认选择
        	</view>
        </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				wifilist:[],
				selectedIds: '',
				objId:''
			}
		},
		onLoad(option) {
			this.objId = option.objId
            this.getwifilist()
		},
		methods: {
			// 获取所有wifi列表
			getwifilist(){
				this.$u.get(`/app/wifi/list`).then(res => {
					if (res.code == 200) {
						this.wifilist = res.rows
					}
				})
			},
			// 点击选择wifi
            btnxz(id){
				this.selectedIds = id
				// const index = this.selectedIds.indexOf(id)
				// if (index > -1) {
				//   this.selectedIds.splice(index, 1)
				// } else {
				//   this.selectedIds.push(id)
				// }
				// console.log(this.selectedIds)
			},
		    // 确认选择wifi 
			btnqr(){
				let data = {
					roomId:Number(this.objId),
					wifiId:this.selectedIds
				}
				this.$u.put(`/app/room/setWifi`,data).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '配置成功',
							icon: 'success',
							duration:2000
						})
						setTimeout(() =>{
							uni.navigateBack()
						},1000)
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration:2000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	/deep/ .u-iconfont,
	/deep/ .u-title{
		padding-bottom: 20rpx;
	}
	#active {
	  background-color: #48893B !important;
	  color: #fff !important;
	}
	.anniu{
		width: 750rpx;
		height: 152rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.3);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		padding-top: 20rpx;
		box-sizing: border-box;
		position: fixed;
		left: 0;
		bottom: 0;
		view{
			width: 680rpx;
			height: 104rpx;
			background: #48893B;
			text-align: center;
			line-height: 104rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #FFFFFF;
			margin: auto;
			border-radius: 20rpx;
		}
	}
	.list{
		width: 680rpx;
		max-height: 76vh;
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: auto;
		margin-top: 22rpx;
		padding: 36rpx 34rpx;
		box-sizing: border-box;
		.list_wifi{
			width: 100%;
			height: 70vh;
			overflow: scroll;
			padding-bottom: 50rpx;
			box-sizing: border-box;
			padding: 0 16rpx;
			box-sizing: border-box;
			.item_wifi{
				width: 100%;
				height: 92rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0,0,0,0.15);
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				display: flex;
				align-items: center;
				font-weight: 600;
				font-size: 32rpx;
				color: #3D3D3D;
				padding-left: 34rpx;
				box-sizing: border-box;
				margin-top: 24rpx;
			}
		}
		.name{
			font-weight: 600;
			font-size: 36rpx;
			color: #3D3D3D;
		}
	}
	page {
		background: #F6F6F6;
	}


</style>