<template>
  <div class="video">
    <div class="videoTop">
      <div class="videoTopLeft">
        选择站点:
        <el-select
        filterable
          v-model="store.state.siteId"
          placeholder="请选择"
          style="width: 150px; margin-right: 20px"
        >
          <el-option
            v-for="site in store.state.siteList"
            :key="site"
            :label="site.siteName"
            :value="site.id"
          ></el-option>
        </el-select>
        <el-input
          placeholder="搜索设备名"
          v-model="filterText"
          class="videoTopLeftInput"
        >
          <!-- <template #suffix>
            <i class="el-icon-search el-input__icon"></i>
          </template> -->
        </el-input>

        <el-button
          type="primary"
          icon="el-icon-search"
          class="search-button"
          @click="videoMonitoringDeviceList()"
        >
          搜索
        </el-button>
        <!-- <el-button
          class="search-button"
          icon="el-icon-plus"
          type="success"
          @click="Insert()"
        >
          新增
        </el-button> -->
      </div>

      <!-- <div class="videoRight">
        <el-button type="primary">导入</el-button>
        <el-button type="primary">导出</el-button>
      </div> -->
    </div>

    <div class="videoContent">
      <el-table
        :data="tableData"
        border
        stripe
        :header-cell-style="headClass"
        :height="Height"
      >
        <el-table-column
          prop="stationStatus"
          label="状态"
          align="center"
          width="50"
        >
          <template #default="scope">
            <el-avatar
              class="status"
              :style="
                scope.row.stationStatus == 0
                  ? 'background-color:red'
                  : 'background-color:#04F21C'
              "
            ></el-avatar>
          </template>
        </el-table-column>

        <el-table-column
          prop="deviceName"
          label="名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="deviceCode"
          label="编号"
          align="center"
          width=""
        ></el-table-column>

        <el-table-column
          prop="floor"
          label="楼层"
          align="center"
          width="60"
        ></el-table-column>
        <el-table-column
          prop="deviceAddress"
          label="设备安装位置"
          align="center"
          width=""
        ></el-table-column>
        <el-table-column prop="deviceType" label="设备类型" align="center">
          <template #default="scope">
            {{ scope.row.deviceType == '2' ? '视频监控设备' : '其他' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="installTime"
          label="安装时间"
          align="center"
          width="200"
        ></el-table-column>
        <el-table-column
          prop="creator"
          label="创建人"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="sim"
          label="sim卡号"
          align="center"
        ></el-table-column>
        <!-- <el-table-column label="视频画面" align="center" width="150">
          <template #default="scope" style="text-align: center">
            <el-button
              type="text"
              size="small"
              style="color: #409eff"
              @click.prevent="LookUp(scope.$index, scope.row)"
            >
              查看
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <div class="listPagination">
        <el-pagination
          v-model:currentPage="currentPage"
          :page-sizes="[15, 20, 25, 30]"
          :page-size="15"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
        ></el-pagination>
      </div>

      <!--视频弹框组件开始-----------------------start-->
      <check-video
        :dialogTitle="dialogTitle"
        @closeDialog="closeDialog"
        :flag="showDialog"
      ></check-video>
      <!--视频弹框组件结束-----------------------end-->
    </div>

    <div></div>
  </div>
</template>
<script>
import { useStore } from 'vuex'
import { defineComponent, ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import * as api from '@/api/deviceManage/videoEquip.js'
import checkVideo from './checkVideo'

export default defineComponent({
  name: 'powerEquip',
  components: { checkVideo },
  props: {
    Height: String,
  },
  setup() {
    const store = useStore()

    const dialogTitle = ref('')
    const showDialog = ref(false)

    const total = ref(0)
    const pageSize = ref(15)
    const currentPage = ref(1)
    const filterText = ref('')
    const activeName = 'powerEquip'
    const tableData = ref([])

    //查看视频画面
    const LookUp = (ind, row) => {
      // alert(2)
      console.log(ind, row)
      dialogTitle.value = '查看视频'
      showDialog.value = true
    }
    const handleSizeChange = (val) => {
      pageSize.value = val
      videoMonitoringDeviceList()
    }
    const handleCurrentChange = (val) => {
      currentPage.value = val
      videoMonitoringDeviceList()
    }
    // 表头样式设置
    const headClass = () => {
      return 'background:#FAFAFA !important;color: black;'
    }

    // 关闭操作
    const closeDialog = () => {
      showDialog.value = false
      // videoMonitoringDeviceList()
    }

    //视频列表
    function videoMonitoringDeviceList() {
      api
        .videoMonitoringDeviceList({
          siteId: store.state.siteId,
          size: pageSize.value,
          current: currentPage.value,
          deviceType: 2,
          deviceName: filterText.value,
        })
        .then((requset) => {
          if (requset.status === 'SUCCESS') {
            tableData.value = requset.data.records
            total.value = requset.data.total
          } else {
            ElMessage.error(requset.msg)
          }
        })
    }
    onMounted(() => {
      videoMonitoringDeviceList()
    })

    return {
      headClass,
      LookUp,
      handleSizeChange,
      handleCurrentChange,
      videoMonitoringDeviceList,

      filterText,
      tableData,
      activeName,
      currentPage,
      closeDialog,
      dialogTitle,
      showDialog,
      store,
    }
  },
})
</script>

<style lang="scss" scoped>
//first样式
.video {
  margin: 15px;
  //顶部左侧样式
  .videoTop {
    display: flex;
    height: 32px;
    line-height: 32px;
    .videoTopLeft {
      width: 70%;
      .goBack {
        margin-right: 15px;
      }
      .videoTopLeftTitle {
        font-size: 14px;
        margin-right: 10px;
      }
      .videoTopLeftInput {
        width: 15rem;
      }
      .el-input__icon {
        color: #409eff;
      }
      .el-input__inner:hover {
        border-color: #409eff;
      }
      .el-input__inner:focus {
        border-color: #409eff;
      }
      .search-button {
        margin-left: 1rem;
      }
    }

    //顶部右侧样式
    .videoRight {
      width: 30%;
      button {
        margin-left: 1rem;
        float: right;
      }
    }
  }
  .videoContent {
    margin-top: 15px;
  }
}

.listPagination {
  margin-top: 15px;
  float: right;
}
</style>