<template>
  <div class="app-container">
    <el-form :model="query" ref="query" :inline="true"  >
      <el-form-item label="路线名称:" >
          <el-input
            v-model="query.lName"
            placeholder="请输入路线名称"
            style="width: 160px"
            clearable
          ></el-input>
       </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
      border
      id="out-table"
      @selection-change="handleSelectionChange"
      style="margin-top:20px"
    >
      <el-table-column prop="placeId" label="巡检点ID" show-overflow-tooltip></el-table-column>
      <el-table-column prop="placeName" label="巡检点名称" show-overflow-tooltip></el-table-column>
      <el-table-column prop="lname" label="路线名称" show-overflow-tooltip></el-table-column>
      <el-table-column prop="lnextplacetime" label="到达下一个点时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="lorder" label="巡检顺序" show-overflow-tooltip></el-table-column>
      <el-table-column prop="lstayTime" 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/patrol-route";

export default {
  //组件注册
  components: {

  },
  name: "elect-partol",

  data() {
    return {
      multipleSelection: [],
      loading:true,
      //初始化列表
      cols: [],
      //列表数据
      tableData: [],
      //列表总数
      totalCount: 0,
      //列表每页条目数
      pageSize: 15,
      //开始页
      pageNo: 1,
      //input搜索
      lName_value:'',
      query:{
        lName: undefined,
        pageNo: 1,
        pageSize: 15,
      },
      form:{
         //列表每页条目数
        pageSize: 15,
        //开始页
        pageNo: 1,
      },
    };
  },
  mounted(){
    this.getData();
  },
  created() {
    this.getData();
  },

  methods: {
    /** 重置按钮操作 */
    resetQuery() {
      this.query = {
        lName: undefined,
        pageNo: 1,
        pageSize: 15,
      },
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getData();
    },
    //列表查询
    getData(data) {
      if(data){
        api.queryPatrollingLine(this.query).then((Response)=>{
          let data = Response.data.pageList
          for(let i =0;i<data.length;i++){
            for(let a=0;a<data[i].ptPointVoEntities.length;a++){
              if(data[i].placeName){
                data[i].placeName = data[i].placeName +'、' + data[i].ptPointVoEntities[a].ptName
              }else{
                data[i].placeName = data[i].ptPointVoEntities[a].ptName
              }
            }
          }
          this.tableData = data
          this.totalCount = Response.data.totalCount
          this.loading = false
        })
      }else{
        api.queryPatrollingLine(this.query).then((Response)=>{
          let data = Response.data.pageList
          for(let i =0;i<data.length;i++){
           for(let a=0;a<data[i].ptPointVoEntities.length;a++){
              if(data[i].placeName){
                data[i].placeName = data[i].placeName +'、' + data[i].ptPointVoEntities[a].ptName
              }else{
                data[i].placeName = data[i].ptPointVoEntities[a].ptName
              }
            }
          }
          this.tableData = data
          this.totalCount = Response.data.totalCount
          this.loading = false
        })
      }

    },
    //改变起始页
    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(() => {
          // 发送删除请求

          // 刷新列表数据
          this.fetchData();
        })
        .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];
          }
        })
      );
    },

    //时间格式化2021-01-21T05:53:00.000+0000
    renderTime(date) {
      var dateee = new Date(date).toJSON();
      return new Date(+new Date(dateee) + 8 * 3600 * 1000)
        .toISOString()
        .replace(/T/g, " ")
        .replace(/\.[\d]{3}Z/, "");
    },
  },
};
</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;
}
.search-button{
  vertical-align: top;
}
</style>

