<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="objId">
        <el-input
          v-model="queryParams.objId"
          placeholder="请输入标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="母排编号" prop="busbarCode">
        <el-input
          v-model="queryParams.busbarCode"
          placeholder="请输入母排编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电柜编号" prop="cabinetCode">
        <el-input
          v-model="queryParams.cabinetCode"
          placeholder="请输入电柜编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="最高温度" prop="tempMax">
        <el-input
          v-model="queryParams.tempMax"
          placeholder="请输入最高温度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最低温度" prop="tempMin">
        <el-input
          v-model="queryParams.tempMin"
          placeholder="请输入最低温度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平均温度" prop="tempAvg">
        <el-input
          v-model="queryParams.tempAvg"
          placeholder="请输入平均温度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="温差" prop="tempDiff">
        <el-input
          v-model="queryParams.tempDiff"
          placeholder="请输入温差"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="是否告警" prop="isAlarm">
        <el-select v-model="queryParams.isAlarm" placeholder="请选择是否告警" clearable>
          <el-option
            v-for="dict in dict.type.record_busbar_temp_is_alarm"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="图像路径" prop="filePath">
        <el-input
          v-model="queryParams.filePath"
          placeholder="请输入图像路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="是否启用" prop="isFlag">
        <el-select v-model="queryParams.isFlag" placeholder="请选择是否启用" clearable>
          <el-option
            v-for="dict in dict.type.record_busbar_temp_is_flag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
<!--      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreatedTime"
          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="updatedBy">
        <el-input
          v-model="queryParams.updatedBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker
          v-model="daterangeUpdatedTime"
          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="记录时间">
        <el-date-picker
          v-model="daterangeRecordTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['record:recordBusbarTemp:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['record:recordBusbarTemp:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['record:recordBusbarTemp:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['record:recordBusbarTemp:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordBusbarTempList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="标识" align="center" prop="objId" />-->
      <el-table-column label="母排编号" align="center" prop="busbarCode" />
      <el-table-column label="电柜编号" align="center" prop="cabinetCode" />
      <el-table-column label="最高温度" align="center" prop="tempMax" />
      <el-table-column label="最低温度" align="center" prop="tempMin" />
      <el-table-column label="平均温度" align="center" prop="tempAvg" />
      <el-table-column label="温差" align="center" prop="tempDiff" />
      <el-table-column label="是否告警" align="center" prop="isAlarm">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.record_busbar_temp_is_alarm" :value="scope.row.isAlarm"/>
        </template>
      </el-table-column>
      <el-table-column label="图像路径" align="center" prop="filePath" />
<!--      <el-table-column label="打开文件" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="showPhoto(scope.row)">显示图片</el-button>
        </template>
      </el-table-column>-->
<!--      <el-table-column label="是否启用" align="center" prop="isFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.record_busbar_temp_is_flag" :value="scope.row.isFlag"/>
        </template>
      </el-table-column>-->
      <el-table-column label="备注" align="center" prop="remark" />
