<template>
  <div class="app-container">
    <el-form :model="query" ref="query" :inline="true"  >
       <!-- <el-form-item label="实际班组:" >
          <el-input
            v-model="query.eTeamName"
            placeholder="请输入实际班组"
            clearable
          ></el-input>
        </el-form-item>
         <el-form-item label="实际巡更人:" >
          <el-input
            v-model="query.UserName"
            placeholder="请输入实际巡更人"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item label="线路名称:" >
          <el-input
            v-model="query.elname"
            placeholder="请输入线路名称"
            clearable
          ></el-input>
        </el-form-item>
         <el-form-item label="时间:" >
          <el-date-picker style="width:300px"
            v-model="dateRange"
            size="small"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
      </el-form-item>
        <el-form-item class="right" >
          <el-button  plain size="mini" @click="resetQuery">重置</el-button>
          <el-button
            type="primary"
            size="mini"
            @click="getData('query')"
          >搜索</el-button
        >
        </el-form-item>
      </el-form>
    <!-- <el-divider></el-divider> -->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      id="out-table"
      @selection-change="handleSelectionChange"
      border
      style="margin-top:20px"
    >
      <!-- <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>
        <template  slot-scope="scope">
            {{scope.row.edflag == "0" ? "否" : scope.row.edflag == "1" ? "是" :  ""}}
        </template>
      </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>

    <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,
        startTime:undefined,
        endTime:undefined,
      },
      form:{
         //列表每页条目数
        pageSize: 15,
        //开始页
        pageNo: 1,
      },
      // 日期范围
      dateRange: [],
    };
  },
  mounted(){

    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(this.dateRange.length>0){
        this.query.startTime = this.dateRange[0]
        this.query.endTime = this.dateRange[1]
      }
      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>
