<!--告警记录-->
<template>
  <div class="app-container warningLog">
    <div class="page-container warningLogPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="请输入标题/内容"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="alarmType">
            <el-select v-model="queryParams.alarmType" clearable placeholder="请选择方式" style="width: 200px">
              <el-option
                v-for="dict in typeList"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-select v-model="queryParams.state" clearable placeholder="请选择状态" style="width: 200px">
              <el-option
                v-for="dict in options"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="dateRange">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="告警时间"
              end-placeholder="告警时间"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="标题" prop="title" width="140" show-overflow-tooltip/>
          <el-table-column label="消息内容" prop="content" show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="clickCopy" @click="clickCopy(scope.row.content,'内容-')">{{scope.row.content}}</span>
            </template>
          </el-table-column>
          <el-table-column label="方式" prop="alarmType" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-for="(item,index) in typeList" :key="index" v-show="scope.row.alarmType == item.id">{{item.name}}</span>
            </template>
          </el-table-column>
          <el-table-column label="接收人" prop="receiver" width="400" show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="clickCopy" @click="clickCopy(scope.row.receiver,'接收人-')">{{scope.row.receiver}}</span>
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="alarmType" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.state?'成功':'失败'}}</span>
              <span v-if="!scope.row.state" @click="lockInfo(scope.row.failDesc)"
                    style="margin-left:20px;cursor: pointer;font-size:18px;color:#FFA312;"
                    class="el-icon-s-opportunity"></span>
            </template>
          </el-table-column>
          <el-table-column label="时间" prop="createTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <public-log-dialog ref="publicLogDialog"></public-log-dialog>
  </div>
</template>

<script>
  import { iotAlarmLogList } from "@/api/iotDevice/index";
  import publicLogDialog from '@/components/publicLogDialog/publicLogDialog.vue'
  export default {
    name: 'index',
    components: {
      publicLogDialog
    },
    data(){
      return{
        loading:false,
        options:[{label:'成功',value:true},{label:'失败',value:false}],
        typeList:[
          {name:"钉钉",id:1,},
          {name:"微信",id:2,},
          {name:"邮件",id:3,},
          {name:"电话",id:4,},
          {name:"短信",id:5,},
        ],
        dateRange:[],
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
          alarmType:null,
          state:null,
        },
        dataList:[],
        total:0,
      }
    },
    created(){

    },
    mounted(){
      this.getList();
    },
    methods:{
      //弹层开启
      lockInfo(response){
        this.$refs.publicLogDialog.publicLogDialogOpen(response);
      },
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
          alarmType:null,
          state:null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        iotAlarmLogList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
    },
  }
</script>

<style scoped lang="scss">
  .warningLog{
    flex:1;
    display: flex;
    flex-direction: column;
    .title-box{
      padding-top:20px;
      border-bottom:1px solid #dedede;
      display: flex;
    }
    .content-box{
      flex: 1;
      display: flex;
      flex-direction: column;
      padding:20px;
      overflow: hidden;
    }
  }
</style>
