<template>
<view :class="$isEmpty(room_list)?'empty-wrap':''">
<view class="bg-gray" style="padding: 16rpx 30rpx;">
	<text >当前选择单元：</text>
</view>
<view class="bg-white" style="padding:30rpx 30rpx 20rpx 30rpx;border-bottom: 1rpx solid #efefef;display: flex;justify-content: space-between;">
	<view class="text-blue">
		<text class="">{{unit_name}}</text>
	</view>
	<view class="cu-btn line-blue sm round" @tap="change">
		<text class="cuIcon-refresh padding-right-10"></text>
		<text>切换单元</text>
	</view>
</view>
	<view class="bg-gray" style="padding: 12rpx 30rpx;">
		<text >选择房间：</text>
	</view>
	<u-cell-group v-if="!$isEmpty(room_list)">
		<u-cell-item  @click="jump(item)"  v-for="(item, index) in room_list" :key="index"  :title="item.name" :arrow="false"></u-cell-item>
	</u-cell-group>
	
	<u-empty marginTop="200" icon-size="160"  v-if="$isEmpty(room_list)" text="暂无房间信息" src="/static/common/empty.png"></u-empty>
	
	<u-back-top :scroll-top="scrollTop"></u-back-top>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
	  city_county_name:"",
	  //房间号
      room_list: null,
	  //小区名字
      residential_name: null,
	  //楼栋名字
	  building_name:null,
	  //楼栋id
	  building_id:null,
	  //单元名字
      unit_name: null ,
	  
	  loading:true,
	  scrollTop:0

    };
  },
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  this.city_county_name=uni.getStorageSync("cityCountyName")
    //小区名字
    this.residential_name = options.residential_name; 
	//楼栋名字
	this.building_name=options.building_name
	//楼栋id
	this.building_id=options.building_id
	//单元名字
    this.unit_name = options.unit_name;
    //单元id
    var unit_id = options.unit_id;
    this.getRoom(unit_id);
  },
  methods: {
	  change(){
		uni.navigateBack({
			delta:1
		})  
	  },
	jump(item){
		let params={
			residential_name:this.residential_name,
			building_name:this.building_name,
			building_id:this.building_id,
			unit_name:this.unit_name,
			room_name:item.name,
			room_id:item.id
		}
		uni.redirectTo({
			url:'../../auth/auth'+this.$u.queryParams(params)
		})
	},
    //根据楼栋信息查询房间
    getRoom: function (unit_id) {
		uni.showLoading({
			title:'加载中..'
		})
      let that = this;
      let params = {};
      params['unit_id'] = unit_id;
      // let operation = 'estate/getByUnitId';
      this.$http.getRoomsByUnitId(params).then(res=>{
		  //获取成功
		  if (res.data.result_code == 1) {
		    that.setData({
		      room_list: res.data.list
		    });
		  } else {
		    app.globalData.oneFailHint(res.data.result_msg);
		  }
		  uni.hideLoading()
        
      });
    }
  }
};
</script>
<style>
/* pages/choosePlot/chooseUnit/chooseUnit.wxss */
page{
  overflow-y: scroll
}
.nav_section {
  width: 100%;
  background:#fff;
}

.nav_section_items {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 30rpx;
  border-bottom: 2rpx solid #ddd;
  position: relative;
}

.nav_section_items:active {
  background: #ddd;
}



.nav_section_items .section_cont view {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.nav_section_items .section_cont .section_cont_sub {
  font-size: 30rpx;
  line-height: 50rpx;
  color: #000;
  margin-bottom: 10rpx;
}
.section_cont_tel .info{
  width: 500rpx;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: inline-block;
}
.empty-wrap{	background-color: #FFFFFF;	min-height: 100vh;}
</style>