<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button
					type="primary"
					icon="el-icon-plus"
					@click="table_add"
					v-auth="'paper.create'"
				></el-button>
			</div>
			<div class="right-panel">
				<el-input
					style="margin-right: 5px"
					v-model="query.search"
					placeholder="名称"
					clearable
				></el-input>
				<el-button
					type="primary"
					icon="el-icon-search"
					@click="handleQuery"
				></el-button>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" :query="query">
				<el-table-column label="名称" prop="name" min-width="300"></el-table-column>
				<el-table-column
					label="限时(分钟)"
					prop="limit"
				></el-table-column>
				<el-table-column
					label="满分"
					prop="total_score"
				></el-table-column>
				<el-table-column
					label="通过分"
					prop="pass_score"
				></el-table-column>
				<el-table-column
					label="单选题数"
					prop="danxuan_count"
				></el-table-column>
				<el-table-column
					label="多选题数"
					prop="duoxuan_count"
				></el-table-column>
				<el-table-column
					label="判断题数"
					prop="panduan_count"
				></el-table-column>
				<el-table-column
					label="操作"
					fixed="right"
					align="center"
					width="150"
				>
					<template #default="scope">
						<el-button
							link
							size="small"
							@click="table_edit(scope.row)"
							v-auth="'paper.update'"
							type="primary"
							>编辑</el-button
						>
						<el-popconfirm
							title="确定删除吗？"
							@confirm="table_del(scope.row, scope.$index)"
						>
							<template #reference>
								<el-button
									link
									size="small"
									v-auth="'paper.delete'"
									type="danger"
									>删除</el-button
								>
							</template>
						</el-popconfirm>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
		<paperDg
			v-if="paperVisiable"
			ref="paperDg"
			@paperSubmit="handleQuery"
		></paperDg>
	</el-container>
</template>
<script>
import paperDg from "./paper_form";
export default {
	components: { paperDg },
	data() {
		return {
			paperVisiable: false,
			apiObj: this.$API.edu.paper.list,
			query: {
				search: "",
			},
		};
	},
	mounted() {},
	methods: {
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		table_add() {
			this.paperVisiable = true;
			this.$nextTick(() => {
				this.$refs.paperDg.open("add");
			});
		},
		table_edit(row) {
			this.paperVisiable = true;

			this.$API.edu.paper.item.req(row.id).then((res) => {
				this.$nextTick(() => {
					this.$refs.paperDg.open("edit", res);
				});
			});
		},
		table_del(row) {
			this.$API.edu.paper.delete.req(row.id).then(() => {
				this.handleQuery();
			});
		},
	},
};
</script>
