<!--
 * @Author: chris
 * @Date: 2025-08-08 16:17:54
 * @LastEditors: chris
 * @LastEditTime: 2025-08-11 11:02:05
-->
<template>
  <el-table
    v-loading="loading"
    :data="orchardList"
    @selection-change="handleSelectionChange"
    row-key="orchardId"
    border
    highlight-current-row
    style="width: 100%"
  >
    <el-table-column type="selection" width="50" align="center" />
    <el-table-column label="果园编号" align="center" prop="orchardId" v-if="columns[0].visible"/>
    <el-table-column label="果园名称" align="center" prop="orchardName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
    <el-table-column label="负责人" align="center" prop="manager" v-if="columns[2].visible" />
    <el-table-column label="联系电话" align="center" prop="phone" v-if="columns[3].visible" />
    <el-table-column label="地址" align="center" prop="address" v-if="columns[4].visible" :show-overflow-tooltip="true" />
    <el-table-column label="面积(亩)" align="center" prop="area" v-if="columns[5].visible" />
    <el-table-column label="状态" align="center" v-if="columns[6].visible">
      <template #default="scope">
        <el-tag :type="statusColorMap[scope.row.status]">
          {{ scope.row.status === '0' ? '正常' : '停用' }}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[7].visible">
      <template #default="scope">
        <span>{{ parseTime(scope.row.createTime) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center" fixed="right">
      <template #default="scope">
        <el-tooltip content="查看" placement="top">
          <el-button link type="primary" icon="Eye" @click="handleView(scope.row)" v-hasPermi="['business:orchard:query']"></el-button>
        </el-tooltip>
        <el-tooltip content="修改" placement="top">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:orchard:edit']"></el-button>
        </el-tooltip>
        <el-tooltip content="删除" placement="top">
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:orchard:remove']"></el-button>
        </el-tooltip>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { parseTime } from '@/utils/ruoyi'

const props = defineProps({
  orchardList: { type: Array, required: true },
  loading: { type: Boolean, required: true },
  columns: { type: Array, required: true }
})

const emits = defineEmits(['selection-change', 'view', 'update', 'delete'])

// 状态颜色映射
const statusColorMap = {
  '0': 'success',
  '1': 'danger'
}

function handleSelectionChange(selection) {
  emits('selection-change', selection)
}

function handleView(row) {
  emits('view', row)
}

function handleUpdate(row) {
  emits('update', row)
}

function handleDelete(row) {
  emits('delete', row)
}
</script>