<script setup lang="ts">
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import searchConfig from "./config/search.config";
import contentConfig from "./config/content.config";
import { usePermission } from "/@/hooks/usePermission";
import { PageContent } from "/@/components/PageContent";
import { ref } from "vue";
import EditModel from "./components/edit-dialog.vue";
const { pageContentRef, handleResetClick, handleSearchClick } = usePageSearch(
  undefined,
  undefined,
  searchConfig
);
const pageName = "setService";
const modelRef = ref<InstanceType<typeof EditModel>>(null);
const { hasPermissionWithCode, permissions } = usePermission(pageName);

function handleAddChangeCheck(item: any, id: string, type: string) {
  modelRef.value.show(item, id, type);
}
</script>

<template>
  <PageAuth :pageName="pageName">
    <PageSearch
      :form-config="searchConfig"
      @search-btn-click="handleSearchClick"
      @reset-btn-click="handleResetClick"
    >
      <template #action>
        <el-button
          type="primary"
          @click="handleAddChangeCheck({}, '', 'create')"
          v-if="hasPermissionWithCode('002')"
        >
          新增
        </el-button>
      </template>
    </PageSearch>
    <PageContent
      ref="pageContentRef"
      :powers="permissions"
      :content-config="contentConfig"
      @preview-btn-click="row => handleAddChangeCheck(row, row.id, 'view')"
      @update-btn-click="row => handleAddChangeCheck(row, row.id, 'edit')"
    />
    <EditModel ref="modelRef" @reload="pageContentRef.onSearch()" />
  </PageAuth>
</template>
