<template>
	<div class="page bg padding Ipt-2 page-full">
		<el-tabs v-model="activeName">
			<el-tab-pane label="模版详情" name="detail">
				<EditTemplateForm ref="editFormRef" />
			</el-tab-pane>
			<el-tab-pane label="模版点位" name="point">
				<TemplateTaskTable />
			</el-tab-pane>
		</el-tabs>
	</div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import EditTemplateForm from './component/editTemplateForm.vue';
import TemplateTaskTable from './component/templateTaskTable.vue';

import api from '/@/api/ice104/index';
import { ElMessageBox, ElMessage } from 'element-plus';
import { useSearch } from '/@/hooks/useCommonIce104';
import { useRoute } from 'vue-router';
import type { TabsPaneContext } from 'element-plus'

const route = useRoute();
const editFormRef = ref();
const detailFormData = ref({});
const queryRef = ref();
const activeName = ref('detail')

const { params, tableData, getList, loading } = useSearch(api.device.getList, 'data', { title: '' });
getList();

/**
 * 删除
 */
const onDel = (row: any) => {
	ElMessageBox.confirm(`此操作将删除：“${row.title}”，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(async () => {
		await api.device.deleteItem({ number: row.number });
		ElMessage.success('删除成功');
		getList();
	});
};

/**
 * 获取设备详情
 */
const initTemplateInfo = async () => {
	const res = await api.template.detailItem(route.params && route.params.id)
	detailFormData.value = res.data;
	editFormRef.value.open(res.data);
}
// 页面加载时
onMounted(() => {
	initTemplateInfo()
});
</script>