<template>
  <div>
    <template v-if="filterData.roomInfos.length">
      <div
        class="room-details"
        v-for="item in filterData.roomInfos"
        @click="goRoomDetail(item)"
        :key="item.roomId">
        <div class="name">
          <div class="flex align-c">
            <h5>{{item.bedText}}</h5>
            <div class="tag flex">
              <p>{{item.type}}</p>
              <p class="lineHidden">门牌号#{{item.unitNum}}</p>
            </div>
          </div>
          <div class="price flex">
            <i>{{item.moneyUnit}}</i>
            <p>{{item.priceText}}</p>
            <span>/{{item.rentTimeUnit}}</span>
          </div>
        </div>
        <div class="attribute flex_sb">
          <div>
            <p class="flex">
              <i>租赁方式</i>
              <span>{{item.rentalModeText}}</span>
            </p>
            <p class="flex">
              <i>租期</i>
              <span>{{item.rentNum}}</span>
            </p>
            <p class="flex">
              <i>起租时间</i>
              <span>{{item.rentTime}}</span>
            </p>
          </div>
          <p v-if="item.status == 1">申请预定</p>
          <p class="disabled" v-else>已租满</p>
        </div>
      </div>
    </template>
    <div class="room-detail-none" v-if="!filterData.roomInfos">暂无数据</div>
  </div>
</template>

<script>
export default {
  name: "RoomInformation",
  props: {
    data: {
      type: Object,
      required: true,
      default: function() {
        return {};
      }
    },
    filterData: {
      type: Object,
      required: true,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      lang: this.$store.state.langStr
    };
  },
  created: function() {},
  mounted: function() {},
  methods: {
    // 跳转预定页面
    goRoomDetail(item) {
      if (this.$util.storage.fetch("userToken")) {
        if (Number(item.status) === 1) {
          let id = this.$route.params.id;
          let data = {
            img: this.data.imgs[0],
            houseName: this.data.name,
            rentTime: item.rentTime,
            rentNum: item.rentNum,
            moneyUnit: item.moneyUnit,
            priceText: item.priceText,
            rentTimeUnit: item.rentTimeUnit
          };
          this.$util.sessionStorage.save("buildingInfo", data);
          this.$router.push({
            path: `/${this.lang}/applyForm?houseId=${id}&roomId=${item.roomId}`
          });
        }
      } else {
        let { fullPath } = this.$route;
        this.$router.push({
          path: `/${this.lang}/login?next=${encodeURIComponent(fullPath)}`,
          replace: true
        });
      }
    }
  }
};
</script>

<style scoped lang="less">
</style>
