<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          任务名称:
          <el-input
            v-model.trim="query.planName"
            placeholder=""
            style="width: 150px"
          ></el-input>
        </div>
        <div class="filter-item">
          任务团队:
          <el-input
            v-model.trim="query.planTeam"
            placeholder=""
            style="width: 150px"
          ></el-input>
        </div>

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

      <div class="handle-button-right">
        <el-button icon="el-icon-plus" type="success" @click="openAdd"
          >新增</el-button
        >
        <el-button icon="el-icon-delete" type="danger" @click="batchDelete"
          >删除</el-button
        >
        <el-button type="warning">
          <svg-icon icon-class="export" />
          导出
        </el-button>
      </div>
    </div>

    <el-divider></el-divider>
    <el-table
      :data="list"
      stripe
      border
      :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
      style="width: 100%"
      id="out-table"
    >
      <el-table-column type="selection" width="40"> </el-table-column>

      <el-table-column prop="planName" label="计划名称" width="130">
      </el-table-column>
      <el-table-column prop="planRoute" label="计划路线" width="100">
      </el-table-column>

      <el-table-column prop="planTeam" label="计划团队 "> </el-table-column>
      <el-table-column prop="planCycle" label="计划周期" width="150">
      </el-table-column>

      <el-table-column prop="planStartDate" label="计划开始日期 " width="130">
      </el-table-column>
      <el-table-column prop="planEndDate" label="计划结束日期" width="130">
      </el-table-column>
      <el-table-column prop="planStartTime" label="计划开始时间 " width="100">
      </el-table-column>

      <el-table-column prop="planEndTime" label="计划结束时间" width="130">
      </el-table-column>

      <el-table-column  label="状态 "> 
        <template slot-scope="scope">
        {{ scope.row.state == 1 ? '显示' : '不显示' }}
      </template>
      </el-table-column>
      <el-table-column prop="user" label="创建人 "> </el-table-column>
      <el-table-column label="创建时间" width="200">
        <template slot-scope="{ row }">
          <span>{{ renderTime(row.creationTime) }}</span>
        </template>
      </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
      @current-change="handleCurrentChange"
      :current-page="page.pageNo"
      :page-size="1"
      layout="prev, pager, next"
      :total="page.total"
    >
    </el-pagination>

    <edit
      :title="edit.title"
      :visible="edit.visible"
      :formData="edit.formData"
      :remoteClose="remoteClose"
    />
  </div>
</template>


<script>
import api from "@/api/partolplan";
import edit from "./edit";

const cityOptions = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];

export default {
  //组件注册
  components: {
    edit,
  },
  name: "partol-plan",
  data() {
    return {
      list: [], //列表数据
      page: {
        //分页对象
        pageNo: 1,
        pageSize: 3,
        total: 0,
      },
      query: {},// query: {"demo":1}, //查询条件


      edit: {
        title: "",
        visible: false,
        formData: {
          planCycle: [],
        },
      },

    };
  },

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

  methods: {

    //列表渲染
    fetchData() {
      api
        .getList(this.query, this.page.pageNo, this.page.pageSize)
        .then((response) => {
          console.log("response", response);
          // 列表数据
          this.list = response.pageList;
          this.page.total = response.totalPages;
        });
    },

    //打开新增窗口
    openAdd() {
      this.edit.visible = true;
      this.edit.title = "新增";
    },

    //关闭窗口 （子组件会触发此事件方法来关闭窗口）
    remoteClose() {
      console.log("============");
      console.log(this.edit.formData);
      this.edit.formData = {};
      this.edit.visible = false;
      this.fetchData();
    },

    

    //分页（当页码改变后触发到此方法  val是当前点击到的那个页码）
    handleCurrentChange(val) {
      this.page.pageNo = val;
      this.fetchData();
    },

    //筛选
    queryData() {
      this.page.pageNo = 1;      //将页码 变为1，第一页
      this.fetchData();
    },

    //修改
    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.fetchData();
        })
        .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);
            console.log("aa");
          }
        }
      }
    },


    //时间格式化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>