<template>
  <div class="mod-demo-echarts">
    <el-breadcrumb class="divi2" separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>可视化设计</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider class="divi"></el-divider>
    <div class="top-bar">
      <el-button type="primary" @click="addHandle()">新建实验</el-button>
      <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      <el-input
        v-model="workflowName"
        placeholder="请输入实验名称"
        clearable
        class="input"
        @keyup.enter.native="
          pageIndex = 1;
          getDataList();
        "
      ></el-input>
      <el-button
        @click="
          pageIndex = 1;
          getDataList();
        "
      >
        查询
      </el-button>
    </div>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column
        label="序号"
        header-align="center"
        align="center"
        width="80"
        type="index"
        :index="
          (index) => {
            return index + 1 + (this.pageIndex - 1) * this.pageSize;
          }
        "
      ></el-table-column>
      <el-table-column prop="experimentName" header-align="center" align="center" label="实验名称"></el-table-column>
      <el-table-column prop="workflowtempName" header-align="center" align="center" label="模板名称"></el-table-column>
      <el-table-column prop="workflowName" header-align="center" align="center" label="工作流名称"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">查看</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
import DesignGraph1 from "./design-graph1.vue";
import { MessageBox } from "element-ui";
export default {
  components: {
    // DesignGraph,
    DesignGraph1
  },
  data() {
    return {
      workflowName: "",
      username: this.$store.state.user.name,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    };
  },
  mounted() {
    this.getDataList();
  },
  methods: {
    addHandle() {
      this.$router.replace({
        path: "/design-create",
        query: {
          update: false
        }
      });
    },
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/visi/visiworkflow/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.workflowName
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(info) {
      this.$router.replace({
        path: "/design-create",
        query: {
          winfo: info,
          update: true
        }
      });
    },
    // 删除
    deleteHandle(info) {
      var ids = info.workflowId
        ? [info.workflowId]
        : this.dataListSelections.map((item) => {
            return item.workflowId;
          });
      var experimentName = info.experimentName
        ? [info.experimentName]
        : this.dataListSelections.map((item) => {
            return item.experimentName;
          });
      MessageBox.confirm(
        `确定对[实验=${experimentName.join(" , ")}]进行[${info.workflowId ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("/visi/visiworkflow/delete"),
          method: "post",
          data: this.$http.adornData(ids, false)
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    }
  }
};
</script>

<style lang="scss" scope>
.top-bar {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .input {
    width: 200px;
    margin: 0 20px;
  }
}
.mod-demo-echarts {
  > .el-alert {
    margin-bottom: 10px;
  }
  > .el-row {
    margin-top: -10px;
    margin-bottom: -10px;
    .el-col {
      padding-top: 10px;
      padding-bottom: 10px;
    }
  }
  .chart-box {
    min-height: 400px;
  }
}
.divi {
  display: block;
  height: 1px;
  width: 100%;
  margin: 24px 0;
  background-color: #dcdfe6;
  position: relative;
}
.divi2 {
  display: block;
  height: 1px;
  width: 100%;
  position: relative;
}
</style>
