<template>
	<cl-crud @load="onLoad">
		<el-row type="flex">
			<cl-refresh-btn />
			<cl-add-btn />
			<cl-multi-delete-btn />
			<cl-flex1 />
			<cl-search-key
				field="task_id"
				:field-list="[
					{
						label: '任务ID',
						value: 'task_id'
					},
					{
						label: '电脑编号',
						value: 'pc_num'
					}
				]"
			></cl-search-key>
		</el-row>

		<el-row>
			<cl-table v-bind="table" >
				<!-- <template #column-icon="{ scope }">rent_duration
					<el-image
					    style="width: 100px; height: 100px"
					    :src="scope.row.icon"
					    :preview-src-list="[scope.row.icon]"
					  />
				</template> -->
			</cl-table>
		</el-row>

		<el-row type="flex">
			<cl-flex1 />
			<cl-pagination />
		</el-row>

		<cl-upsert v-model="form" v-bind="upsert">
		</cl-upsert>
	</cl-crud>
</template>

<script lang="ts">
import { CrudLoad, Table, Upsert } from "cl-admin-crud-vue3/types";
import { defineComponent, inject, reactive } from "vue";
import { useRoute } from "vue-router";

export default defineComponent({
	name: "computer_usage",

	setup() {
		const service = inject<any>("service");
		const route = useRoute();
		// 表单值
		const form = reactive<any>({
			relevance: 1
		});

		// 新增、编辑配置
		const upsert = reactive<Upsert>({
			width: "800px",

			items: [
				{
					prop: "task_id",
					label: "任务ID",
					span: 8,
					component: {
						name: "shuyouGameTaskselect",
						props: {
							placeholder: "任务ID"
						}
					}
				},
				{
					prop: "pc_num",
					label: "电脑编号",
					span: 8,
					component: {
						name: "shuyouGameComputerselect",
						props: {
							placeholder: "电脑编号"
						}
					}
				},
				{
					prop: "remark",
					label: "备注",
					span: 24,
					group: "base_msg",
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写备注",
							type: "textarea",
							rows: 3
						}
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "task_id",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "task_id",
					label: "任务id",
					sortable: "true",
					minWidth: 100,
				},
				{
					prop: "task_name",
					label: "任务名称",
					sortable: "true",
					minWidth: 100,
				},
				{
					prop: "pc_name",
					label: "电脑编号",
					sortable: "true",
					minWidth: 120
				},
				
				{
					prop: "remark",
					label: "备注",
					minWidth: 100
				},
				{
					prop: "updateTime",
					label: "更新时间",
					sortable: "custom",
					minWidth: 150
				},
				{
					label: "操作",
					type: "op"
				}
			]
		});

		// crud 加载
		function onLoad({ ctx, app }: CrudLoad) {
			// console.log(route.query)
			ctx.service(service.shuyouComputerUsage).done();
			app.refresh();
		}
		
		return {
			form,
			upsert,
			table,
			onLoad
		};
	}
});
</script>
