<script setup lang="ts">
import { ref } from "vue";
import { useDetail } from "/@/hooks/core/useDetail";
import { useAsync } from "/@/hooks/core/useAsync";
// import { purchpayReliveColumns } from "./config/_details";
import BasicDescriptions from "/@/components/BasicDescriptions";
import ReconciliationForm from "/@/components/ReconciliationForm";
import ChooseForm from "./component/choose-form.vue";
import { useRouter } from "vue-router";

import { httpDetail, httpAdd } from "/@/api/purchase/purchPayRelive";
import { purchpayReliveColumns } from "/@/utils/details/_purchase";

const { push } = useRouter();

const formRef = ref<InstanceType<typeof ReconciliationForm> | null>(null);

const { id, isDetail, title, collapses } = useDetail({
  baseName: "采购回款解除",
  collapseLen: 5
});

const { run: detail, data } = useAsync<Record<string, string>>({
  initalData: {}
});

const { run: create } = useAsync({
  success: () => push("/supply/supplyPurchPayRelive")
});

const requesetDetail = () => detail(httpDetail({ returnCode: id.value }));
const handleCreate = data => create(httpAdd(data));

if (isDetail.value) requesetDetail();
</script>

<template>
  <div class="padding__container">
    <ElTabs>
      <ElTabPane :label="title">
        <ElCollapse v-model="collapses">
          <ElCollapseItem name="2" :title="title">
            <!-- 解除付款详情 -->
            <BasicDescriptions
              class="mb-2"
              v-if="isDetail"
              :columns="purchpayReliveColumns"
              :data="data"
            />

            <!-- 创建：选择付款解除 -->
            <ChooseForm v-else @create="handleCreate" />
          </ElCollapseItem>

          <div v-if="isDetail">
            <ElCollapseItem name="2" title="对账详情">
              <ReconciliationForm ref="formRef" readonly :id="data.payNo" />
            </ElCollapseItem>
          </div>
        </ElCollapse>
      </ElTabPane>
    </ElTabs>
  </div>
</template>
