<template>
  <Dialog title="设备信息详情" v-model="dialogVisible" width="700px">
    <el-descriptions :column="2" border>
      <el-descriptions-item label="设备名称">{{ detailData.deviceName }}</el-descriptions-item>
      <el-descriptions-item label="设备分类">{{ detailData.deviceCategory || '-' }}</el-descriptions-item>
      <el-descriptions-item label="采购地方">{{ detailData.purchasePlace || '-' }}</el-descriptions-item>
      <el-descriptions-item label="采购供应商">{{ detailData.supplier || '-' }}</el-descriptions-item>
      <el-descriptions-item label="联系方式">{{ detailData.contactInfo || '-' }}</el-descriptions-item>
      <el-descriptions-item label="采购价格">
        {{ detailData.purchasePrice ? '¥' + detailData.purchasePrice : '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="产品参数" :span="2">
        {{ detailData.productParams || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="产品要素" :span="2">
        {{ detailData.productElements || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="使用部件" :span="2">
        {{ detailData.usedParts || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="设备图片" :span="2">
        <el-image
          v-if="detailData.picUrl"
          :src="detailData.picUrl"
          :preview-src-list="[detailData.picUrl]"
          class="w-[120px] h-[120px]"
          fit="cover"
          preview-teleported
        />
        <span v-else>-</span>
      </el-descriptions-item>
      <el-descriptions-item label="备注信息" :span="2">
        {{ detailData.remark || '-' }}
      </el-descriptions-item>
      <el-descriptions-item label="创建时间">
        {{ formatDate(detailData.createTime) }}
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { DeviceInfoVO } from '@/api/iot/device/deviceInfo'
import { formatDate } from '@/utils/formatTime'

/** 设备信息详情 */
defineOptions({ name: 'DeviceInfoDetail' })

const dialogVisible = ref(false) // 弹窗的是否展示
const detailData = ref<Partial<DeviceInfoVO>>({}) // 详情数据

/** 打开弹窗 */
const open = (row: DeviceInfoVO) => {
  dialogVisible.value = true
  detailData.value = row
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
