<template>
  <div class="login">
    <div class="pageCard backgroundTitle" id="warnMessage">
      <div class="cardTitle">
        <div>
          <span class="arrows1">&gt;</span><span class="arrows2">&gt;</span>
          <span class="arrows3">&gt;</span> 告警/故障信息
          <span class="arrows3">&lt;</span><span class="arrows2">&lt;</span>
          <span class="arrows1">&lt;</span>
        </div>
        <div class="operation">
          <span @click="handleClear"
            ><i class="el-icon-tickets" style="margin-right: 5px"></i
            >查看全部</span
          >
        </div>
      </div>
      <div class="cardContent">
        <el-table
          ref="restauranttable"
          :data="tableData"
          border
          class="tableHi"
        >
          <el-table-column align="center" prop="warnTime" label="报警时间">
          </el-table-column>
          <el-table-column align="center" prop="deviceName" label="设备名称">
          </el-table-column>
          <el-table-column align="center" prop="warnDesc" label="告警信息">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="dark"
                :content="scope.row.warnDesc"
                placement="top"
              >
                <span> {{ scope.row.warnDesc }}</span>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="warningCount" label="告警次数">
          </el-table-column>
          <el-table-column align="center" prop="warningValue" label="当前值">
          </el-table-column>
          <el-table-column align="center" prop="threadval" label="告警阈值">
          </el-table-column>
          <el-table-column align="center" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="particulars(scope.$index, scope.row)"
                type="text"
                size="small"
              >
                查看详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 阈值设置 -->
    <!-- <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogOpen"
      width="40%"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="相位" prop="xw">
              <el-select v-model="form.xw" placeholder="请选择相位">
                <el-option
                  v-for="dict in phasePosition"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select> </el-form-item
          ></el-col>
          <el-col :span="12"
            ><el-form-item label="阈值" prop="fz">
              <el-input
                type="number"
                v-model="form.fz"
              ></el-input> </el-form-item
          ></el-col>
        </el-row>
      </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> -->
    <!-- 清除 -->
    <el-dialog
      :title="warnDialogTitle"
      :visible.sync="warnDdialogOpen"
      width="60%"
      append-to-body
      :fullscreen="fullscreen"
      :close-on-click-modal="false"
    >
      <clearDialog v-if="dialogType == '1'" :tableData="dataAll"> </clearDialog>
      <particularsDialog v-else :data="detailData"> </particularsDialog>
    </el-dialog>
  </div>
</template>

