<template>
  <el-dialog
    class="cmdMsgDialog"
    title="历史信息"
    :visible.sync="isShow"
    :close-on-click-modal="false"
  >
    <div class="cmdBoxMain">
      <el-table
        :data="gridData"
        style="width: 100%"
        border
        stripe
        height="calc(100% - 40px)"
        v-loading="girdloading"
      >
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column prop="createTime" label="时间"></el-table-column>
        <el-table-column label="id">
          <template slot-scope="scope">
            {{ scope.row.raw_report.id }}
          </template>
        </el-table-column>

        <el-table-column label="i1服务器">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.cma
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.cma }}</span>
          </template>
        </el-table-column>
        <el-table-column label="心跳间隔" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.heartbeatDuration
            }}</span>
            <span v-else>{{
              scope.row.raw_report.msgs.heartbeatDuration
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="电池">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.battary
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.battery }}</span>
          </template>
        </el-table-column>
        <el-table-column label="电池温度" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.batteryTmp
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.batteryTmp }}</span>
          </template>
        </el-table-column>
        <el-table-column label="主板温度" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.mainBoardTmp
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.mainBoardTmp }}</span>
          </template>
        </el-table-column>

        <el-table-column label="系统重启" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.rebootTimes
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.rebootTimes }}</span>
          </template>
        </el-table-column>
        <el-table-column label="i1重启" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.i1RebootTimes
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.i1RebootTimes }}</span>
          </template>
        </el-table-column>

        <el-table-column label="收" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.recv
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.recv }}</span>
          </template>
        </el-table-column>
        <el-table-column label="传图" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.pic
            }}</span>
            <span v-else> {{ scope.row.raw_report.pic }}</span>
          </template>
        </el-table-column>
        <el-table-column label="拍" width="60">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.photoTimes
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.photoTimes }}</span>
          </template>
        </el-table-column>
        <el-table-column label="成/败/传" width="70">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">
              {{ scope.row.raw_report.success }}/{{
                scope.row.raw_report.failure
              }}/{{ scope.row.raw_report.uploads }}</span
            >
            <span v-else>
              {{ scope.row.raw_report.msgs.success }}/{{
                scope.row.raw_report.msgs.failure
              }}/{{ scope.row.raw_report.msgs.uploads }}</span
            >
          </template>
        </el-table-column>
        <el-table-column label="心跳累计" width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.numberOfHb
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.numberOfHb }}</span>
          </template>
        </el-table-column>
        <el-table-column label="网络异常" width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.networkError
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.networkError }}</span>
          </template>
        </el-table-column>
        <el-table-column label="信号1" width="60">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.signature1
            }}</span>
            <span v-else>{{ scope.row.raw_report.msgs.signature1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="信号2" width="60">
          <template slot-scope="scope">
            <span v-if="scope.row.raw_report.hasOwnProperty('XyDev')">{{
              scope.row.raw_report.signature2
            }}</span>
            <span v-else> {{ scope.row.raw_report.msgs.signature2 }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="其他">
          <template slot-scope="scope">
            {{  scope.row.raw_report.msgs.id }}
          </template>
        </el-table-column> -->

        <el-table-column prop="content" label="其他" class-name="msgClass">
          <template slot-scope="scope">
            <el-tooltip
              :open-delay="600"
              popper-class="msgTootip"
              placement="top"
              effect="light"
            >
              <div slot="content">
                <p v-html="cutout(scope.row)"></p>
              </div>
              <p>
                {{ scope.row.content }}
              </p>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageNation">
        <el-pagination
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page="page"
          :page-size="pageSize"
          layout="sizes, prev, pager, next, jumper,total"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { getqueryRawApi } from "@/utils/api/index";
export default {
  props: {},
  data() {
    return {
      gridData: [],
      girdloading: true,
      isShow: false,
      page: 1, // 当前页数
      pageSize: 20, // 每页数量
      total: 0, //总条数
      termid: "",
    };
  },
  methods: {
    //tootip提示
    cutout(cellValue) {
      var aString = cellValue.content
        .replace(/\,/g, "</br>")
        .replace(/{|}/g, "")
        .replace(/"|"/g, "")
        .replace(/msg:/g, "");

      return aString;
    },
    getQueryList() {
      this.girdloading = true;
      getqueryRawApi({
        termId: this.termid,
        p: this.page,
        ps: this.pageSize,
      })
        .then((res) => {
          console.log(res);
          this.gridData = res.data;
          this.total = Number(res.page.totalRecords);
          this.girdloading = false;
        })
        .catch((err) => {});
    },
    display(val) {
      this.isShow = true;
      this.termid = val.id;
      this.getQueryList();
    },

    hide() {
      this.isShow = false;
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getQueryList();
    },
    //每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.getQueryList();
    },
  },
};
</script>
<style lang="less">
.cmdMsgDialog {
  display: flex;
  align-items: center;
  justify-items: center;
  justify-content: center;
  .el-dialog {
    width: 95%;
    height: 83%;
    margin-top: 0px !important;

    .el-dialog__body {
      padding: 12px;
      width: calc(100% - 24px);
      height: calc(100% - 78px);

      .cmdBoxMain {
        width: 100%;
        height: 100%;

        .el-table {
          .el-table__cell {
            text-align: center;
          }
          .msgClass {
            .cell {
              p {
                white-space: nowrap;
                text-overflow: ellipsis;
                overflow: hidden;
                cursor: default;
              }
            }
          }
        }
      }
      .pageNation {
        margin-top: 10px;
        display: flex;
        justify-content: flex-end;
      }
    }
  }
}
.msgTootip {
  color: #333;
  overflow: auto;
  height: 90%;
  p {
    font-size: 14px;
    line-height: 22px;
  }
}
</style>