<!--      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" />
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="记录时间" align="center" prop="recordTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="showPhoto(scope.row)"
            v-hasPermi="['record:recordBusbarTemp:list']"
          >打开文件</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['record:recordBusbarTemp:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['record:recordBusbarTemp:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改母排测温信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="母排编号" prop="busbarCode">
          <el-input v-model="form.busbarCode" placeholder="请输入母排编号" />
        </el-form-item>
        <el-form-item label="电柜编号" prop="cabinetCode">
          <el-input v-model="form.cabinetCode" placeholder="请输入电柜编号" />
        </el-form-item>
        <el-form-item label="最高温度" prop="tempMax">
          <el-input v-model="form.tempMax" placeholder="请输入最高温度" />
        </el-form-item>
        <el-form-item label="最低温度" prop="tempMin">
          <el-input v-model="form.tempMin" placeholder="请输入最低温度" />
        </el-form-item>
        <el-form-item label="平均温度" prop="tempAvg">
          <el-input v-model="form.tempAvg" placeholder="请输入平均温度" />
        </el-form-item>
        <el-form-item label="温差" prop="tempDiff">
          <el-input v-model="form.tempDiff" placeholder="请输入温差" />
        </el-form-item>
        <el-form-item label="是否告警" prop="isAlarm">
          <el-radio-group v-model="form.isAlarm">
            <el-radio
              v-for="dict in dict.type.record_busbar_temp_is_alarm"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="图像路径" prop="filePath">
          <el-input v-model="form.filePath" placeholder="请输入图像名称(*.jpg)" />
        </el-form-item>
        <el-form-item label="是否启用" prop="isFlag">
          <el-radio-group v-model="form.isFlag">
            <el-radio
              v-for="dict in dict.type.record_busbar_temp_is_flag"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
<!--        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="updatedBy">
          <el-input v-model="form.updatedBy" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedTime">
          <el-date-picker clearable
            v-model="form.updatedTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>-->
        <el-form-item label="记录时间" prop="recordTime">
          <el-date-picker clearable
            v-model="form.recordTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择记录时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



<!-- 图片显示对话框 -->
<!-- 通过增加key属性来确保每次图片URL更新时，Vue都会重新渲染图片元素，从而避免显示旧的缓存图片。 -->
    <el-dialog :title="photoTitle" :visible.sync="photoOpen" width="1333px" append-to-body>
      <div class="dialog-content">
        <div class="image-container" v-if="visiblePhoto">
          <img :src="visiblePhoto" alt="显示可见光图片" v-show="photoOpen" :key="visiblePhotoKey" />
        </div>
        <div class="image-container" v-if="thermalPhoto">
          <img :src="thermalPhoto" alt="显示热成像图片" v-show="photoOpen" :key="thermalPhotoKey" />
        </div>
      </div>
    </el-dialog>


<!--<el-dialog :title="photoTitle" :visible.sync="photoOpen" width="500px" append-to-body>
<template>
  <div class="image-container">
    <img :src="visiblePhoto" alt="显示图片" />
  </div>
  <div class="image-container">
    <img :src="thermalPhoto" alt="显示图片" />
  </div>
</template>
</el-dialog>-->


  </div>
</template>

<script>
import {
  listRecordBusbarTemp,
  getRecordBusbarTemp,
  delRecordBusbarTemp,
  addRecordBusbarTemp,
  updateRecordBusbarTemp,
  getVisiblePhoto, getThermalPhoto
} from "@/api/record/recordBusbarTemp";

export default {
  name: "RecordBusbarTemp",
  dicts: ['record_busbar_temp_is_alarm', 'record_busbar_temp_is_flag'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 母排测温信息表格数据
      recordBusbarTempList: [],
      // 弹出层标题
      title: "",
      // 图片显示标题
      photoTitle: "",
      // 是否显示弹出层
      open: false,
      // 是否显示图片显示
      photoOpen: false,
      // 记录时间时间范围
      daterangeCreatedTime: [],
      // 记录时间时间范围
      daterangeUpdatedTime: [],
      // 记录时间时间范围
      daterangeRecordTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        objId: null,
        busbarCode: null,
        cabinetCode: null,
        tempMax: null,
        tempMin: null,
        tempAvg: null,
        tempDiff: null,
        isAlarm: null,
        filePath: null,
        isFlag: null,
        remark: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        recordTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        busbarCode: [
          { required: true, message: "母排编号不能为空", trigger: "blur" }
        ],
        cabinetCode: [
          { required: true, message: "电柜编号不能为空", trigger: "blur" }
        ],
      },
      visiblePhoto: '',
      thermalPhoto: '',
      thermalPhotoKey: 0,//在图片对话框中使用，更新图片时增加key值，防止缓存
      visiblePhotoKey: 0,//在图片对话框中使用，更新图片时增加key值，防止缓存
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询母排测温信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreatedTime && '' != this.daterangeCreatedTime) {
        this.queryParams.params["beginCreatedTime"] = this.daterangeCreatedTime[0];
        this.queryParams.params["endCreatedTime"] = this.daterangeCreatedTime[1];
      }
      if (null != this.daterangeUpdatedTime && '' != this.daterangeUpdatedTime) {
        this.queryParams.params["beginUpdatedTime"] = this.daterangeUpdatedTime[0];
        this.queryParams.params["endUpdatedTime"] = this.daterangeUpdatedTime[1];
      }
      if (null != this.daterangeRecordTime && '' != this.daterangeRecordTime) {
        this.queryParams.params["beginRecordTime"] = this.daterangeRecordTime[0];
        this.queryParams.params["endRecordTime"] = this.daterangeRecordTime[1];
      }
      listRecordBusbarTemp(this.queryParams).then(response => {
        this.recordBusbarTempList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.photoOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        objId: null,
        busbarCode: null,
        cabinetCode: null,
        tempMax: null,
        tempMin: null,
        tempAvg: null,
        tempDiff: null,
        isAlarm: null,
        filePath: null,
        isFlag: null,
        remark: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null,
        recordTime: null,
        photoOpen : false,
        visiblePhoto : null,
        thermalPhoto : null,
        thermalResponse : null,
        visibleResponse : null,
      };
      this.resetForm("form");
      this.photoOpen = false;
      this.visiblePhoto = null;
      this.thermalPhoto = null;
      this.thermalResponse = null;
      this.visibleResponse = null;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreatedTime = [];
      this.daterangeUpdatedTime = [];
      this.daterangeRecordTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.objId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加母排测温信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const objId = row.objId || this.ids
      getRecordBusbarTemp(objId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改母排测温信息";
      });
    },

    /** 图片显示操作 */
    showPhoto(row) {
      this.reset();
      if(row.filePath){
        const filePath = row.filePath ;

        // 清除缓存
        this.thermalPhoto = null;
        this.visiblePhoto = null;

        //TODO:修改为实际接口地
/*        const thermalResponse = `/dev-api/record/recordBusbarTemp/getVisiblePhoto/${filePath}`;
        this.thermalPhoto = thermalResponse;
        const visibleResponse = `/dev-api/record/recordBusbarTemp/getThermalPhoto/${filePath}`;
        this.visiblePhoto = visibleResponse;*/
        const thermalResponse = `/prod-api/record/recordBusbarTemp/getVisiblePhoto/${filePath}`
        this.thermalPhoto = thermalResponse;
        const visibleResponse = `/prod-api/record/recordBusbarTemp/getThermalPhoto/${filePath}`
        this.visiblePhoto = visibleResponse;

        this.thermalPhotoKey++; // 更新 key 以重新渲染图片
        this.visiblePhotoKey++; // 更新 key 以重新渲染图片

        this.photoOpen = true;
        this.photoTitle = row.filePath + "图片显示";
      }else {
        this.$modal.msgError("暂无图像路径");
      }
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.objId != null) {
            updateRecordBusbarTemp(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecordBusbarTemp(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const objIds = row.objId || this.ids;
      this.$modal.confirm('是否确认删除母排测温信息编号为"' + objIds + '"的数据项？').then(function() {
        return delRecordBusbarTemp(objIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('record/recordBusbarTemp/export', {
        ...this.queryParams
      }, `recordBusbarTemp_${new Date().getTime()}.xlsx`)
    },

  }
};
</script>
<!--
上面的图像是 2688x1520，下面的图像是 1920x1080。
<style scoped>
/* 定义一个图像容器类，用于设置图像的布局和样式 */
.image-container {
  width: 100%; /* 设置容器宽度为100%，以适应父元素 */
  max-width: 1080px; /* 设置容器的最大宽度，防止图像在大屏幕上显示过大 */
  margin: 0 auto; /* 居中显示容器 */
  position: relative; /* 设置相对定位，以便于在容器内进行绝对定位 */
  aspect-ratio: 16 / 9; /* 16:9 的比例，适合 1920x1080 的图像 */
  margin-bottom: 10px; /* 减少容器之间的间距 */
}

/* 设置图像容器内的图像样式 */
.image-container img {
  width: 100%; /* 设置图像宽度为100%，充满容器 */
  height: 100%; /* 设置图像高度为100%，充满容器 */
  object-fit: contain; /* 使用 contain 以确保图像完整显示 */
}

/* 对话框内容区域的样式 */
.dialog-content {
  max-height: 80vh; /* 设置最大高度为视口高度的 80% */
  overflow-y: auto; /* 添加垂直滚动条 */
}
</style>
-->

<style scoped>
.dialog-content {
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  width: 100%; /* 增大对话框的宽度 */
  max-width: 1920px; /* 设置对话框的最大宽度 */
}

.image-container {
  text-align: center;
  margin-bottom: 10px;
  width: 49%; /* 修改为100%以充满父容器 */
  max-width: 100%; /* 增加最大宽度 */
  aspect-ratio: 16/9;
  position: relative;
}

.image-container img {
  max-width: 100%;
  height: auto;
  border: 1px solid #ddd;
  padding: 5px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  object-fit: contain;
}
</style>

