<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>
            <el-image style="width: 40px; height: 40px" :src="scope.row.imgUrl.split(',')[0]" fit="contain" />
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="showPosition" align="center" label="弹窗位置">
        <template #default="scope">
          {{ showPositionFilter(scope.row.showPosition) }}
        </template>
      </el-table-column>
      <el-table-column label="是否可见" align="center" prop="status">
        <template #default="scope">
          <el-switch v-model="scope.row.status" @change="handleStatusChange(scope.row)" :active-value="1"
            :inactive-value="0" />
        </template>
      </el-table-column>
      <el-table-column prop="frequency" align="center" label="弹窗频率">
        <template #default="scope">
          {{ frequencyFilter(scope.row.frequency) }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" align="center" label="创建日期" />
      <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 frequencyFilter(d) {
  // only_one 仅首次展示, every_show 每次打开都展示，every_day 每天展示一次，three_day 每三天展示一次， seven_day 每七天展示一次， thirty_day 没30天展示一次
  if (d == 'only_one') return '仅首次展示'
  if (d == 'every_show') return '每次打开都展示'
  if (d == 'every_day') return '每天展示一次'
  if (d == 'three_day') return '每三天展示一次'
  if (d == 'seven_day') return '每七天展示一次'
  if (d == 'thirty_day') return '每30天展示一次'
}
function handleStatusChange(d) {
  emit('handleStatusChange', d)
}
function showPositionFilter(d) {
  // home首页，make_order点餐页
  if (d == 'home') return '首页'
  if (d == 'make_order') return '点餐页'
}
function handleEdit(row) {
  emit('handleEdit', row)
}
function handleDelete(index, row) {
  emit('handleDelete', row.id)
}

</script>
