<template>
  <div class="app-container algorithm">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="联系方式" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系方式" />
      </el-form-item >
      <el-form-item label="报警状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择报警状态">
          <el-option
            v-for="item in statusList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
             <el-date-picker clearable size="small"
               v-model="queryParams.startTime"
               type="date"
               value-format="yyyy-MM-dd"
               placeholder="请选择开始时间">
             </el-date-picker>
           </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
             <el-date-picker clearable size="small"
               v-model="queryParams.endTime"
               type="date"
               value-format="yyyy-MM-dd"
               placeholder="请选择结束时间">
             </el-date-picker>
           </el-form-item>
      <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
      </el-form-item>

      </el-form>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column label="报警方式" align="center" prop="method" />
      <el-table-column label="报警状态" align="center" prop="status">
        <template slot-scope="scope">
          <div :style="{'color':scope.row.status=='失败'? 'red':'green'}">
            {{scope.row.status}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="报警内容" align="center" prop="notice" width="500"/>
      <el-table-column label="拨打次数" align="center" prop="isBack" />
      <el-table-column label="回调时间" align="center" prop="updateTime" width="200"/>
      <el-table-column label="首次报警时间" align="center" prop="createTime" width="200"/>
    </el-table>

    <pagination :page-sizes="[20, 30, 40, 50]"
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="imgTitle" :visible.sync="imgOpen" width="800px" append-to-body>
      <div class="scrollbar-box" style="width:760px;max-height:700px;overflow-y: scroll;">
        <img :src="imgUrl" style="width:760px;">
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAlarmLog } from "@/api/laboratory/alarm";

export default {
  name: "Algorithm",
  data() {
    return {
      imgTitle:"",
      imgOpen:false,
      imgUrl:"",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      statusList: [
        {
          value: '成功',
          label: '成功'
        },
        {
          value: '失败',
          label: '失败'
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        phone: null,
        startTime: null,
        endTime: null,
        status: ''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询算法回调结果列表 */
    getList() {
      this.loading = true;
      listAlarmLog(this.queryParams).then( response => {
        this.dataList =  response.rows;
        this.total =  response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        algorithmType: null,
        algorithmResult: null,
        parseResult: null,
        parseResultMsg: null,
        signId: null,
        subId: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAlgorithm(id).then( response => {
        this.form =  response.data;
        this.open = true;
        this.title = "修改算法";
      });
    },



  }
};

</script>

<style scoped lang="scss">
  .algorithm {
    display: flex!important;
    flex-direction: column;
    box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
    padding:20px 20px 20px!important;
    .button-box{
      width:190px;
      display: flex;
      margin:0 auto;
    }
  }
</style>
