<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="StaterLogList" @selection-change="handleSelectionChange">
      <el-table-column prop="state" label="运行状态" align="left" width="100px;">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.camera_offline_reason" :value="scope.row.state"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="left" prop="createTime" width="150px;"/>
      <el-table-column label="上报报文" align="left" prop="reportText">
        <template slot-scope="scope">
          <json-viewer :value="JSON.parse(scope.row.reportText)" :expand-depth="1" :boxed="true"></json-viewer>
        </template>
      </el-table-column>
    </el-table>

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

  </div>
</template>

<script>
import { listStateLog } from '@/api/centerMonitor/camera/camera'
import JsonViewer from 'vue-json-viewer';

export default {
  name: 'StaterLog',
  dicts:['camera_offline_reason'],
  components:{
      JsonViewer
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      StaterLogList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportText: null,
        state: null,
        createTime: null,
        id: null,
        cameraId: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
  },
  props: {
    sonId: '',
  },
  methods: {
    /** 查询监测设备列表 */
    getList() {
      this.loading = true
      this.queryParams.cameraId = this.sonId;
      listStateLog(this.queryParams).then(response => {
        this.StaterLogList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false,
        this.openSee = false;
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        createTime: null,
        state: null,
        reportText: null,
      };
      this.resetForm("form");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  },
};
</script>
