<template>
  <div class="main-box">
    <div class="table-box">
      <ProTable
        ref="proTable"
        :columns="columns"
        :data="getTableList"
        :init-param="initParam"
        :search-col="{ xs: 1, sm: 1, md: 2, lg: 3, xl: 3 }"
      >
        <!-- 表格 header 按钮 -->
        <template #tableHeader>
          <el-button type="primary" plain :icon="Download" @click="exportAction"> 导出 </el-button>
        </template>
        <template #tableHeaderRight>
          <el-button type="primary" :icon="Plus" @click="openDialog()"> 添加 </el-button>
        </template>
        <!-- 表格操作 -->
        <template #operation="scope">
          <el-button type="primary" link :icon="EditPen" @click="openDialog(scope.row)"> 编辑 </el-button>
          <el-button type="primary" link :icon="Delete" @click="handleDelete(scope.row)"> 删除 </el-button>
        </template>
      </ProTable>
    </div>
  </div>
</template>
<script setup lang="ts" name="semanticAssociationManage">
import { ref, reactive } from "vue";
import { SemanticsAssociation } from "@/api/interface";
import ProTable from "@/components/ProTable/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { Download, Plus, Delete, EditPen } from "@element-plus/icons-vue";
// import { useDownload } from "@/hooks/useDownload";

// ProTable 实例
const proTable = ref<ProTableInstance>();

// 如果表格需要初始化请求参数，直接定义传给 ProTable(之后每次请求都会自动带上该参数，此参数更改之后也会一直带上，改变此参数会自动刷新表格数据)
const initParam = reactive({ deptId: "" });

// 表格配置项
const columns = reactive<ColumnProps<SemanticsAssociation.ResSemanticsAssociationList>[]>([
  { prop: "semanticsName", label: "语义关联", search: { el: "input" } },
  { prop: "semanticsName", label: "定义", search: { el: "input" } },
  { prop: "updateTime", label: "更新时间", search: { el: "date-range-picker", custom: true } },
  { prop: "updatePerson", label: "更新人", search: { el: "input" } },
  {
    prop: "dataSources",
    label: "数据来源",
    // enum: () => getDictOptions("sys_oper_type"),
    // enum: [{ label: "添加", value: "1" }],
    search: { el: "select" }
  },
  { prop: "notes", label: "备注" },
  { prop: "operation", label: "操作", width: 330, fixed: "right" }
]);
// 分页列表获取数据
const getTableList = [
  {
    semanticsId: "111222",
    semanticsName: "111",
    updateTime: "2024-10-01 12:02:03",
    updatePerson: "更新人",
    dataSources: "数据来源",
    notes: "备注"
  }
];
console.log("getTableList", getTableList);
// const getTableList = (params: SemanticsAssociation.ReqSemanticsAssociationParams) => {
//   if (params.createTime) {
//     const [beginTime, endTime] = params.createTime;
//     params.params = {
//       beginTime,
//       endTime
//     };
//     delete params.createTime;
//   }
//   return getUserList(params);
// };
// 删除
const handleDelete = async (params: SemanticsAssociation.ResSemanticsAssociationList) => {
  console.log(params);
  proTable.value?.getTableList();
};
// 打开(新增、查看、编辑)
// const dialogRef = ref<InstanceType<typeof SemanticsDialog> | null>(null);
const openDialog = (row?: Partial<SemanticsAssociation.ResSemanticsAssociationList>) => {
  console.log("打开语义关联", row);
  // dialogRef.value?.open(row).then(proTable.value?.getTableList);
};

// 导出
async function exportAction() {
  console.log("导出");
}
</script>
