<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>
    <!-- <design-graph></design-graph> -->
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-button type="primary" @click="addHandle()">新建实验</el-button>
        <el-button
          type="danger"
          @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button
        >
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="dataForm.workflowName"
          placeholder="请输入实验名称"
          clearable
          @keyup.enter.native="
            pageIndex = 1;
            getDataList();
          "
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          @click="
            pageIndex = 1;
            getDataList();
          "
          >查询</el-button
        >
      </el-form-item>

    </el-form>

    <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 prop="datasetId" header-align="center" align="center" width="80" label="数据集ID">-->
      <!--      </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="username"
        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 { info } from '../../../mock/modules/sys-menu';
// import DesignGraph from "./design-graph.vue"
import DesignGraph1 from "./design-graph1.vue";
import { Message } from "element-ui";
import { MessageBox } from "element-ui";
export default {
  components: {
    // DesignGraph,
    DesignGraph1,
  },
  data() {
    return {
      dataForm: {
        key: "",
      },
      username: this.$store.state.user.name,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
    };
  },
  mounted() {},
  activated() {
    // if (location.href.indexOf("#reloaded") == -1) {
    //   location.href = location.href + "#reloaded";
    //   location.reload();
    // }
    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.dataForm.key,
        }),
      }).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;
      });
    },
    // 筛选查询
    getDataList2 () {
      this.dataListLoading = true

      if (this.status === '1') {
        // 获取静态数据集
        this.st_dataList = []
        this.$http({
          url: this.$http.adornUrl('/dataset/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: this.pageIndex,
            limit: this.pageSize,
            modelName: this.dataForm.modelName,
            // 增加status参数用于筛选查询
            classificationtag: this.classificationtag,
            status: this.status
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.st_dataList = data.page.list.reverse()
            this.totalPage = data.page.totalCount
          } else {
            this.st_dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      } else {
        this.dy_dataList = []
        // 获取动态数据集
        this.$http({
          url: this.$http.adornUrl('/datasetdy/list'),
          method: 'get',
          params: this.$http.adornParams({
            page: this.pageIndex,
            limit: this.pageSize,
            modelName: this.dataForm.modelName,
            // 增加status参数用于筛选查询
            classificationtag: this.classificationtag,
            status: this.status
          })
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dy_dataList = data.page.list.reverse()
            this.totalPage = data.page.totalCount
          } else {
            this.dy_dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
        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.addOrUpdateVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.addOrUpdate.init(info);
      // });

      this.$router.replace({ path: '/design-create' ,query: {
                winfo: info,update: true
              },})
    },
    // // 删除
    // deleteHandle (info) {
    //   var datasetId = info.datasetId
    //     ? [info.datasetId] : this.dataListSelections.map((item) => {
    //       return item.datasetId
    //     })
    //   var datasetName = info.datasetName ? [info.datasetName] : this.dataListSelections.map(item => {
    //     return item.datasetName
    //   })

    //   MessageBox.confirm(
    //     `确定对[数据集=${datasetName.join(' , ')}]进行[${info.datasetId ? '删除' : '批量删除'}]操作?`,
    //     '提示',
    //     {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     }
    //   )
    //     .then(() => {
    //       this.dataListLoading = true
    //       this.$http({
    //         url: this.$http.adornUrl('/dataset/delete'),
    //         method: 'post',
    //         data: this.$http.adornData(datasetId, false)
    //       }).then(({ data }) => {
    //         if (data && data.code === 0) {
    //           this.dataListLoading = false
    //           Message({
    //             message: '操作成功',
    //             type: 'success',
    //             duration: 1500,
    //             onClose: () => {
    //               this.getDataList()
    //             }
    //           })
    //           this.pageIndex = 1
    //         } else {
    //           Message.error(data.msg)
    //         }
    //       })
    //     })
    //     .catch(() => {})
    // },
    // 删除
    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">
.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>

