<template>
	<cl-crud ref="Crud">
		<el-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</el-row>

		<el-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</el-row>

		<el-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</el-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert">
			<!-- <template #slot-layerList="{ scope }">
				<layers-check v-model="scope.atlasName" :type="scope.atlasName" />
			</template> -->
		</cl-upsert>
	</cl-crud>
</template>

<script lang="ts" name="base-atlas" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import LayersCheck from "./components/check.vue";

const { service } = useCool();

// cl-upsert 配置
const Upsert = useUpsert({
	items: [
		{ label: "图集名称", prop: "atlasName", required: true, component: { name: "el-input" } },
		// { label: "图层", prop: "layerList", component: { name: "slot-layerList" } },
		{
			label: "图层",
			prop: "layerList",
			value: [],
			component: { vm: LayersCheck, style: { height: "400px" } }
		},
		{
			label: "图集类型",
			prop: "atlasType",
			required: true,
			component: {
				name: "el-select",
				options: [
					{
						label: "图层",
						value: "图层"
					},
					{
						label: "底图",
						value: "底图"
					}
				]
			}
		}
		// {
		// 	label: "排序号",
		// 	prop: "orderNum",
		// 	required: true,
		// 	component: {
		// 		name: "el-input-number",
		// 		props: {
		// 			placeholder: "请填写排序号",
		// 			min: 0,
		// 			max: 99,
		// 			"controls-position": "right"
		// 		}
		// 	}
		// }
	]
});

// cl-table 配置
const Table = useTable({
	columns: [
		{ type: "selection" },
		// { label: "ID", prop: "id" },
		{ label: "图集名称", prop: "atlasName" },
		// { label: "图层名称", prop: "id" },
		// { label: "创建时间", prop: "createTime" },
		// { label: "更新时间", prop: "updateTime" },
		{ type: "op", buttons: ["edit", "delete"] }
	]
});

// cl-crud 配置
const Crud = useCrud(
	{
		service: service.base.sys.atlas,
		onRefresh(_, { render }) {
			service.base.sys.atlas.distinctList().then((list) => {
				render(list);
			});
		}
	},
	(app) => {
		app.refresh();
	}
);
</script>
