<script setup lang="ts" name="BreedingEgg">
import apis from "@a"
import dayjs from "dayjs"
const tableRef = ref()
const modalRef = ref()

const opts = reactive({
	columns: [
		//{ field: "id", name: "种蛋ID", width: 100, isSort: true, visible: false, tooltip: true },
		{
			field: "coopName",
			name: "鸡舍",
			visible: true,
			isSort: false,
			width: "auto",
			tooltip: true
		},
		{
			field: "batchNum",
			name: "批次号",
			visible: true,
			isSort: false,
			width: "auto",
			tooltip: true
		},
		{
			field: "familyNum",
			name: "家系号",
			visible: true,
			isSort: false,
			width: "auto",
			tooltip: true
		},
		{
			field: "eggType",
			name: "蛋分类",
			visible: true,
			isSort: false,
			width: "auto",
			tooltip: true
		},
		{ field: "eggCount", name: "蛋库数量", visible: true, isSort: false, width: 100 }

		//{ field: "layDate", name: "产蛋日期", visible: true, isSort: false, width: 185 }
		//{ field: "remark", name: "备注", visible: true, isSort: false, tooltip: true },
		//{ field: "actions", name: `操作`, width: 150 }
	] as any[],
	queryParams: {
		coopId: undefined,
		coopNum: undefined,
		batchNum: undefined,
		familyNum: undefined,
		eggType: undefined
	},
	searchFormItems: [
		{
			field: "coopName",
			label: "鸡舍",
			class: "w-100",
			required: false,
			placeholder: "请输入鸡舍",
			component: "I"
		},
		{
			field: "batchNum",
			label: "批次号",
			class: "w-100",
			required: false,
			placeholder: "请输入批次号",
			component: "I"
		},
		{
			field: "familyNum",
			label: "家系号",
			class: "w-100",
			required: false,
			placeholder: "请输入家系号",
			component: "I"
		},
		{
			field: "eggType",
			label: "蛋分类",
			class: "w-100",
			required: false,
			component: "Dict",
			props: {
				placeholder: "请选择蛋分类",
				dictType: "breeding_egg_type",
				type: "select",
				valueIsNumber: 1,
				showAll: true
			}
		}
	] as any,
	permission: "breeding:eggCurrentStore",
	handleBtns: [],
	handleFuns: {
		handleCreate,
		handleUpdate: () => {
			const row = tableRef.value.getSelected()
			handleUpdate(row)
		},
		handleDelete: () => {
			const rows = tableRef.value.getSelecteds()
			handleDelete(rows)
		}
	},
	customBtns: [],
	tableListFun: apis.breeding.eggCurrentStoreApi.list,
	// getEntityFun: apis.breeding.eggCurrentStoreApi.get,
	// deleteEntityFun: apis.breeding.eggCurrentStoreApi.del,
	// exportUrl: apis.breeding.eggCurrentStoreApi.exportUrl,
	exportName: "BreedingEgg",
	modalTitle: "种蛋管理",

	resetForm: () => {},
	labelWidth: "80px"
})

const { queryParams } = toRefs(opts)

/** 搜索按钮操作 */
function handleQuery(query?: any) {
	query = query || tableRef.value?.getQueryParams() || queryParams.value
	addDateRange(query, query.dateRangeLayDate, "LayDate")
	addDateRange(query, query.dateRangeCreateTime)
	addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
	tableRef.value?.query(query)
}

/** 重置按钮操作 */
function resetQuery(query?: any) {
	query = query || tableRef.value?.getQueryParams() || queryParams.value
	query.dateRangeLayDate = [] as any
	addDateRange(query, query.dateRangeLayDate, "LayDate")
	query.dateRangeCreateTime = [] as any
	addDateRange(query, query.dateRangeCreateTime)
	query.dateRangeUpdateTime = [] as any
	addDateRange(query, query.dateRangeUpdateTime, "UpdateTime")
	//
}
function handleCreate() {
	//isEdit.value = false
	tableRef.value.defaultHandleFuns.handleCreate()
}
/** 修改按钮操作 */
function handleUpdate(row: any) {
	//isEdit.value = true
	tableRef.value.defaultHandleFuns.handleUpdate("", row)
}

/** 删除按钮操作 */
function handleDelete(rows: any[]) {
	tableRef.value.defaultHandleFuns.handleDelete("", rows)
}
</script>
<template>
	<div class="app-container">
		<VbDataTable
			ref="tableRef"
			keyField="id"
			:columns="opts.columns"
			:handle-perm="opts.permission"
			:handle-btns="opts.handleBtns"
			:handle-funs="opts.handleFuns"
			:remote-fun="opts.tableListFun"
			:search-form-items="opts.searchFormItems"
			:custom-btns="opts.customBtns"
			:export-name="opts.exportName"
			:modal="modalRef"
			:reset-form-fun="opts.resetForm"
			v-model:query-params="queryParams"
			:check-multiple="true"
			:reset-search-form-fun="resetQuery"
			:custom-search-fun="handleQuery">
			<template #eggType="{ row }">
				<DictTag type="egg_type" :value-is-number="1" :value="row.eggType"></DictTag>
			</template>
		</VbDataTable>
	</div>
</template>
