<!-- 用户管理 -->
<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true">
        <el-form-item label="参数名称" prop="keywords">
          <el-input
            v-model="queryParams.keywords"
            placeholder="请输入算子参数名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="主类型" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="全部类型"
            clearable
            style="width: 200px"
          >
            <el-option label="前置算子" value="1" />
            <el-option label="后置算子" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="子类型" prop="statusv">
          <el-select
            v-model="queryParams.statusv"
            placeholder="全部类型"
            clearable
            style="width: 200px"
          >
            <el-option label="图像分类" value="1" />
            <el-option label="格式转换" value="2" />
            <el-option label="人脸识别" value="3" />
            <el-option label="图像缩放" value="4" />
          </el-select>
        </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">
      <template #header>
        <div class="flex justify-between">
          <div>
            <el-button type="success" @click="openDialog('user-form')"
              ><i-ep-plus />添加算子参数</el-button
            >
          </div>
          <!-- <div>
            <el-dropdown split-button>
              导入
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="downloadTemplate">
                    <i-ep-download />下载模板</el-dropdown-item
                  >
                  <el-dropdown-item @click="openDialog('user-import')">
                    <i-ep-top />导入数据</el-dropdown-item
                  >
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            <el-button class="ml-3" @click="handleExport"
              ><template #icon><i-ep-download /></template>导出</el-button
            >
          </div> -->
        </div>
      </template>
      <el-table
        v-loading="loading"
        :data="tableData"
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="算子参数名称" align="left" prop="szmc" width="250" />
        <el-table-column label="算子主类型" align="left" prop="szlx" />
        <el-table-column label="算子子类型" align="left" prop="szzlx" />
        <el-table-column label="参数描述" width="180" align="left" prop="bb" />
        <el-table-column label="互联时间" width="180" align="left" prop="hlcjsj" />
        <el-table-column label="操作" fixed="right" width="220">
          <template #default="scope">
            <el-button
              type="warning"
              size="small"
              @click="openDialog('user-form', scope.row.id)"
              ><i-ep-edit />查看参数</el-button
            >
            <el-button type="danger" size="small" @click="handleDelete(scope.row)"
              ><i-ep-delete />删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <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">
defineOptions({
  name: "calculateIndex",
  inheritAttrs: false,
});

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(0); // 数据总数

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

const tableData = [
  {
    szmc: "RGB24格式转换算子参数",
    szlx: "前处理",
    szzlx: "格式转换",
    bb: "",
    hlcjsj: "2024-05-03",
  },
  {
    szmc: "图像缩放算子参数",
    szlx: "前处理",
    szzlx: "图像缩放",
    bb: "专业的图像缩放",
    hlcjsj: "2024-06-07",
  },
  {
    szmc: "人脸识别算子",
    szlx: "后处理",
    szzlx: "人脸识别",
    bb: "好高大上的人脸识别算子模型",
    hlcjsj: "2024-06-08",
  }
];

/** 查询 */
function handleQuery() {
  loading.value = true;
  ElMessage.success("查询成功");
  loading.value = false;
  // UserAPI.getPage(queryParams)
  //   .then((data) => {
  //     console.log("handleQuery", data);
  //     pageData.value = data.list;
  //     total.value = data.total;
  //   })
  //   .finally(() => {
  //     loading.value = false;
  // });
}

/** 重置查询 */
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("删除成功");
  });
}

/**
 * 打开弹窗
 *
 * @param type 弹窗类型  用户表单：user-form | 用户导入：user-import
 * @param id 用户ID
 */
async function openDialog(type: string, id?: number) {
  router.replace({ path: "/operatorLibrary/calculateParamEdit" });
}

/** 下载导入模板 */
function downloadTemplate() {
  ElMessage.success("下载模板成功");
}

/** 导出用户 */
function handleExport() {
  ElMessage.success("导出成功");
}

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