<script setup lang="ts">
import type {PaymentReviewVO} from '#/api/property/costManagement/paymentReview/model';
import {shallowRef} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {Descriptions, DescriptionsItem} from 'ant-design-vue';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
import {paymentReviewInfo} from '#/api/property/costManagement/paymentReview';
import {renderDict} from "#/utils/render";

dayjs.extend(duration);
dayjs.extend(relativeTime);

const [BasicModal, modalApi] = useVbenModal({
  onOpenChange: handleOpenChange,
  onClosed() {
    paymentReviewDetail.value = null;
  },
});

const paymentReviewDetail = shallowRef<null | PaymentReviewVO>(null);

async function handleOpenChange(open: boolean) {
  if (!open) {
    return null;
  }
  modalApi.modalLoading(true);
  const {id} = modalApi.getData() as { id: number | string };
  paymentReviewDetail.value =await paymentReviewInfo(id);
  modalApi.modalLoading(false);
}
</script>

<template>
  <BasicModal :footer="false" :fullscreen-button="false" title="缴费审核详情" class="w-[70%]">
    <Descriptions v-if="paymentReviewDetail" size="small" :column="2" bordered
                  :labelStyle="{width:'120px'}">
      <DescriptionsItem label="房屋">
        {{ paymentReviewDetail.roomNumber }}
      </DescriptionsItem>
      <DescriptionsItem label="费用项目">
        {{ paymentReviewDetail.chargeItem }}
      </DescriptionsItem>
      <DescriptionsItem label="付费周期">
        {{ paymentReviewDetail.chargeCycle }}
      </DescriptionsItem>
      <DescriptionsItem label="缴费开始时间">
        {{ paymentReviewDetail.startTime }}
      </DescriptionsItem>
      <DescriptionsItem label="缴费结束时间">
        {{ paymentReviewDetail.endTime }}
      </DescriptionsItem>
      <DescriptionsItem label="实付金额">
        {{ paymentReviewDetail.receivedAmount }}
      </DescriptionsItem>
      <DescriptionsItem label="应收金额">
        {{ paymentReviewDetail.receivableAmount }}
      </DescriptionsItem>
      <DescriptionsItem label="缴费时间">
        {{ paymentReviewDetail.payTime }}
      </DescriptionsItem>
      <DescriptionsItem label="审核状态" v-if="paymentReviewDetail.state!=null">
        <component
          :is="renderDict(paymentReviewDetail.state,'cost_review_status')"
        />
      </DescriptionsItem>
    </Descriptions>
  </BasicModal>
</template>
