<template>
  <BasicModal v-bind="$attrs" :title="title" @register="registerInnerModal">
    <template #footer>
      <div v-if="isUpdate !== 3">
        <a-button type="default" @click="handleCancle">取消</a-button>
        <a-button type="primary" @click="handleSubmit">确认</a-button>
      </div>
    </template>
    <Descriptions
      title="电梯管理"
      bordered
      :column="{ xxl: 2, xl: 2, lg: 2, md: 2, sm: 2, xs: 2 }"
    >
      <DescriptionsItem label="电梯名称">{{
        elevatorInfo.elevatorName || "-"
      }}</DescriptionsItem>
      <DescriptionsItem label="楼宇">{{
        elevatorInfo.buildingName || "-"
      }}</DescriptionsItem>
      <!-- <DescriptionsItem label="电梯型号"></DescriptionsItem> -->
      <DescriptionsItem label="电梯编号">{{
        elevatorInfo.elevatorNum || "-"
      }}</DescriptionsItem>
      <DescriptionsItem label="维保单位">{{
        elevatorInfo.maintenanceName || "-"
      }}</DescriptionsItem>
      <DescriptionsItem label="物业单位">{{
        elevatorInfo.tenementName || "-"
      }}</DescriptionsItem>
      <DescriptionsItem label="年检日期">{{
        elevatorInfo.annualDate || "-"
      }}</DescriptionsItem>
      <!-- <DescriptionsItem label="上次维保日期"></DescriptionsItem>
      <DescriptionsItem label="下次维保计划日期"></DescriptionsItem> -->
    </Descriptions>
  </BasicModal>
</template>

<script setup lang="ts">
import { BasicModal, useModalInner } from "@/components/Modal";
import { Descriptions, DescriptionsItem } from "ant-design-vue";
import { computed, ref, unref } from "vue";

defineOptions({ name: "BuildingInfoModal" });

const emit = defineEmits(["register", "reload"]);
const elevatorInfo = ref<any>({});
const isUpdate = ref<number>(1);
const title = computed<string>(() => {
  return "电梯详情";
});

const [registerInnerModal, { modalLoading, closeModal }] = useModalInner(
  async (data: { record?: Recordable; update: number }) => {
    modalLoading(true);
    const { record, update } = data;
    isUpdate.value = update;
    console.log(record, "ppp");
    elevatorInfo.value = record;
    modalLoading(false);
  }
);

async function handleSubmit() {
  try {
    modalLoading(true);

    emit("reload");
    closeModal();
  } catch (e) {
    console.warn(e);
  } finally {
    modalLoading(false);
  }
}
function handleCancle() {
  closeModal();
}
</script>

<style scoped></style>
