<script setup lang="ts">

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 { suppliersInfo} from '#/api/property/assetManage/suppliers';
import {renderDict} from "#/utils/render";
import type {SuppliersVO} from "#/api/property/assetManage/suppliers/model";

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

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

const supplierDetail = shallowRef<null | SuppliersVO>(null);

async function handleOpenChange(open: boolean) {
  if (!open) {
    return null;
  }
  modalApi.modalLoading(true);

  const {id} = modalApi.getData() as { id: number | string };
  // 赋值
  supplierDetail.value = await suppliersInfo(id);

  modalApi.modalLoading(false);
}


</script>

<template>
  <BasicModal :footer="false" :fullscreen-button="false" title="供应商详情" class="w-[70%]">
    <Descriptions v-if="supplierDetail" size="small" :column="2" bordered :labelStyle="{width:'110px'}">
      <DescriptionsItem label="供应商名称" :span="2">
       {{ supplierDetail.suppliersName }}
      </DescriptionsItem>
      <DescriptionsItem label="联系人">
        {{supplierDetail.user}}
      </DescriptionsItem>
      <DescriptionsItem label="电话">
        {{supplierDetail.phone}}
      </DescriptionsItem>
      <DescriptionsItem label="地址" :span="2">
        {{ supplierDetail.location}}
      </DescriptionsItem>
      <DescriptionsItem label="开户行">
        {{ supplierDetail.bank}}
      </DescriptionsItem>
      <DescriptionsItem label="卡号">
        {{ supplierDetail.bankNumber}}
      </DescriptionsItem>
      <DescriptionsItem label="状态" v-if="supplierDetail.state!=null">
        <component
          :is="renderDict(supplierDetail.state,'wy_state')"
        />
      </DescriptionsItem>
      <DescriptionsItem label="创建时间">
        {{ supplierDetail.createTime}}
      </DescriptionsItem>
      <DescriptionsItem label="备注">
       {{ supplierDetail.remark}}
      </DescriptionsItem>
    </Descriptions>
  </BasicModal>
</template>
