<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预警类型" prop="alarmType">
        <el-select v-model="queryParams.alarmType" placeholder="预警类型" clearable>
          <el-option
            v-for="dict in dict.type.aibox_alarm_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="预警时间">
        <el-date-picker
          v-model="daterangeMarksTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item
        label="责任主体"
        prop="projectDeptId"
        v-hasPermi="['project:project:zgs']"
      >
        <el-select
          v-model="queryParams.projectDeptId"
          placeholder="请选择责任主体"
          clearable
        >
          <el-option
            v-for="dict in depts"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="dataList" stripe
    >
      <el-table-column
        label="项目名称"
        align="center"
        prop="projectName"
        width="240"
      />
      <el-table-column
        label="单位名称"
        align="center"
        prop="deptName"
        width="210"
      />
      <el-table-column label="预警图片" align="center" property="path" width="220">
        <template slot-scope="scope">
          <el-image
            ref="preview"
            style="width: 200px; height: 100px"
            :src="getSrc(scope.row.imageUrl)"
            @click="onPreview(scope.row.imageUrl)"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="预警类型" align="center" prop="alarmType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.aibox_alarm_type" :value="scope.row.alarmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="设备通道"
        align="center"
        prop="channelName"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column
        label="设备名称"
        align="center"
        prop="deviceName"
        width="250"
      >
        <template slot-scope="scope">
          <el-tag :type="info">{{ scope.row.deviceName }}</el-tag>
          <div>{{ scope.row.serialNumber }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="预警时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据状态" align="center" prop="isDel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_isdel" :value="scope.row.isDel" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="srcList" />
  </div>
</template>

<script>
import { listAiBoxProjectData } from "@/api/project/aiBoxProjectData";
import ElImageViewer from "element-ui/packages/image/src/image-viewer";

export default {
  name: "SspProblemmodify",
  components: {
    ElImageViewer,
  },
  dicts: ["aibox_alarm_type", "sys_common_isdel"],
  data() {
    return {
      showViewer: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全整改表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openVideo: false,
      videoSrc: null,
      // 更新时间时间范围
      daterangeMarksTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: null,
        projectName: null,
        deptId: null,
        deptName: null,     
        projectDeptId: null,
      },
      depts: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      srcList: [],
    };
  },
  created() {
    this.getList();
    this.$api.publics.getZgsDeptList().then((d) => {
      this.depts = d?.data || [];
    });
  },
  methods: {
    getSrc(url){
      return url + '.min.jpg'
    },
    onPreview(urls) {
      var arrayurls = urls.split(",");
      this.srcList = [];
      arrayurls.forEach((v, i) => {
        this.srcList.push(v);
      });
      this.showViewer = true;
    },
    closeViewer() {
      this.showViewer = false;
    },
    /** 查询安全整改列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeMarksTime && "" != this.daterangeMarksTime) {
        this.queryParams.params["beginTime"] = this.daterangeMarksTime[0];
        this.queryParams.params["endTime"] = this.daterangeMarksTime[1];
      }
      listAiBoxProjectData(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.roleTypes=[];
      this.daterangeMarksTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
