<template>
  <div style="margin-top: 10px;">
    <el-table :data="props.list" border style="width: 100%">
      <el-table-column prop="name" align="center" label="商品">
        <template v-slot="scope">
          <div style="display: flex;align-items: center;">
            <el-image style="width: 40px; height: 40px" :src="scope.row.goodsImageUrl" fit="contain" />
            {{ scope.row.goodsName }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="所需积分" align="center" prop="requiredPoints" />
      <el-table-column label="额外价格(元)" align="center" prop="extraPrice" />
      <el-table-column label="累计兑换次数" align="center" prop="totalExchangeCount" />
      <el-table-column label="库存" align="center" prop="quantity" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">{{ scope.row.status === 1 ? '上架' : '下架'
            }}</el-tag>
        </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'])
const props = defineProps({
  list: {
    type: Array,
    default: () => []
  }
})

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

</script>
