<template>
  <Dialog v-model="dialogVisible" title="巡检物资柜详情" width="800">
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column label="计划名称" align="center" prop="planName" />
      <el-table-column label="巡检物资柜" align="center" prop="cabinetName" />
      <el-table-column label="签名" align="left" prop="signatureImg">
        <template #default="scope">
          <UploadImg
            v-if="scope.row.signatureImg"
            v-model="scope.row.signatureImg"
            :limit="1"
            height="50px"
            width="50px"
          />
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left">
        <template #default="scope">
          <el-button link type="primary" @click="handleViewRecord(scope.row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <template #footer>
      <el-button @click="dialogVisible = false">关 闭</el-button>
    </template>
  </Dialog>

  <!-- 检查记录弹窗 -->
  <CheckRecordDialog ref="recordRef" />
</template>

<script lang="ts" setup>
import * as PlanApi from '@/api/material/plan'

defineOptions({ name: 'PlanDetailDialog' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据

/** 打开弹窗 */
const open = async (row: any) => {
  dialogVisible.value = true
  loading.value = true
  try {
    const data = await PlanApi.getCheckPlanCabinetList({
      planId: row.planId,
      pageSize: 999999999,
      pageNum: 1
    })
    list.value = data
  } finally {
    loading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 查看检查记录 */
const recordRef = ref()
const handleViewRecord = (row: any) => {
  recordRef.value.open(row)
}
</script>
