<script setup lang="ts">
import { PageContent } from "/@/components/PageContent";
import { PageSearch, usePageSearch } from "/@/components/PageSearch";
import { useRouter } from "vue-router";
import contentConfig from "./config/content.config";
import searchFormConfig from "./config/search.config";
import { useUserStoreHook } from "/@/store/modules/user";
import { onMounted, computed } from "vue";
import PagePower from "/@/components/PagePower/PagePower.vue";

defineOptions({
  name: "purchPay"
});

const { pageContentRef, handleSearchClick, handleResetClick } = usePageSearch();

const contentConfigRef = computed(() => contentConfig);

const { push } = useRouter();

function handleCreate() {
  push("/purchase/purchPayDetail");
}

function handlePreview(item) {
  push({
    path: "/purchase/purchPayDetail",
    query: {
      id: item.dzNo
    }
  });
}

onMounted(
  () => (contentConfig.powers = useUserStoreHook().getMenuActions("purchPay"))
);
</script>

<template>
  <div class="main role">
    <PagePower :isShow="contentConfigRef.powers.some(i => i === '001')">
      <div w-full>
        <PageSearch
          ref="pageContentRef"
          :form-config="searchFormConfig"
          @search-btn-click="handleSearchClick"
          @reset-btn-click="handleResetClick"
        />
        <PageContent
          ref="pageContentRef"
          :content-config="contentConfigRef"
          @preview-btn-click="handlePreview"
        >
          <template #create>
            <el-button type="primary" @click="handleCreate">新建</el-button>
          </template>
        </PageContent>
      </div>
    </PagePower>
  </div>
</template>
