<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="account_text"
				:field-list="[
					{
						label: '账号',
						value: 'account_text'
					},
					{
						label: '游戏名称',
						value: 'game_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: "game-list",

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

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

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

			items: [
				{
					prop: "account_id",
					label: "账号id",
					span: 8,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写账号id"
						}
					},
					rules: {
						required: true,
						message: "账号id不能为空"
					}
				},
				{
					prop: "game_id",
					label: "游戏id",
					span: 8,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写游戏id"
						}
					},
					rules: {
						required: true,
						message: "游戏id不能为空"
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "game_id",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "account_text",
					label: "账号",
					minWidth: 150,
					sortable: "true"
				},
				{
					prop: "status",
					label: "状态",
					minWidth: 150,
					sortable: "true"
				},
				{
					prop: "game_name",
					label: "游戏名称",
					minWidth: 120
				},
				{
					prop: "game_agentId",
					label: "厂商",
					minWidth: 120
				},
				{
					prop: "login_modeId",
					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.shuyouGameAccountRecord).done();
			app.refresh();
		}

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