<script lang="ts">
// 声明额外的选项
export default {
  name: "ApiInfo"
};
</script>
<script setup lang="ts">
import { provide } from "vue";
import { useApiInfo } from "./hook";
import { http } from "@/utils/http";
import { useRenderIcon, hasAuth, PureTableBar } from "@/utils/importUsed"
import Add from "./components/add/index.vue";
import EditSetVersion from "./components/setVersion/index.vue";
import EditUpdate from "./components/update/index.vue";
import EditSetRouter from "./components/setRouter/index.vue";
import Search from "@iconify-icons/ep/search";
import Addicon from "@iconify-icons/ep/document-add";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";

const {
  form,
  loading,
  columns,
  dataList,
  pagination,
  onSearch,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  ruleFormRef,
  groupIdOptionList,
  handleAdd,
  addVisible,
  handleSetVersion,
  editSetVersionVisible,
  editSetVersionFormData,
  handleDelete,
  handleUpdate,
  editUpdateVisible,
  editUpdateFormData,
  handleSetRouter,
  editSetRouterVisible,
  editSetRouterFormData,

} = useApiInfo();
// 关闭添加
const closeAddVisible = () => {
  addVisible.value = false
}
provide('closeAddVisible', closeAddVisible)
// 关闭修改
const closeEditSetVersionVisible = () => {
  editSetVersionVisible.value = false
}
provide('closeEditSetVersionVisible', closeEditSetVersionVisible)
// 关闭修改
const closeEditUpdateVisible = () => {
  editUpdateVisible.value = false
}
provide('closeEditUpdateVisible', closeEditUpdateVisible)
// 关闭修改
const closeEditSetRouterVisible = () => {
  editSetRouterVisible.value = false
}
provide('closeEditSetRouterVisible', closeEditSetRouterVisible)

</script>

<template lang="pug">
.main
  div
    //- 搜索表格组件条件
    el-form.bg-bg_color.pl-8.pt-4.pr-8(
      label-position="left"
      label-width="100px"
      :inline="true",
      :model="form",
      class="w-[99/100]"
      ref="ruleFormRef"
      :rules="rules"
    )
      el-form-item(label="分组", prop="groupId")
        el-select(
          v-model="form.groupId",
          placeholder="请选择分组",
          clearable,
          class="!w-[230px]"
        )
          el-option(:label="item.groupName", :value="item.id" v-for="(item,index) in groupIdOptionList")
      el-form-item(label='接口名称' prop="apiName")
        el-input(v-model='form.apiName' autocomplete='off' class="!w-[230px]"
          placeholder="请输入接口名称")

      el-form-item
        el-button(
          type="primary",
          :icon="useRenderIcon(Search)",
          :loading="loading",
          @click="onSearch(ruleFormRef)"
        ) 查询
    //- 表格组件
    PureTableBar(title="api接口", @refresh="onSearch" )
      template(#buttons)
        el-button(type="primary" :icon="useRenderIcon(Addicon)" @click="handleAdd()" v-if="hasAuth(['add'])") 新增

      template(v-slot="{ size, checkList }")
        pure-table(stripe 
          border,
          align-whole="center",
          table-layout="auto",
          :loading="loading",
          :size="size",
          :data="dataList",
          :columns="columns",
          :checkList="checkList",
          :pagination="pagination",
          :paginationSmall="size === 'default' ? true : false",
          :header-cell-style="{ background: 'var(--el-table-row-hover-bg-color)', color: 'var(--el-text-color-primary)' }",
          @selection-change="handleSelectionChange",
          @size-change="handleSizeChange",
          @current-change="handleCurrentChange"
        )          
          template(#operation="{ row }")
            .flex.flex-wrap.items-center
              el-dropdown(trigger="click", :hide-on-click="false")
                el-button(type="primary") 操作
                  el-icon.el-icon--right
                    arrow-down
                template(#dropdown)
                  el-dropdown-menu
                    el-dropdown-item
                      el-button.reset-margin(
                        type="primary"
                        size="small"
                        @click="handleSetVersion(row)"
                        :icon="useRenderIcon(EditPen)"
                        v-if="hasAuth(['setVersion'])"
                      ) 设置版本号
                    el-button.reset-margin(
                      type="primary"
                      size="small"
                      @click="handleDelete(row)"
                      :icon="useRenderIcon(Delete)"
                      v-if="hasAuth(['delete'])"
                    ) 删除
                    el-dropdown-item
                      el-button.reset-margin(
                        type="primary"
                        size="small"
                        @click="handleUpdate(row)"
                        :icon="useRenderIcon(EditPen)"
                        v-if="hasAuth(['update'])"
                      ) 修改
                    el-dropdown-item
                      el-button.reset-margin(
                        type="primary"
                        size="small"
                        @click="handleSetRouter(row)"
                        :icon="useRenderIcon(EditPen)"
                        v-if="hasAuth(['setRouter'])"
                      ) 设置请求地址

    Add(:addVisible="addVisible")
    EditSetVersion(:editVisible="editSetVersionVisible" :formData="editSetVersionFormData")
    EditUpdate(:editVisible="editUpdateVisible" :formData="editUpdateFormData")
    EditSetRouter(:editVisible="editSetRouterVisible" :formData="editSetRouterFormData")

                    
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

:deep(.el-form-item__label) {
  font-weight: 700;
}

:deep(.el-pagination) {
  flex-flow: wrap;
}

:deep(.is-draggable) {
  max-height: 80vh;
  overflow: auto;
}

:deep(.el-dialog__header) {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
}

:deep(.el-descriptions__header) {
  margin: 16px 0 !important;
}
</style>