<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          操作人：
          <el-input
            v-model="input"
            placeholder=""
            style="width: 150px"
          ></el-input>
        </div>
        <div class="filter-item" style="width:500px">
          操作时间:
          <el-date-picker
            style="width: 40%"
            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: 40%"
            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>

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

      <div class="handle-button-right">
        <el-button type="warning">
          <svg-icon icon-class="export" />
          导出
        </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="orderNo" label="序号" width="50">
      </el-table-column>
      <el-table-column prop="operator" label="操作人员"> </el-table-column>
      <el-table-column prop="opTime" label="操作时间" width="200">
      </el-table-column>
      <el-table-column prop="opContent" label="操作内容"> </el-table-column>
      <el-table-column prop="executionTime" label="执行时间"> </el-table-column>

      <el-table-column prop="ip" label="请求ip" width="200"> </el-table-column>

      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            style="color: #406CE5"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-delete"
            style="color: #F27979"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <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: [
        {
          orderNo: "1",
          operator: "admin",
          opTime: "2020-09-14 12:15:23",
          opContent: "楼层查询",
          executionTime: "1031",
          ip: "192.1.5.6",
        },
        {
          orderNo: "1",
          operator: "admin",
          opTime: "2020-09-14 12:15:23",
          opContent: "楼层查询",
          executionTime: "1031",
          ip: "192.1.5.6",
        },
        {
          orderNo: "1",
          operator: "admin",
          opTime: "2020-09-14 12:15:23",
          opContent: "楼层查询",
          executionTime: "1031",
          ip: "192.1.5.6",
        },
        {
          orderNo: "1",
          operator: "admin",
          opTime: "2020-09-14 12:15:23",
          opContent: "楼层查询",
          executionTime: "1031",
          ip: "192.1.5.6",
        },
        {
          orderNo: "1",
          operator: "admin",
          opTime: "2020-09-14 12:15:23",
          opContent: "楼层查询",
          executionTime: "1031",
          ip: "192.1.5.6",
        },
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "操作人1",
        },
        {
          value: "2",
          label: "操作人2",
        },
        {
          value: "3",
          label: "操作人3",
        },
      ],
      value: "",
      input:"",

      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;
          }
        },
      },
    };
  },
  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;
    },
  },
};
</script>