<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="card_text"
				:field-list="[
					{
						label: '卡号',
						value: 'card_text'
					}
				]"
			></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 } from "cl-admin-crud-vue3/types";
import { defineComponent, inject, reactive } from "vue";

export default defineComponent({
	name: "sys-role",

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

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

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "id",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "card_text",
					label: "卡号",
					minWidth: 150
				},
				{
					prop: "card_password",
					label: "密码",
					minWidth: 120
				},
				{
					prop: "type_id",
					label: "卡类型",
					minWidth: 120
				},
				{
					prop: "consume",
					label: "消耗金额",
					minWidth: 120
				},
				{
					prop: "occupyTime",
					label: "取走时间",
					sortable: "custom",
					minWidth: 120
				},
				{
					prop: "occupy_task",
					label: "任务",
					sortable: "custom",
					minWidth: 120
				},
				{
					prop: "occupy_acc",
					label: "账号",
					minWidth: 120
				},
				{
					prop: "status",
					label: "状态",
					minWidth: 120,
					dict: [
						{
							label: "已取出",
							value: 2,
							type: "warning"
						},
						{
							label: "已使用",
							value: 3,
							type: "success"
						},
						{
							label: "失效",
							value: 4,
							type: "danger"
						},
						{
							label: "余额不足",
							value: 5,
							type: "danger"
						},
						{
							label: "无法使用",
							value: 6,
							type: "danger"
						},
						{
							label: "已被删除",
							value: 7,
							type: "danger"
						}
					]
				},
				{
					prop: "consumeTime",
					label: "消耗时间",
					sortable: "custom",
					minWidth: 150
				},
				{
					label: "操作",
					type: "op"
				}
			]
		});

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

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