<template>
	<cl-crud @load="onLoad">
		<el-row type="flex">
			<cl-refresh-btn />
			<!-- <cl-add-btn /> -->
			<!-- <cl-multi-delete-btn /> -->
			<!-- <demo-query-agentOrDirector /> -->
			<cl-flex1 />
			<demo-adv-search-dateActiveSearch />
			<!-- <cl-search-key
				field="name"
				:field-list="[
					{
						label: '日期',
						value: 'new_date'
					}
				]"
			></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";
import dayjs from "dayjs";
import DateActiveSearch from "../components/adv-search-dataActive.vue";
import AgentOrDirector from "../components/adv-search-AgentOrDirector.vue";

export default defineComponent({
	name: "data-active",

	components: {
		"demo-adv-search-dateActiveSearch": DateActiveSearch,
		"demo-query-agentOrDirector": AgentOrDirector
	},

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

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

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

			items: [
				{
					prop: "new_date",
					label: "目标日期",
					span: 6,
					value: dayjs(new Date()).format("YYYY-MM-DD"),
					component: {
						name: "el-date-picker",
						props: {
							type: "date",
							placeholder: "选择日期",
							format: "YYYY-MM-DD",
							valueFormat: "YYYY-MM-DD"
						}
					},
					rules: {
						required: true,
						message: "日期不能为空"
					}
				},
				{
					prop: "sum_new",
					label: "总新增",
					span: 6,
					value: 0,
					component: {
						name: "el-input",
						props: {
							placeholder: "总新增"
						}
					},
					rules: {
						required: true,
						message: "不能为空"
					}
				},
				{
					prop: "sum_active",
					label: "总活跃",
					span: 6,
					value: 0,
					component: {
						name: "el-input",
						props: {
							placeholder: "总活跃"
						}
					},
					rules: {
						required: true,
						message: "不能为空"
					}
				},
				{
					prop: "sum_pay",
					label: "总付费",
					span: 6,
					value: 0,
					component: {
						name: "el-input",
						props: {
							placeholder: "总付费"
						}
					},
					rules: {
						required: true,
						message: "不能为空"
					}
				},
				{
					prop: "remark",
					label: "备注",
					span: 24,
					component: {
						name: "el-input",
						props: {
							placeholder: "请填写备注",
							type: "textarea",
							rows: 4
						}
					}
				}
			]
		});

		// 表格配置
		const table = reactive<Table>({
			props: {
				"default-sort": {
					prop: "total_new",
					order: "descending"
				}
			},
			columns: [
				{
					type: "selection",
					width: 60
				},
				{
					prop: "game_director",
					label: "负责人",
					minWidth: 150
				},
				{
					prop: "game_agent",
					label: "游戏端口",
					minWidth: 150
				},
				{
					prop: "new_date",
					label: "目标日期",
					sortable: "true",
					minWidth: 150
				},
				{
					prop: "target_new",
					label: "目标新增",
					minWidth: 150
				},
				{
					prop: "target_active",
					label: "目标活跃",
					minWidth: 150
				},
				{
					prop: "target_pay",
					label: "目标付费",
					minWidth: 150
				},
				{
					prop: "total_new",
					label: "完成新增",
					minWidth: 150
				},
				{
					prop: "total_active",
					label: "完成活跃",
					minWidth: 150
				},
				{
					prop: "total_pay",
					label: "完成付费",
					minWidth: 150
				}
			]
		});

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

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