<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="name"
				:field-list="[
					{
						label: '供应商',
						value: 'name'
					}
				]"
			></cl-search-key>
		</el-row>

		<el-row>
			<cl-table v-bind="table" >
				<!-- <template #column-icon="{ scope }">
					<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-crud>
</template>

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

export default defineComponent({
	name: "rent-computer-shop",

	setup() {
		const service = inject<any>("service");

		// 表单值
		const form = reactive<any>({
			relevance: 1
		});

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

			items: [
				{
					prop: "name",
					label: "供应商",
					span: 20,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写供应商"
						}
					},
					rules: {
						required: true,
						message: "供应商不能为空"
					}
				},
				{
					prop: "description",
					label: "描述",
					span: 20,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写描述",
							type: "textarea",
							rows: 4
						}
					},
					rules: {
						required: true,
						message: "描述不能为空"
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "name",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "name",
					label: "供应商",
					sortable: "true",
					headerAlign: "left",
					align: "left",
					minWidth: 150
				},
				{
					prop: "description",
					label: "描述",
					headerAlign: "left",
					align: "left",
					minWidth: 120
				},
				{
					prop: "createTime",
					label: "创建时间",
					headerAlign: "left",
					align: "left",
					sortable: "custom",
					minWidth: 150
				},
				{
					prop: "updateTime",
					label: "更新时间",
					headerAlign: "left",
					align: "left",
					sortable: "custom",
					minWidth: 150
				},
				{
					label: "操作",
					type: "op"
				}
			]
		});

		// crud 加载
		function onLoad({ ctx, app }: CrudLoad) {
			// console.log(service)
			ctx.service(service.shuyouRentComputerShop).done();
			app.refresh();
		}

		return {
			form,
			upsert,
			table,
			onLoad
		};
	}
});
</script>
