<template>
  <folder-page type="case" @click="folderHandleSelected" :style="{ height: '600px' }">
      <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
        <el-table-column type="selection"/>
        <el-table-column label="用例名称" align="center" prop="name"/>
        <el-table-column label="创建人" align="center" prop="createBy"/>
        <el-table-column label="用例状态" align="center" prop="status" :formatter="row => ['','草稿', '通过', '不通过'][row.status]"/>
        <el-table-column label="创建时间" align="center" prop="createTime"/>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
  </folder-page>
</template>

<script>
import FolderPage from "@/components/FolderPage/index.vue";
import {runCaseSync} from "@/api/test/case";
import {getRelateCaseList} from "@/api/test/planCase";

export default {
  name: "relateCase",
  components: {FolderPage},
  props: {
    form: {
      type: Object
    }
  },
  data() {
    return {
      loading: false,
      open: false,
      showSearch: true,
      total: 0,
      dataList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        groupId: null,
        planId: '',
        type: 0,
      },
      selectedRows: [], // 存储选中的行
      caseSID: null,
    }
  },
  methods: {
    getSelectedCaseIds() {
      // 返回选中的行的用例 id 数组
      return this.selectedRows.map(row => row.id);
    },
    handleSelectionChange(selection) {
      this.selectedRows = selection; // 更新选中的行
    },
    folderHandleSelected(id) {
      if (id) {
        this.queryParams.groupId = id;
        this.getList();
      } else {
        this.dataList = [];
      }
    },
    getList() {
      this.loading = true;
      this.queryParams.type = this.form.type;
      this.queryParams.planId = this.form.planId;
      getRelateCaseList(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-table__row {
  cursor: pointer;
}
</style>

