<template>
  <div>

    <el-row :gutter="40" class="panel-group">
      <el-col :xs="8" :sm="8" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="monitor" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              会议室总数
            </div>
            <count-to :start-val="total" :end-val="total" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="8" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="monitor" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              正在使用
            </div>
            <count-to :start-val="in_use" :end-val="in_use" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="8" :sm="8" :lg="8" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <svg-icon icon-class="monitor" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              空闲
            </div>
            <count-to :start-val="idle" :end-val="idle" class="card-panel-num" />
          </div>
        </div>
      </el-col>
    </el-row>

    <!--空闲会议室列表,展示8个-->
    <span style="font-weight: bold;">空闲会议室</span>
    <el-row :gutter="40" class="panel-group">
      <el-col v-for="(item) in idleList" :key="item.roomId" :xs="6" :sm="6" :lg="6" class="card-panel-col" @click.native="showInfo(item)">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-message">
            <img :src="item.imgPath" width="61px">
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              {{ item.roomName }}
            </div>
            <div class="card-panel-text">
              {{ item.floorName }}
            </div>
          </div>
        </div>
      </el-col>
    </el-row>

    <!--会议室详情-->
    <el-dialog :visible.sync="infoVisible" title="会议室详情" width="500px">
      <!--会议室基础信息-->
      <el-form>
        <el-row>
          <el-col :span="12">
            <el-form-item label="会议室名称:">
              {{ room.roomName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会议室描述:">
              {{ room.description }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所在楼层:">
              {{ roomFloor.floorName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维护人:">
              {{ room.maintainer }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系方式:">
              {{ room.contacts }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注:">
              {{ room.remark }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import crudDmMeetingRoom from '@/api/dm/meeting/dmMeetingRoom'
import { mapGetters } from 'vuex'

export default {
  components: {
    CountTo
  },
  data() {
    return {
      total: 0, // 会议室总数
      in_use: 0, // 正在使用数量
      idle: 0, // 空闲数量
      idleList: [], // 空闲列表
      infoVisible: false, // 会议室详情
      room: {}, // 会议室信息
      roomFloor: {}// 会议楼层信息
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  created() {
    this.roomSummary()
    this.viewList()
  },
  mounted() {
    // 定时器
    this.roomSummaryTimer = setInterval(() => {
      this.roomSummary()
    }, 60000)
    // 空闲列表定时器
    this.viewListTimer = setInterval(() => {
      this.viewList()
    }, 60000)
  },
  beforeDestroy() {
    clearInterval(this.roomSummaryTimer)
    clearInterval(this.viewListTimer)
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    },
    roomSummary() {
      crudDmMeetingRoom.roomSummary().then(res => {
        this.total = res.total
        this.in_use = res.in_use
        this.idle = res.idle
      })
    },
    viewList() {
      crudDmMeetingRoom.viewList({ page: 0, size: 8, sort: 'roomId,desc', roomStatus: 0 }).then(res => {
        this.idleList = res.content
      })
    },
    showInfo(row) {
      console.info('点击查看详情 row ==>> ' + JSON.stringify(row))
      crudDmMeetingRoom.viewInfo(row.roomId).then(res => {
        console.info('视图详情 viewInfo ==>> ' + JSON.stringify(res))
        this.room = res.room
        this.roomFloor = res.room.dmFloor
        /* this.deviceList = res.deviceList
        this.meetingList = res.meetingList
        this.usedMeeting = res.usedMeeting */
        this.infoVisible = true
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
