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

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

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

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" name="fixtures-mould" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";

const { service, router } = useCool();

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: "页面名称",
			prop: "name",
			required: true,
			component: {
				name: "el-input"
			}
		},
		{
			label: "页面背景色",
			prop: "background",
			value: "#f6f7fa",
			component: {
				name: "el-color-picker",
				props: {
					"show-alpha": true,
					predefine: ["#f6f7fa"]
				}
			}
		},
		{
			label: "页面背景图",
			prop: "backgroundImage",
			component: {
				name: "cl-upload"
			}
		},
		{
			label: "是否首页",
			prop: "isHome",
			required: true,
			value: 0,
			component: {
				name: "el-radio-group",
				options: [
					{
						label: "是",
						value: 1
					},
					{
						label: "否",
						value: 0
					}
				]
			}
		},
		{
			label: "状态栏占位",
			prop: "statusBar",
			value: 1,
			component: {
				name: "el-switch",
				props: {
					"active-text": "显示",
					"inactive-text": "隐藏",
					"active-value": 1,
					"inactive-value": 0,
					"inline-prompt": true,
					style: "--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
				}
			}
		},
		{
			label: "状态栏颜色",
			prop: "statusBarColor",
			value: "#fff",
			component: {
				name: "el-color-picker",
				props: {
					"show-alpha": true,
					predefine: ["#f6f7fa", "rgba(0, 0, 0, 0)"]
				}
			}
		},
		{
			label: "是否启用",
			prop: "status",
			value: 1,
			component: {
				name: "el-switch",
				props: {
					"active-text": "是",
					"inactive-text": "否",
					"active-value": 1,
					"inactive-value": 0,
					"inline-prompt": true,
					style: "--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
				}
			}
		}
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: "页面名称", prop: "name", minWidth: 140 },

		{
			label: "是否首页",
			prop: "isHome",
			minWidth: 140,
			dict: [
				{
					label: "是",
					value: 1,
					type: "primary"
				},
				{
					label: "否",
					value: 0,
					type: "info"
				}
			]
		},
		{ label: "状态", prop: "status", minWidth: 100, component: { name: "cl-switch" } },

		{
			label: "更新时间",
			prop: "updateTime",
			minWidth: 160,
			component: { name: "cl-date-text" }
		},
		{
			type: "op",
			width: 240,
			buttons: [
				{
					label: "装修",
					onClick(data: any) {
						router.push("/fixtures/mould/edit?id=" + data.scope.row.id);
					}
				},
				"edit",
				"delete"
			]
		}
	]
});

// cl-crud
const Crud = useCrud(
	{
		service: service.fixtures.mould
	},
	(app) => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
