<!-- 用户管理 -->
<template>
  <div class="app-container">
    <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 shadow="never" class="table-container">      

      <el-table v-loading="loading" :data="tableData" stripe @selection-change="handleSelectionChange">
        <el-table-column label="模型名称" align="left" prop="name" />
        <el-table-column label="网络名称" align="left" prop="netName"  width="120"/>
        <el-table-column label="模型类型"  align="left" prop="modelType" />
        <el-table-column label="版本" align="left" prop="ver" />
        <el-table-column label="互联名称" align="left" prop="netName"  width="120"/>
        <el-table-column label="互联说明"  align="left" prop="desc" />
        <el-table-column label="互联创建时间" width="120" align="left" prop="upTime" />
        <el-table-column label="创建用户" width="100" align="left" prop="upUser" />        
        <el-table-column label="操作" fixed="right" align="center" width="270">
          <template #default="scope">            
            <el-button text type="primary" size="small"
              @click="doShowDetail(scope.row)"><i-ep-edit />查看模型</el-button>
            <el-button text type="primary" size="small"
              @click="doEdit(scope.row)"><i-ep-link/>编译部署</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 lang="ts">

import { UserQuery } from "@/api/user/model";

const queryFormRef = ref(ElForm); // 查询表单
const router = useRouter();

const loading = ref(false); //  加载状态
const removeIds = ref([]); // 删除用户ID集合 用于批量删除
const queryParams = reactive<UserQuery>({
  pageNum: 1,
  pageSize: 10,
});
const dateTimeRange = ref("");
const total = ref(100); // 数据总数

watch(dateTimeRange, (newVal) => {
  if (newVal) {
    queryParams.startTime = newVal[0];
    queryParams.endTime = newVal[1];
  }
});

const tableData = [
  {
    id:"1",
    name: "模型名称模型名称模型名称查看",    
    modelType: "图像分类",
    ver: "1.0",
    netName:'我的互联名称',
    desc:'进行10种类型 的目标分类模型查看',    
    upTime: "2024-02-02",
    upUser:'USER',
    state:'1'        
  },
  {
    id:"2",
    name: "模型名称模型名称模型名称查看",    
    modelType: "图像分类",
    ver: "1.0",
    netName:'我的互联名称',
    desc:'进行10种类型 的目标分类模型查看',
    upTime: "2024-02-02",
    upUser:'USER' ,
    state:'1'        
  },
  {
    id:"3",
    name: "模型名称模型名称模型名称查看",    
    modelType: "图像分类",
    ver: "1.0",
    netName:'我的互联名称',
    desc:'进行人员检测的模型',
    upTime: "2024-02-02",
    upUser:'USER' ,
    state:'1'        
  },
  {
    id:"4",
    name: "模型名称模型名称模型名称查看",    
    modelType: "图像分类",
    ver: "1.0",
    netName:'我的互联名称',
    desc:'进行10种类型 的目标分类模型查看',
    upTime: "2024-02-02",
    upUser:'USER' ,
    state:'0'        
  },
  {
    id:"5",
    name: "模型名称模型名称模型名称查看",    
    modelType: "图像分类",
    ver: "1.0",
    netName:'我的互联名称',
    desc:'进行人员检测的模型',
    upTime: "2024-02-02",
    upUser:'USER' ,
    state:'0'        
  }
];

/** 查询 */
function handleQuery() {
  loading.value = true;
  ElMessage.success("查询成功");
  loading.value = false;
  
}

function doUploadModel(){
  router.replace({ path: "/modelMgr/uploadModel" });
}

/** 重置查询 */
function resetQuery() {
  queryFormRef.value.resetFields();
  dateTimeRange.value = "";
  queryParams.pageNum = 1;
  queryParams.deptId = undefined;
  queryParams.startTime = undefined;
  queryParams.endTime = undefined;
  handleQuery();
}

/** 行选中 */
function handleSelectionChange(selection: any) {
  removeIds.value = selection.map((item: any) => item.id);
}

/** 删除数据 */
function handleDelete(row: { [key: string]: any }) {
  ElMessageBox.confirm("确认删除算子?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(function () {
    ElMessage.success("删除成功");
  });
}

const doShowDetail=(row:any)=>{
  router.replace({path:"/modelMgr/modelDetail",query:{id:row.id,from:'simulation'}})
}

const doEdit=(row:any)=>{
  router.replace({path:"/simulationEvaluation/compile",query:{id:row.id,type:'edit'}})
}

const doAdd=(row:any)=>{
  router.replace({path:"/connection/edit",query:{id:row.id,type:'add'}})
}


onMounted(() => {
  //handleQuery();
});
</script>


<style scoped lang='scss'>
.search-container{
  display:flex;
}
.card-footer{
  position: fixed;
  width: calc(100% - 215px);
  bottom: 0px;
  :deep(.el-card__body){
    padding:0px;
    .el-pagination{
      justify-content: end;
    }
  }
}
</style>

