<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          时间:
          <el-date-picker
            style="width:43%"
            v-model="formDaliog.startTime"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions1"
          >
          </el-date-picker>
          ~
          <el-date-picker
            style="width:43%"
            v-model="formDaliog.endTime"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions2"
          >
          </el-date-picker>
        </div>

        <div class="filter-item">
          处理状态:
          <el-select v-model="value" placeholder="" style="width: 110px">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <el-button type="primary" icon="el-icon-search" class="search-button"
          >搜索</el-button
        >
      </div>
    </div>

    <el-divider></el-divider>
    <el-table
      :data="tableData"
      stripe
      border
      :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
      style="width: 100%"
      id="out-table"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40"> </el-table-column>

      <el-table-column prop="time" label="报告时间" width="200">
      </el-table-column>
      <el-table-column prop="reportData" label="报告数据"> </el-table-column>
      <el-table-column prop="reportContent" label="报告内容" width="300">
      </el-table-column>
      <el-table-column  label="处理状态"> 
         <template slot-scope="{row}" >
            <div :class="row.status == '已处理' ? 'handled':'unhandle'">{{ row.status }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="handler" label="处理人"> </el-table-column>
      <el-table-column prop="handleTime" label="处理时间" width="200">
      </el-table-column>

      <el-table-column label="操作" width="80" fixed="right">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            style="color: #406ce5"
            @click="dialogFormVisible = true"
            >处置</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="处置" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="监控设备:" :label-width="formLabelWidth">
          <el-input
            v-model="form.name"
            autocomplete="off"
            placeholder="重传装置"
          ></el-input>
        </el-form-item>

        <el-form-item label="报告信息:" :label-width="formLabelWidth">
          <el-input
            v-model="form.name2"
            autocomplete="off"
            placeholder="入侵报告"
          ></el-input>
        </el-form-item>

        <el-form-item label="误报:" :label-width="formLabelWidth">
          <el-radio v-model="radio" label="1">是</el-radio>
          <el-radio v-model="radio" label="2">否</el-radio>
        </el-form-item>
        <el-form-item label="处理范围:" :label-width="formLabelWidth">
          <el-radio v-model="radio2" label="1">批量</el-radio>
          <el-radio v-model="radio2" label="2">单一</el-radio>
        </el-form-item>

        <el-form-item label="处理内容:" :label-width="formLabelWidth">
          <el-input v-model="form.name3" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogFormVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogFormVisible = false"
          >处 理</el-button
        >
      </div>
    </el-dialog>

    <el-pagination background layout="prev, pager, next" :total="1000">
    </el-pagination>
  </div>
</template>


<script>
// 引入导出Excel表格依赖
import FileSaver from "file-saver";
import XLSX from "xlsx";

export default {
  name: "javascriptthree",
  data() {
    return {
      tableData: [
        {
          time: "2020-09-14 12:15:23",
          reportData: "入侵报警",
          reportContent: "视频告警检测#2，开关量，端口号：104",
          status: "未处理",
          handler: "",
          handleTime: "",
        },
        {
          time: "2020-09-14 12:15:23",
          reportData: "占道检测报告",
          reportContent: "视频告警检测#2，开关量，端口号：104",
          status: "已处理",
          handler: "张三",
          handleTime: "2020-09-14 12:15:23",
        },
        {
          time: "2020-09-14 12:15:23",
          reportData: "占道检测报告",
          reportContent: "视频告警检测#2，开关量，端口号：104",
          status: "已处理",
          handler: "张三",
          handleTime: "2020-09-14 12:15:23",
        },
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "状态1",
        },
        {
          value: "2",
          label: "状态2",
        },
        {
          value: "3",
          label: "状态3",
        },
      ],
      value: "",

      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        region2: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",

      //日期时间选择器
      formDaliog: {
        startTime: "",
        endTime: "",
      },
      pickerOptions1: {
        disabledDate: (time) => {
          if (this.formDaliog.endTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() > new Date(this.formDaliog.endTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      pickerOptions2: {
        disabledDate: (time) => {
          if (this.formDaliog.startTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() < new Date(this.formDaliog.startTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },

      //单选
      radio: "1",
      radio2: "1",


    };
  },
  methods: {
    //定义导出Excel表格事件
    exportExcel() {
      /* 从表生成工作簿对象 */
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* 获取二进制字符串作为输出 */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        FileSaver.saveAs(
          //Blob 对象表示一个不可变、原始数据的类文件对象。
          //Blob 表示的不一定是JavaScript原生格式的数据。
          //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
          //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
          new Blob([wbout], { type: "application/octet-stream" }),
          //设置导出文件名称
          "sheetjs.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    handleEdit(index, row) {
      alert(index, row);
    },
    handleDelete(index, row) {
      this.$confirm("确定删除该单位吗?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.tableData.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    batchDelete() {
      let multData = this.multipleSelection;
      let tableData = this.tableData;
      let multDataLen = multData.length;
      let tableDataLen = tableData.length;

      for (let i = 0; i < multDataLen; i++) {
        for (let y = 0; y < tableDataLen; y++) {
          if (JSON.stringify(tableData[y]) == JSON.stringify(multData[i])) {
            //判断是否相等，相等就删除
            this.tableData.splice(y, 1);
            console.log("aa");
          }
        }
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
  filters:{
     statusFilter(status) {
      const statusMap = {
        已处理: 'success',
        未处理: 'info',
      }
      return statusMap[status]
    }
  }
};
</script>
<style>
.el-radio {
  width: 70px;
}
.handled{
  color:#8DCF6E
}
.unhandle{
  color:#FE5D0E
}
</style>