<!--
 * @Author: chris
 * @Date: 2025-08-08 16:18:20
 * @LastEditors: chris
 * @LastEditTime: 2025-08-08 16:26:05
-->
<template>
  <el-dialog :title="'果园详情'" v-model="props.open" width="600px" append-to-body>
    <el-descriptions title="果园信息" :column="1" border>
      <el-descriptions-item label="果园名称">{{ viewForm.orchardName }}</el-descriptions-item>
      <el-descriptions-item label="负责人">{{ viewForm.manager }}</el-descriptions-item>
      <el-descriptions-item label="联系电话">{{ viewForm.phone }}</el-descriptions-item>
      <el-descriptions-item label="地址">{{ viewForm.address }}</el-descriptions-item>
      <el-descriptions-item label="面积(亩)">{{ viewForm.area }}</el-descriptions-item>
      <el-descriptions-item label="状态">{{ viewForm.status === '0' ? '正常' : '停用' }}</el-descriptions-item>
      <el-descriptions-item label="创建时间">{{ parseTime(viewForm.createTime) }}</el-descriptions-item>
      <el-descriptions-item label="备注">{{ viewForm.remark || '-' }}</el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="close">关 闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getOrchard } from '@/api/orchard'
import { parseTime } from '@/utils/ruoyi'

const props = defineProps({
  open: { type: Boolean, required: true },
  orchardId: { type: [String, Number], required: false }
})

const emits = defineEmits(['update:open'])

const viewForm = ref({})

onMounted(() => {
  if (props.open && props.orchardId) {
    loadData(props.orchardId)
  }
})

// 加载详情数据
async function loadData(id) {
  try {
    const res = await getOrchard(id)
    viewForm.value = res || {}
  } catch (error) {
    ElMessage.error('获取果园详情失败: ' + (error.message || '未知错误'))
    emits('update:open', false)
  }
}

// 关闭对话框
function close() {
  emits('update:open', false)
}
</script>