<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="game_name" :field-list="[
				{
					label: '游戏名',
					value: 'game_name'
				},
				{
					label: '游戏端口',
					value: 'game_agent'
				},
				{
					label: '登录方式',
					value: 'login_mode'
				}
			]"></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: "game-list",

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

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

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

			items: [
				{
					label: "警告1:",
					prop: "h",
					component: ({ h }: any) => {
						return h("p", "添加游戏前,请务必搜索此游戏是否已经存在,避免重复添加");
					}
				},
				{
					label: "警告2:",
					prop: "h",
					component: ({ h }: any) => {
						return h("p", "填写游戏名称时,只需要添加游戏真实名称,厂商渠道一律省略,如(笑傲江湖魅族501002,游戏名称就写笑傲江湖)");
					}
				},
				{
					prop: "game_name",
					label: "游戏名称",
					span: 8,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写游戏名称"
						}
					},
					rules: {
						required: true,
						message: "游戏名称不能为空"
					}
				},
				{
					prop: "game_agentId",
					label: "游戏端口",
					span: 8,
					group: "base",
					component: {
						name: "shuyouGameAgentselect",
						props: {
							placeholder: "游戏端口"
						}
					},
					rules: {
						required: true,
						message: "负责人不能为空"
					}
				},
				{
					prop: "login_modeId",
					label: "登录方式",
					span: 8,
					group: "base",
					component: {
						name: "shuyouLoModeselect",
						props: {
							placeholder: "登录方式"
						}
					},
					rules: {
						required: true,
						message: "登录方式不能为空"
					}
				},
				{
					prop: "remark",
					label: "备注",
					span: 20,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写备注",
							type: "textarea",
							rows: 4
						}
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "game_name",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "game_name",
					label: "游戏名称",
					headerAlign: "left",
					align: "left",
					minWidth: 150,
					sortable: "true"
				},
				{
					prop: "game_agent",
					label: "游戏端口",
					headerAlign: "left",
					align: "left",
					minWidth: 120
				},
				{
					prop: "login_mode",
					label: "登录方式",
					headerAlign: "left",
					align: "left",
					minWidth: 120
				},
				{
					prop: "remark",
					label: "备注",
					minWidth: 120
				},
				{
					prop: "createTime",
					label: "创建时间",
					sortable: "custom",
					minWidth: 150
				},
				{
					prop: "updateTime",
					label: "更新时间",
					sortable: "custom",
					minWidth: 150
				},
				{
					label: "操作",
					type: "op"
				}
			]
		});

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

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