<template>
  <div style="margin-top: 10px;">
    <el-table :data="props.list" border style="width: 100%">
      <el-table-column prop="id" align="center" label="ID" />
      <el-table-column prop="name" align="center" label="耗材类型名称" />
      <el-table-column prop="status" align="center" label="状态">
        <template #default="scope">
          <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" active-color="#13ce66"
            inactive-color="#ff4949" @change="handleStatusChange(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button size="small" type="primary" link icon="Edit" @click="handleEdit(scope.row)">编辑</el-button>
          <!-- <el-button size="small" type="danger" link icon="Delete" style="color: #f89797;"
            @click="handleDelete(scope.$index, scope.row)"> 删除 </el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
const emit = defineEmits(['handleDelete', 'handleEdit', 'handleStatusChange'])
const props = defineProps({
  list: {
    type: Array,
    default: () => []
  }
})

function handleEdit(row) {
  emit('handleEdit', row)
}
function handleDelete(index, row) {
  emit('handleDelete', row.id)
}

function handleStatusChange(row) {
  emit('handleStatusChange', row)
}
</script>
