<template>
  <div class="app-container">
    <el-form :model="query" ref="query" :inline="true"  >
      <el-form-item label="计划模式:" >
        <el-select
          v-model="pMode_value"
          placeholder="请选择计划模式"
          @change="select"
          style="width: 150px"
          clearable
        >
          <el-option
            v-for="(item, index) in pMode_list"
            :key="index"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </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"
      style="margin-top:20px"
    >
      <el-table-column prop="lineId" label="巡更线路id" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pCreateTime" label="计划创建时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pEndTime" label="计划结束时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pExcCycle" label="执行周期天数" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pExcWeek" label="执行星期" show-overflow-tooltip></el-table-column>
      <el-table-column prop="planId" label="巡更计划id" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pMode" label="计划模式" show-overflow-tooltip>
        <template  slot-scope="scope">
            {{scope.row.pMode == "0" ? "常规" : scope.row.pMode == "1" ? "班组" : scope.row.pMode == "2" ? "星期" : scope.row.pMode == "3" ? "周期" : ""}}
        </template>
      </el-table-column>
      <el-table-column prop="pRestCycle" label="休息周期天数" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pStartDate" label="周期开始日期" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pStartTime" label="计划开始时间" show-overflow-tooltip></el-table-column>
      <el-table-column prop="pType" 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>
import api from "@/api/patrol/partol-plan";

export default {
  //组件注册
  components: {},
  name: "partol-plan",
  data() {
    return {
      loading:true,
      //初始化列表
      cols: [],
      //列表数据
      tableData: [],
      //列表总数
      totalCount: 0,
      //列表每页条目数
      pageSize: 15,
      //开始页
      pageNo: 1,
      //input计划模式
      pMode_value: undefined,
      //select计划模式
      pMode_list: [
        {
          label: "全部",
          value: "",
        },
        {
          label: "常规",
          value: "0",
        },
        {
          label: "班组",
          value: "1",
        },
        {
          label: "星期",
          value: "2",
        },
        {
          label: "周期",
          value: "3",
        },
      ],
      query:{
        pMode: undefined,
        pageNo: 1,
        pageSize: 15,
      },
      form:{
         //列表每页条目数
        pageSize: 15,
        //开始页
        pageNo: 1,
      },
      //表格自适应高度
    };
  },
  mounted(){

    this.getData();
  },
  created() {
    this.getData();
  },

  methods: {
      /** 重置按钮操作 */
      resetQuery() {
        this.pMode_value = undefined
        this.query = {
          pMode: undefined,
          pageNo: 1,
          pageSize: 15,
        },
        this.handleQuery();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getData();
      },
    //下拉筛选
    select(value){
      this.query.pMode = value
    },
    //列表渲染
    getData(data) {
      if(data){
        api.queryPatrollingPlan(this.query).then((Response) => {
          this.tableData = Response.data.pageList;
          this.totalCount = Response.data.totalCount;
          this.loading = false
        });
      }else{
        api.queryPatrollingPlan(this.form).then((Response) => {
          this.tableData = Response.data.pageList;
          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) {
      this.edit.visible = true;
      this.edit.title = "修改";
      row.planCycle = row.planCycle ? row.planCycle.split(",") : [];
      this.edit.formData = row;
      // alert(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.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);
          }
        }
      }
    },
    //时间格式化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;
}
</style>
<style >
</style>
