<template>
	<view class="page">
		<u-navbar title="选择房间" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='40' id="navbar">
		</u-navbar>
		
		<view class="list">
			<view class="list_item" v-for="(item,index) in roomlist" :key="index" :id="roomindex == index? 'active': ''" @click="btnroom(index,item.roomId)">
				<view class="name">
					{{item.storeName}}
				</view>
				<view class="zt" v-if="item.status ==1">
					空闲中
				</view>
				<view class="zt" style="color: #ffba00;" v-if="item.status ==2">
					未打扫
				</view>
				<view class="zt" style="color: #ff4949;" v-if="item.status ==3">
					离线
				</view>
				<view class="zt" style="color: #ff4949;" v-if="item.status ==4">
					使用中
				</view>
				<view class="zt" style="color: #ffba00;" v-if="item.status ==5">
					打扫中
				</view>
				<view style="color: #ccc;" class="zt" v-if="item.status == 8">
					维护中
				</view>
			</view>
		</view>
		<view class="" style="width: 100%;text-align: center;margin-top: 50rpx;font-size: 34rpx;color: #ccc;">
			没有更多房间啦...
		</view>
		
		
		<view class="anniu">
			<view class="xinjian" @click="btndt">
				新建大厅
			</view>
			<view class="xinjian" @click="btnmd">
				新建房间
			</view>
			<view class="queren" @click="btnrxz">
				确认选择
			</view>
		</view>
        
	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				storeId:'',
				roomlist:[],
				roomindex:-1,
				roomId:'',
				deviceId:''
			}
		},
		onLoad(option) {
           this.storeId = option.storeId
		   this.deviceId = option.deviceId
		},
		onShow() {
	        this.getroom()
		},
		methods: {
			// 点击确认投放
			btnrxz(){
				this.$u.post(`/app/device/placement/${this.roomId}/${this.deviceId}`).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '投放成功',
							icon: 'success',
							duration: 2000
						})
						setTimeout(()=>{
							uni.reLaunch({
								url:'/page_shanghu/shebei'
							})
						},1000)
					}else{
						uni.showToast({
							title: res.mag,
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			// 点击切换房间
			btnroom(index,roomId){
				this.roomId = roomId
				this.roomindex = index
			},
			// 请求门店所有房间
            getroom(){
				this.$u.get(`/app/room/getRoomListByStoreId?storeId=${this.storeId}`).then(res => {
					if (res.code == 200) {
						this.roomlist = res.data
					}
				})
			},
			// 点击跳转新建大厅
			btndt(){
				uni.navigateTo({
					url:'/page_shanghu/adddating'
				})
			},
			// 点击跳转新建房间
			btnmd(){
				uni.navigateTo({
					url:'/page_shanghu/addtoom'
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F6F6F6;
	}
	#active{
		border: 4rpx solid #48893B !important;
	}
	.list{
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
        padding: 0 36rpx;
		box-sizing: border-box;
		margin-top: 22rpx;
		.list_item{
			border-radius: 10rpx;
			width: 326rpx;
			height: 178rpx;
			background: #FFFFFF;
			border: 4rpx solid #fff;
			padding-top: 26rpx;
			padding-left: 42rpx;
			box-sizing: border-box;
			.name{
				font-weight: 600;
				font-size: 36rpx;
				color: #3D3D3D;
			}
			.zt{
				font-size: 28rpx;
				color: #48893B;
				margin-top: 8rpx;
			}
		}
	}
	.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;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		padding: 0 36rpx;
		box-sizing: border-box;
		padding-top: 24rpx;
		.queren{
			width: 214rpx;
			height: 104rpx;
			background: #48893B;
			text-align: center;
			line-height: 104rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #FFFFFF;
			border-radius: 20rpx;
		}
		.xinjian{
			width: 214rpx;
			height: 104rpx;
			border: 2rpx solid #48893B;
			border-radius: 20rpx;
			text-align: center;
			line-height: 104rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #48893B;
		}
	}
</style>