<template>
  <div class="app-container">
    <div class="main-right-box">
      <div class="main-search-box">
        <el-form
          v-show="showSearch"
          ref="queryForm"
          :inline="true"
          :model="queryParams"
          size="small"
        >
          <el-form-item label="机构名称">
            <org-tree
              v-model="queryParams.orgId"
              @defaultKey="getDefaultKey"
              @checkChange="changeCheckBox"
              @click="handleNodeClick"
              ref="orgTree"
            ></org-tree>
          </el-form-item>
          <!-- <el-form-item label="监控主机" prop="hostName">
            <el-input
              v-model="queryParams.hostName"
              clearable
              placeholder="请输入监控主机名称"
            />
          </el-form-item> -->
          <el-form-item label="通道名称" prop="channelName">
            <el-input
              v-model="queryParams.channelName"
              clearable
              placeholder="请输入通道名称"
            />
          </el-form-item>
          <el-form-item label="录像丢失状态" prop="integrityState">
            <el-select
              v-model="queryParams.integrityState"
              clearable
              placeholder="请选择状态"
            >
              <el-option
                v-for="dict in dict.type.video_integrity_state"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="录像存储状态" prop="daysState">
            <el-select
              v-model="queryParams.daysState"
              clearable
              placeholder="请选择状态"
            >
              <el-option
                v-for="dict in dict.type.video_days_state"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="视频诊断状态" prop="diagnosisState">
            <el-select
              v-model="queryParams.diagnosisState"
              clearable
              placeholder="请选择状态"
            >
              <el-option
                v-for="dict in dict.type.video_diagnosis_state"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-form>

        <el-row :gutter="10">
          <el-col :span="1.5">
            <el-button
              icon="el-icon-search"
              size="mini"
              type="primary"
              @click="handleQuery"
              >搜索</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              icon="el-icon-refresh"
              size="mini"
              type="primary"
              @click="resetQuery"
              >重置</el-button
            >
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['core:letter:add']"
            >录入介绍信</el-button>
          </el-col> -->
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>
      </div>
      <el-table
        v-loading="loading"
        :data="dataList"
        border
        height="600"
        size="small"
      >
        <el-table-column label="序号" type="index" align="center" width="70">
          <template slot-scope="scope">
            {{
              (queryParams.pageNum - 1) * queryParams.pageSize +
              scope.$index +
              1
            }}
          </template>
        </el-table-column>
        <el-table-column
              align="center"
              label="地区"
              prop="affiliatedArea"
              show-overflow-tooltip
              min-width="80"
            />
            <el-table-column
              align="center"
              label="行社名称"
              prop="affiliatedBank"
              show-overflow-tooltip
              min-width="120"
            />
        <el-table-column
          :show-overflow-tooltip="true"
          align="center"
          label="组织机构"
          prop="orgName"
          min-width="160"
        ></el-table-column>
        <!--        <el-table-column :show-overflow-tooltip="true" align="center" label="设备名称" prop="reasons"/>-->
         <el-table-column
          :show-overflow-tooltip="true"
          align="center"
          label="主机名称"
          prop="hostName"
        ></el-table-column>
         <el-table-column
          :show-overflow-tooltip="true"
          align="center"
          label="通道名称"
          prop="channelName"
          min-width="200"
        ></el-table-column>
        <!-- <el-table-column
          align="center"
          label="IP地址"
          prop="channelIp"
        ></el-table-column> -->
        <el-table-column
          align="center"
          label="录像丢失时长"
          prop="loseDuration"
          width="120"
        >
          <template slot-scope="r">
            {{
              lostDurationText( r.row.loseDuration)
            }}
          </template>
        </el-table-column>
<!--        <el-table-column
          align="center"
          label="实际/计划存储(天)"
          prop="planDays"
          width="180"
        >
          <template slot-scope="r">
            {{
              r.row.planDays == null
                ? "未知"
                : `${r.row.realDays}/${r.row.planDays}`
            }}
          </template>
        </el-table-column>-->
        <!-- <el-table-column
          align="center"
          label="无视频信号"
          prop="signalLost"
          width="120"
        >
          <template slot-scope="r">
            {{
              getLabel(
                dict.type.video_diagnosis_state,
                r.row.signalLost,
                "未知"
              )
            }}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="视频遮挡"
          prop="occlude"
          width="120"
          ><template slot-scope="r">
            {{
              getLabel(dict.type.video_diagnosis_state, r.row.occlude, "未知")
            }}
          </template></el-table-column
        > -->
        <el-table-column
          align="center"
          label="视频质量"
          prop="quality"
          width="120"
          ><template slot-scope="r">
            {{
              getLabel(dict.type.video_diagnosis_state, r.row.quality, "未知")
            }}
          </template></el-table-column
        >
        <el-table-column label="操作" align="center" width="120">
          <template slot-scope="r">
            <el-button
              type="text"
              @click="openDetail(r.row.hostCode, r.row.channelCode)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </div>
    <!--详情页面-->
    <detail
      ref="DialogDetail"
      @success="refresh(true)"
      :videoDaysState="dict.type.video_days_state"
      :videoDiagnosisState="dict.type.video_diagnosis_state"
      :videoIntegrityState="dict.type.video_integrity_state"
    ></detail>
  </div>
</template>

<script>
import OrgTree from "@/components/orgTree/orgQuerySelector.vue";
import dayjs from "dayjs";
import detail from "./detail.vue";
import { list } from "@/api/iot/videoDiagnosis.js";
import { getLabel } from "@/views/commonOption.js";

export default {
  components: { detail, OrgTree },
  dicts: ["video_integrity_state", "video_days_state", "video_diagnosis_state"],

  data() {
    return {
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hostName: null,
        channelName: null,
        integrityState: null,
        daysState: null,
        diagnosisState: null,
        orgId: null,
        checkSub: true,
      },
      dataList: [],
    };
  },
  mounted() {},
  methods: {
    dayjs,
    getLabel,
    openDetail(hostCode, channelCode) {
      this.$refs.DialogDetail.show(hostCode, channelCode);
    },
    getDefaultKey(key) {
      this.queryParams.orgId = key;
      this.getList();
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.orgId = data.id;
      this.handleQuery();
    },
    /** 下穿状态改变*/
    changeCheckBox() {
      this.queryParams.checkSub = !this.queryParams.checkSub;
      this.handleQuery();
    },

    /** 查询介绍信列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    lostDurationText(duration) {
      if (!duration) {
        return "未知";
      }
      if (duration=='0') {
        return "未丢失";
      }
      let str = "";
      let hour = Math.floor(duration / 60);
      if (hour > 0) {
        str += `${hour}小时`;
      }

      let minute = duration % 60;
      if (minute > 0) {
        str += `${minute}分`;
      }

      return str;
    },
  },
};
</script>
