<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;justify-content: center;">
            <el-image style="width: 40px; height: 40px" :src="scope.row.imgUrl" fit="contain" />
            {{ scope.row.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="unit" align="center" label="单位" />
      <el-table-column prop="period" align="center" label="有效期（天）" />
      <el-table-column prop="source" align="center" label="来源">
        <template v-slot="scope">
          {{ scope.row.source == 1 ? '商品' : '手动' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button size="small" type="primary" link icon="Edit" @click="myDialogRefqs(scope.row)">存酒</el-button>
          <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', 'myDialogRefqs'])
const props = defineProps({
  list: {
    type: Array,
    default: () => []
  }
})

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

</script>
