<template>
	<div>
		<!--增、查交易记录的按钮-->
<!--		<el-button type="primary" round @click="openAddDialog" size="small">添加</el-button>-->
<!--		<el-row>-->
<!--			<el-col :span="24">-->
<!--				<el-form :inline="true" :model="state.query" class="demo-form-inline">-->
<!--					<el-form-item label="电影名称：">-->
<!--						<el-input v-model="state.query.title" placeholder="请输入电影名称" clearable @input="init" />-->
<!--					</el-form-item>-->
<!--				</el-form>-->
<!--			</el-col>-->
<!--		</el-row>-->
		<!--表格-->
		<el-row>
			<el-col :span="24">
				<el-table :data="state.getList">
					<!--					列表结开始-->
					<el-table-column prop="item.id" label="编号" align="center" width="120px"/>
					<el-table-column prop="item.title" label="名称" align="center" width="120px"/>
					<el-table-column prop="userEntity.nickName" label="用户昵称" align="center" width="120px" />
					<el-table-column prop="itemDTO.largePic" label="图片" align="center" width="100" >
						<template #default="{ row }">
							<!-- 点击图片后显示弹框预览 -->
							<el-image
								:src="row.item.image"
								fit="cover"
							/>
						</template>
					</el-table-column>
					<el-table-column prop="score" label="评分" align="center" />
					<el-table-column prop="content" label="评论内容" align="center">
						<template #default="scope">
							<div style="width: 100%;  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
								{{ scope.row.content }}
							</div>
						</template>

					</el-table-column>
					<!--列表结束-->
					<el-table-column label="操作" align="center" width="120px">
						<template #default="scope">
							<el-button @click="del(scope.row.id)" type="danger" size="small">删除</el-button>
						</template>
					</el-table-column>
					<template v-slot:empty>
						<el-empty description="数据去外太空了~" />
					</template>
				</el-table>
				<!-- 分页控件 -->
				<el-pagination
					v-if="state.query.total > 0"
					:current-page="state.query.page"
					:page-size="state.query.limit"
					:total="state.query.total"
					background layout="prev, pager, next"
					@current-change="handlePageChange"
				/>
			</el-col>
		</el-row>


	</div>
</template>
<script setup lang="ts">

const state = reactive({
	route:"sys/order",
	dialogVisible:false,
	getList: [],//获取数据
	query:{
		total: 0, // 总记录数
		page: 1, // 当前页码
		limit: 10, // 每页显示的记录数
		title:"",
		type:"0",
		orderStatus:3
	}
})

// 获取交易记录
const init = () => {
	adminRequest.get(`${state.route}/page`, {
		params: state.query
	}).then((res:any) => {
		state.getList = res.data.list
		state.query.total = res.data.total
		console.log(state.getList)
	})
}


// 删除交易记录
const del = async (id: number) => {
	try {
		await adminRequest.delete(`${state.route}/${id}`)
		init()
		ElMessage.success("删除成功~")
	} catch (error) {
		ElMessage.error("删除失败~")
	}
}

// 页码改变时的处理函数
const handlePageChange = (page: number) => {
	state.query.page = page
	init()
}
// 页面加载时获取交易记录
onMounted(() => {
	init()
})
</script>
<style scoped>
.dialog-footer {
	text-align: right;
}
:deep(.el-upload) {
	border: 1px dashed var(--el-border-color);
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
	transition: var(--el-transition-duration-fast);
}

:deep(.el-upload:hover) {
	border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	text-align: center;
}
.avatar{
	width: 178px;
  height: 178px;
  object-fit: cover;
}

</style>
<route lang="json">
{
"meta": {
"layout": "admin"
}
}
</route>