<script>
import { queryAlarm, queryAlarmDetail } from "@/api/home/home";
// 左边
import clamp from "@/assets/page_left/clamp.png";
// 引入table组件
import clearDialog from "../clearDialog";
import particularsDialog from "../particularsDialog";
export default {
  name: "Login",
  components: {
    clearDialog,
    particularsDialog,
  },
  data() {
    return {
      fullscreen: true,
      dialogType: "1",
      pageCardTitle: "告警/故障信息",
      warnDialogTitle: "告警详情",
      warnDdialogOpen: false,
      phasePosition: [],
      form: {
        xw: "",
        fz: "",
      },
      rules: {
        xw: [{ required: true, message: "相位不能为空", trigger: "blur" }],
        fz: [{ required: true, message: "阈值不能为空", trigger: "blur" }],
      },
      loading: false,
      // 左边
      clamp: clamp,
      //   卡片显示与否
      tabPosition: "bottom",
      //   开关状态
      //   标题内容是否显示
      oilChromatographyTitle: "",
      tableData: [],
      dataAll: {},
      samplingDate: "2021-10-11 15:15:30",
      progressbarLen1: 0,
      detailData: {},
      queryData: {
        state: "1",
        startTime: "",
        endTime: "",
        eqmId: "",
        page: 1,
        limit: 10,
      },
    };
  },
  created() {
    this.queryAlarm();
  },
  mounted() {
    this.$nextTick(() => {
      if (this.tableData.length > 3) {
        //判断表格的长度
        this.a = setInterval(() => {
          //一直调用
          this.restaurantTableMove(); //调用方法
        }, 50);
      }
    });
  },
  methods: {
    queryAlarm() {
      queryAlarm(this.queryData).then((response) => {
        const { code, data, msg } = response;
        this.loading = false;
        if (code === 200) {
          this.tableData = data;
        } else {
          this.msgError(msg);
        }
      });
    },
    restaurantTableMove() {
      if (
        this.$refs.restauranttable &&
        this.$refs.restauranttable.bodyWrapper
      ) {
        var len = this.$refs.restauranttable.bodyWrapper.scrollHeight / 2 + 6; //进度条最大高度，可以加快滚动速度
        this.progressbarLen1 += 1;
        this.$refs.restauranttable.bodyWrapper.scrollTop = this.progressbarLen1;
        if (this.progressbarLen1 > len) {
          this.progressbarLen1 = 0;
          this.$refs.restauranttable.bodyWrapper.scrollTop = 0;
        }
      }
    },
    particulars(index, row) {
      this.queryData.eqmId = row.eqmId;
      queryAlarmDetail(this.queryData).then((response) => {
        const { code, data, msg } = response;
        this.loading = false;
        if (code === 200) {
          this.detailData = data;
        } else {
          this.msgError(msg);
        }
      });
      // rows.splice(index, 1);
      this.warnDdialogOpen = true;
      this.dialogType = "2";
    },

    // 清除操作
    handleClear() {
      let params = {
        state: "1",
        startTime: "",
        endTime: "",
        eqmId: "",
        page: 1,
        limit: 10,
      };
      queryAlarmDetail(params).then((response) => {
        const { code, data, msg } = response;
        this.loading = false;
        if (code === 200) {
          this.dataAll = data;
        } else {
          this.msgError(msg);
        }
      });
      this.warnDdialogOpen = true;
      this.dialogType = "1";
      // this.warnDialogTitle=""
    },
    // 点击开关
    tendencyChartChange(type) {
      let unit = "mA";
      let legendData = ["铁芯泄露电流", "夹件泄漏电流"];
      let xAxisData = ["10-01", "10-02", "10-03", "10-04", "10-05", "10-06"];
      let seriesData = [
        { name: "铁芯泄露电流", data: [10, 25, 2, 100, 59, 78, 36] },
      ];
      this.$emit("dataDispose", unit, legendData, xAxisData, seriesData);
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "~@/assets/stylesheet/card";
.warnPageCardTitle {
  color: #ff1b1bff;
  background: #ff1b1b33 !important;
  border: 1px solid #ff1b1bff;
  backdrop-filter: blur(10px);
  box-shadow: inset 0px 2px 9.77px 0px #eb1414b2;
}
.pageCard {
  min-height: 250px;
}
.pageCard .cardTitle {
  color: #fff;
  .unfoldCloseIcon {
    color: #fff;
  }
}
#warnMessage .cardTitle {
  border-bottom: 1px dashed #fff;
  padding: 0 !important;
}
#warnMessage .cardContent {
  padding: 0px !important;
  box-sizing: border-box;
}
.tableHi {
  width: 100%;
  height: 200px;
}
/* 警告标题箭头 */
.arrows3 {
  color: #fff;
}
.arrows2 {
  color: rgba(256, 256, 256, 0.5);
}
.arrows1 {
  color: rgba(256, 256, 256, 0.15);
}
.operation {
  font-size: 14px;
  span {
    cursor: pointer;
  }
  i {
    margin-left: 10px;
  }
}
.backgroundTitle {
  background-size: 100% 100%;
  background-repeat: no-repeat;
  position: relative;
  margin-bottom: 0px;
}
#warnMessage {
  background: #ff1b1b33;
  border: 1px solid #ff1b1bff;
  backdrop-filter: blur(10px);
  box-shadow: inset 0px 2px 9.77px 0px #eb1414b2;
  padding: 0 30px;
  box-sizing: border-box;
  /* 修改表格默认样式 */
  /deep/ .el-table__fixed-right-patch {
    background: none;
    border: none !important;
  }
  /deep/ .cardContent .el-table,
  /deep/ .cardContent .el-table thead,
  /deep/ .cardContent .el-table tr,
  /deep/ .cardContent .el-table td.el-table__cell,
  /deep/ .el-table th.el-table__cell.is-leaf {
    color: #fff !important;
    background: transparent !important;
    border: none !important;
  }
  /deep/ .el-table::before,
  /deep/ .el-table--border::after,
  /deep/ .el-table--group::after,
  /deep/ .el-table__fixed-right::before,
  .el-table__fixed::before {
    display: none;
  }
  /deep/ .cardContent .el-table td.el-table__cell,
  /deep/ .cardContent .el-table .el-table__cell {
    padding: 5px 0;
  }
  /deep/ .el-table--scrollable-y .el-table__body-wrapper {
    overflow-y: hidden;
  }
  /deep/ .el-table--border th.el-table__cell.gutter:last-of-type {
    border-width: 0px !important;
    background: none;
  }
}
@media screen and (max-width: 1440px) {
  .tableHi {
    height: 160px;
  }
}
</style>