<template>
  <div class="app-container simulation-his-task-list">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true" style="flex-grow: 1;text-align: right;">
        <el-form-item label="" prop="keywords">
          <el-input v-model="queryParams.keywords" placeholder="请输入模型名称" clearable style="width: 250px"
            @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery"><i-ep-search />搜索</el-button>
          <el-button @click="resetQuery">
            <i-ep-refresh />
            重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-card>
      <el-table v-loading="loading" :data="info.tableData" stripe @selection-change="handleSelectionChange">
        <el-table-column label="任务名称" align="left" prop="task_name" />
        <el-table-column label="任务说明" align="left" prop="task_desc" />
        <el-table-column label="使用数据集" align="left" prop="data_set_name" />
        <el-table-column label="运行模型" align="left" prop="model_name" width="120" />
        <el-table-column label="模型网络" align="left" prop="modl_net_type" width="120" />
        <el-table-column label="创建时间" align="left" prop="crTime" width="120" />
        <el-table-column label="操作" fixed="right" align="center" width="200">
          <template #default="scope">
            <el-button text type="primary" size="small" @click="doShowDetail(scope.row)"><i-ep-view />查看报告</el-button>
            <el-button text type="primary" v-if="1 == 2" size="small"
              @click="doDelete(scope.row)"><i-ep-close-bold />删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="card-footer">
      <pagination v-if="total > 0" v-model:total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="handleQuery" />
    </el-card>

  </div>
</template>

<script setup>
import TaskApi from '@/api/task'
const queryFormRef = ref(ElForm); // 查询表单
const router = useRouter();
const loading = ref(false); //  加载状态
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  keywords: '',
});
const total = ref(0); // 数据总数
let info = reactive({
  tableData: []
})
/** 查询 */
function handleQuery() {
  loadData();
}


const doDelete = (row) => {
  ElMessageBox.confirm("确认删除?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(function () {

    let idx = tableData.indexOf(row);
    if (idx >= 0) {
      tableData.splice(idx, 1);
      ElMessage.success("删除成功");
    }

  });
}
const doShowDetail = row => {
  router.push({ path: "/simulationEvaluation/taskDesc", query: { ...row } });
}
const loadData = () => {
  loading.value = true;
  TaskApi.tasks(queryParams).then(d => {
    loading.value = false;
    total.value = d.data.data.total || 0;
    info.tableData = (d.data.data.task_list || []).map(it => {
      it.device_name = (it.device_list || []).map(item => item.device_name).join(",");
      return it;
    })
  })
}

onMounted(loadData);
</script>
<style lang='scss'>
.simulation-his-task-list {
  .card-footer {
    position: fixed;
    width: calc(100% - 215px);
    bottom: 0px;

    .el-card__body {
      padding: 0px;

      .el-pagination {
        justify-content: end;
      }
    }
  }
}
</style>