<script setup lang="ts">
import { useColumns } from "./columns";
import { httpList } from "/@/api/InvoiceSales/invoiceApply";
import { reactive, ref, onMounted } from "vue";

import { TableProBar } from "/@/components/ReTable";
import { type PaginationProps } from "@pureadmin/table";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { useNav } from "/@/layout/hooks/nav";
import { statusList, inv_type_list } from "./status";
import { useRouter } from "vue-router";
import { responseHandle } from "/@/utils/responseHandle";
const { logout } = useNav();
defineOptions({
  name: "InvoiceApplyDetail"
});

const initform = {
  buy_id: "", //客户公司
  companyNo: "", //业务企业公司
  khNo: "", //申请人
  invtype: "",
  email: "",
  remark: "",
  orderArr: []
};
const id = ref("");
const form = reactive({ ...initform });
const startDisabledDate = (time: Date) => {
  const { end } = form;
  if (end ?? "") {
    return time.getTime() > Date.now(end).valueOf();
  }
};
const endDisabledDate = (time: Date) => {
  const { start } = form;
  if (start ?? "") {
    return time.getTime() < Date.now(start).valueOf();
  }
};
const { push } = useRouter();
const dataList = ref([]);
const loading = ref(false);
const { columns } = useColumns();

const pagination = reactive<PaginationProps>({
  total: 0,
  pageSize: 15,
  currentPage: 1,
  background: true
});

async function handleCurrentChange(val: number) {
  form.page = val;
  await onSearch();
}

async function handleSizeChange(val: number) {
  form.size = val;
  form.page = 1;
  await onSearch();
}

function handleSelectionChange(val) {
  console.log("handleSelectionChange", val);
}

async function onSearch() {
  if (loading.value) return;
  loading.value = true;
  const { code, data, message } = await httpList(form);
  responseHandle({
    code,
    message,
    logout,
    handler: () => {
      const { list, count } = data;
      dataList.value = list ?? [];
      pagination.total = count ?? 0;
      pagination.pageSize = form.size;
      pagination.currentPage = form.page;
    }
  });

  loading.value = false;
}
async function resetSearch() {
  form.page = 1;
  await onSearch();
}
//新建/详情页面
function editItem(id) {
  push({
    path: "/InvoiceSales/invoiceApplyDeatil",
    query: {
      id
    }
  });
}
async function resetForm() {
  Object.keys(form.value).forEach(key => {
    form.value[key] = initform[key];
  });
  await onSearch();
}

onMounted(() => {
  onSearch();
});
</script>

<template>
  <div class="main bg-white">111</div>
</template>

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