<template>
    <div class="app-container home">
      <TabTitle :text="nowText" />
      <el-row :gutter="10">
        <el-col :xs="24" :sm="24" :md="24" :lg="24">
          <el-scrollbar height="700px">
            <el-card class="right-list">
            <template v-slot:header>
              <el-form :model="queryParams" ref="queryRef" :inline="true" >
                <el-form-item label="摄像头" prop="algorithmName">
                  <el-select v-model="queryParams.deptName" placeholder="请选择所属部门" clearable style="width: 200px">
                      <el-option
                        v-for="dict in deviceList"
                        :key="dict.id"
                        :label="dict.deviceName"
                        :value="dict.id"
                      />
                  </el-select>
                </el-form-item>
                <el-form-item label="创建时间" >
                  <el-date-picker
                    v-model="dateRange"
                    value-format="YYYY-MM-DD"
                    type="daterange"
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                  ></el-date-picker>
                </el-form-item>
                <el-form-item label="算法场景" prop="applicationScenarios">
                  <el-select v-model="queryParams.deptName" placeholder="请选择所属部门" clearable style="width: 200px">
                      <el-option
                        v-for="dict in algList"
                        :key="dict.id"
                        :label="dict.algorithmName"
                        :value="dict.id"
                      />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                  <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
            </template>
            <el-row :gutter="10" class="mb8" style="justify-content: flex-start;">
               <el-col :span="1.5">
                  <el-button
                     type="primary"
                     plain
                  >四分屏</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     type="primary"
                     plain
                  >六分屏</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     type="primary"
                     plain
                  >十二分屏</el-button>
               </el-col>
            </el-row>
            <div class="alg-list" >
              <el-card  v-for="item in algList" :key="item.name" class="alg-item" shadow="hover" >
                <!-- <template v-slot:header>
                  <div class="cleartitle">
                    <span>{{item.algorithmName}}</span>
                    <el-tag
                      :type="'success'"
                      effect="dark"
                    >
                      {{ 'success'}}
                    </el-tag>
                  </div>
                </template> -->
                <template v-slot:default >
                  <div   style="width: 100%;max-height: 200px;overflow: hidden;">
                    <img
                      :src="'http://192.168.4.206' +item.alarmImg"
                      style="width: 100%;"
                    />
                  </div>
                  <h2>{{ item.alarmType }}</h2>
                  <p style="color: #999999;font-size: 12px;">
                    {{ changeTime(item.alarmTime) }}
                  </p>
                  <div style="display: flex;justify-content: flex-end;position: absolute;right: 15px;bottom: 10px;" >
                    <el-button link type="primary" icon="Edit" @click.stop="handleUpdate(item)" >详情</el-button>
                    <!-- <el-button link type="primary" icon="Edit" @click.stop="handleUpdate(item)" >修改</el-button>
                    <el-button link type="primary" icon="Delete" @click.stop="handleDelete(item)">删除</el-button> -->
                  </div>
                </template>
              </el-card>
            </div>
          </el-card>
          </el-scrollbar>
        </el-col>
      </el-row>
    </div>
</template>
  
<script setup name="Index">
  import { listAlarm, detailAlarm } from "@/api/alarmControl/index.js";
  import { listDevice, } from "@/api/yunshou/device";
  import moment from 'moment'
  // import algForm from './components/algorithmDown.vue'
  import { ArrowDown } from '@element-plus/icons-vue'
  import { Search } from '@element-plus/icons-vue'
  const router = useRouter();
  const { proxy } = getCurrentInstance();
  const algorithmDownRef = ref(null)
  const nowText=ref('告警管理')
  const ids = ref([]);
  const deviceList = ref([]);
  const algorithmList=reactive([
    {
      name:"我的算法",
      value:1
    },
    {
      name:"最新算法",
      value:2
    },
    {
      name:"基础算法",
      value:3
    },
    {
      name:"智慧煤矿",
      value:4
    },
    {
      name:"智慧能源",
      value:5
    },
    {
      name:"智慧校园",
      value:6
    },
    {
      name:"智慧港口",
      value:7
    },
    {
      name:"智慧煤矿",
      value:8
    },
    {
      name:"智慧能源",
      value:9
    },
    {
      name:"智慧校园",
      value:10
    },
  ])
  const algList = ref([]);
  const data = reactive({
    form: {},
    queryParams: {
      postCode: undefined,
      searchValue: '',
      status: undefined
    },
    rules: {
      postName: [{ required: true, message: "岗位名称不能为空", trigger: "blur" }],
      postCode: [{ required: true, message: "岗位编码不能为空", trigger: "blur" }],
      postSort: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }],
    }
  });
  const { queryParams, form, rules } = toRefs(data);


  function changeTime(val){
    return moment(val).format('YYYY/MM/DD HH:mm:ss')
  }
  
 /** 查询定时任务列表 */
 function getDeviceList() {
   listDevice().then(response => {
     deviceList.value = response.rows;
   });
 }
 /** 重置按钮操作 */
 function resetQuery() {
   proxy.resetForm("queryRef");
   handleQuery();
 }

  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }
  
  /** 查询算法列表 */
  function getList() {
    listAlarm(queryParams.value).then(response => {
      // console.log("🚀 ~ listAlg ~ response:", response)
      algList.value = response.rows
    });
  }
  function handeAdd(row){
    algorithmDownRef.value.handleAdd()
  }
  function handDetails(id){
    router.push("/algorithmList/details/info/" + '123');
  }
  function handleSetSize(row) {
    console.log('%c [ row ]-170', 'font-size:13px; background:pink; color:#bf2c9f;', row)
    // reset();
    // const postId = row.postId || ids.value;
    // getPost(postId).then(response => {
    //   form.value = response.data;
    //   open.value = true;
    //   title.value = "修改岗位";
    // });
  }
  function handleUpdate(row) {
    algorithmDownRef.value.handleUpdate(row)
  }
  
  /** 删除按钮操作 */
  function handleDelete(row) {
    const id = row.id || ids.value;
    proxy.$modal.confirm('是否确认删除算法名称为"' + row.algorithmName + '"的数据项？').then(function() {
      return deleteAlg(id);
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    }).catch(() => {});
  }
  getList();
  getDeviceList();
  </script>
  
  <style scoped lang="scss">
   .search-input{
    display: flex;
    width: 400px;
    margin-right: 10px;
   }
   .add-but{
    position: absolute;
    display: flex;
    top: 30px;
    right: 30px;
   }
   .left-list{
    min-height: 700px;
   }
   .right-list{
    min-height: 700px;
    .alg-list{
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 16px;
      .alg-item{
        width: 100%;
        min-height: 350px;
        cursor: pointer;
        position: relative;
      }
    }
   }
   .cleartitle{
    font-size: 16px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
  }
  </style>
  
  