<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          实际班组:
          <el-input
            v-model="query.eTeamName"
            placeholder="请输入实际班组"
            style="width: 150px"
            clearable
          ></el-input>
        </div>
        <div class="filter-item">
          实际巡更人:
          <el-input
            v-model="query.UserName"
            placeholder="请输入实际巡更人"
            style="width: 150px"
            clearable
          ></el-input>
        </div>
        <div class="filter-item">
          线路名称:
          <el-input
            v-model="query.eLName"
            placeholder="请输入线路名称"
            style="width: 150px"
            clearable
          ></el-input>
        </div>

        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getData('query')"
          >搜索</el-button
        >
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </div>
    </div>
    <!-- <el-divider></el-divider> -->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      style="width: 100%; margin-bottom: 5rem;margin-top:10px"
      id="out-table"
      @selection-change="handleSelectionChange"
      :max-height="tableHeight"
    >
      <el-table-column prop="eBindDevice" label="巡更设备" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eBindTeam" label="绑定班组" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eBindUser" label="计划巡更人" width="100" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eCreateTime" label="实际实施创建时间" width="130" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eDeviceName" label="实际巡检设备" width="120" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eDFlag" label="是否报警" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eEndTime" label="结束时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eErrorTime" label="误差时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eLineOrder" label="线路顺序" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eLName" label="线路名称" show-overflow-tooltip></el-table-column>
      <el-table-column prop="ePatrolTime" label="巡更时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="ePlaceName" label="巡更地点" show-overflow-tooltip></el-table-column>
      <el-table-column prop="ePlanMode" label="计划模式" show-overflow-tooltip>
        <template  slot-scope="scope">
            {{scope.row.ePlanMode == "0" ? "常规" : scope.row.ePlanMode == "1" ? "班组" : scope.row.ePlanMode == "2" ? "星期" : scope.row.ePlanMode == "3" ? "周期" : ""}}
        </template>
      </el-table-column>
      <el-table-column prop="ePlanState" label="巡更状态" show-overflow-tooltip></el-table-column>
      <el-table-column prop="ePlanType" label="计划类型" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eStartTime" label="开始时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eStayTime" label="停留时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eTeamName" label="实际班组" show-overflow-tooltip></el-table-column>
      <el-table-column prop="eUserName" label="实际巡更人" width="100" show-overflow-tooltip></el-table-column>
    </el-table>

    <el-pagination
      background
      @current-change="handleCurrentChange"
      :page-sizes="[10, 15, 20, 30]"
      @size-change="handleSizeChange"
      :current-page="pageNo"
      :page-size="pageSize"
      layout="sizes,prev, pager, next"
      :total="totalCount"
    >
    </el-pagination>
  </div>
</template>


<script>
//引入api文件
import api from "@/api/patrol/elect-partol";

export default {
  //组件注册
  components: {},
  name: "elect-partol",

  data() {
    return {
      loading:true,
      //初始化列表
      cols: [],
      //列表数据
      tableData: [],
      //列表总数
      totalCount: 0,
      //列表每页条目数
      pageSize: 15,
      //开始页
      pageNo: 1,
      //input实际巡更人
      eBindUser_value: "",
      //input线路名称
      eLName_value: "",
      //input计划完成状态
      ePlanState_value: "",
      query:{
        eTeamName:undefined,
        UserName: undefined,
        eLName: undefined,
        pageNo: 1,
        pageSize: 15,
      },
      form:{
         //列表每页条目数
        pageSize: 15,
        //开始页
        pageNo: 1,
      },
      //表格自适应高度
      tableHeight:undefined,
    };
  },
  mounted(){
    // table高度
    if(window.innerWidth <1920){
      this.tableHeight = window.innerHeight - 300
    }else{
      this.tableHeight = window.innerHeight - 295
    }
    // 监听窗口大小变化
    let self = this;
    window.onresize = function() {
      self.tableHeight = window.innerHeight - 300
    }
    this.getData();
  },
  created() {
    this.getData();
  },

  methods: {
    /** 重置按钮操作 */
    resetQuery() {
      this.query = {
        eTeamName:undefined,
        UserName: undefined,
        eLName: undefined,
        pageNo: 1,
        pageSize: 15,
      },
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getData();
    },
    //列表查询
    getData(data) {
      if(data){
        api.queryPatrollingPlanStatus(this.query).then((Response) => {
          this.tableData = Response.data.pageList;
          this.totalCount = Response.data.totalCount;
          this.loading = false
          if(this.tableData.length<1){
            setTimeout(() =>{
              document.getElementsByClassName("el-table__empty-text")[0].innerHTML = "您查询的巡更计划不存在"
            },10)
          }
        });
      }else{
        api.queryPatrollingPlanStatus(this.form).then((Response) => {
          this.tableData = Response.data.pageList;
          this.totalCount = Response.data.totalCount;
          this.loading = false
          if(this.tableData.length<1){
            setTimeout(() =>{
              document.getElementsByClassName("el-table__empty-text")[0].innerHTML = "您查询的巡更计划不存在"
            },10)
          }
        });
      }

    },
    //改变起始页
    handleCurrentChange(val) {
      this.pageNo = val;
      this.query.pageNo = this.pageNo
      this.getData('query');
    },
    //改变每条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.query.pageSize = this.pageSize
      this.getData('query');
    },

    //修改
    handleEdit(index, row) {},

    //删除
    handleDelete(id) {
      this.$confirm("确定删除该数据吗?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 发送删除请求
          api.deleteById({ queryJson: id }).then((response) => {
            // 处理响应结果提示
            this.$message({
              type: response.success ? "success" : "error",
              message: response.Msg,
            });
          });
          // 刷新列表数据
          this.select();
        })
        .catch(() => {
          // 不用理会
        });
    },

    //全部删除
    batchDelete() {
      let multData = this.multipleSelection;
      let tableData = this.list;
      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.list.splice(y, 1);
          }
        }
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    //导出功能
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = [
          "巡更计划名称",
          "设备名称",
          "执行开始日期",
          "执行结束日期",
          "巡更开始时间",
          "巡更结束时间",
          "巡更周期",
          "添加时间",
        ];
        const filterVal = [
          "deviceName",
          "patrolPlanName",
          "startDate",
          "endDate",
          "startTime",
          "endTime",
          "patrolPlanCycle",
          "creationTime",
        ];
        const data = this.formatJson(filterVal);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "table-list",
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal) {
      return this.list.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
  },
};
</script>
<style scoped>
.table-tit {
  background: rgb(235, 241, 255);
  border: 1px solid #d9d9d9;
  border-bottom: 0;
  font-weight: bold;
  padding: 8px 10px;
}
.el-checkbox {
  margin-right: 15px;
  line-height: 0;
}
.el-dialog {
  min-width: 736px !important;
}
</style>
<style >
</style>
