<template>
	<a-table :data-source="tableData" :columns="columns" :pagination="false" style="width: 100%">
		<template #bodyCell="{ column, record }">
			<template v-if="column.key === 'ferryType'">
				<span>{{ record.ferryType === 0 ? '复制' : '移动' }}</span>
			</template>
			<template v-else-if="column.key === 'operation'">
				<a-button type="link" danger size="small" @click="handleDelete(record)">删除</a-button>
			</template>
		</template>
	</a-table>
</template>

<script setup>
	import { ferryRecordDelete } from '@/api/myResource/file' // 假设路径调整为相对路径
	import { message } from 'ant-design-vue'

	const props = defineProps({
		tableData: {
			type: Array,
			required: true
		}
	})

	const emit = defineEmits(['delTransferList'])

	const columns = [
		{ title: '文件名', dataIndex: 'fileName', key: 'fileName' },
		{ title: '文件类型', dataIndex: 'fileType', key: 'fileType' },
		{ title: '文件大小', dataIndex: 'fileSize', key: 'fileSize' },
		{ title: '传输类型', dataIndex: 'ferryType', key: 'ferryType' },
		{ title: '时间', dataIndex: 'createTime', key: 'createTime' },
		{ title: '操作', key: 'operation', fixed: 'right', width: 100 }
	]

	const handleDelete = (row) => {
		ferryRecordDelete(row.recordId).then(
			(res) => {
				if (res.code === 0) {
					message.success('删除记录成功')
					emit('delTransferList')
				} else {
					message.error(res.message || '删除失败')
				}
			},
			(err) => {
				message.error(`删除失败: ${JSON.stringify(err)}`)
			}
		)
	}
</script>

<style lang="less" scoped>
	.btnsy {
		background-color: #29175b;
		border-color: #29175b;
	}
</style>
