<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 { ref, onMounted } from "vue";
defineOptions({
  name: "orderRecord"
});
const powers = ref([]);
const searchCallback = ({ timer }: any) => {
  const [startTime, endTime] = timer;
  return {
    result: {
      startTime,
      endTime
    },
    deleteProps: ["timer"]
  };
};

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

const { push } = useRouter();

const handleCreate = () => push("/purchase/orderRecordDetail");

function handlePreview(item) {
  push({
    path: "/purchase/orderRecordDetail",
    query: {
      id: item.payNo
    }
  });
}
onMounted(() => {
  const arr = useUserStoreHook().getMenuActions("orderRecord");
  powers.value = [].concat(...arr);
  contentConfig.powers = [].concat(...arr);
  // if (powers.value.some(i => i == "001")) {
  //   actionTableRef.value.onSearch();F
  // }
});
</script>

<template>
  <div class="main orderRecord">
    <div v-show="powers.some(i => i == '001')">
      <PageSearch
        ref="pageContentRef"
        :form-config="searchFormConfig"
        @search-btn-click="handleSearchClick"
        @reset-btn-click="handleResetClick"
      />

      <PageContent
        ref="pageContentRef"
        :content-config="contentConfig"
        @preview-btn-click="handlePreview"
      >
        <template #create>
          <el-button
            type="primary"
            v-if="powers.some(i => i == '002')"
            @click="handleCreate"
            >新建</el-button
          >
        </template>
      </PageContent>
    </div>
    <NoAuth v-show="!powers.some(i => i == '001')" />
  </div>
</template>
