<template>
	<a-drawer
		:title="'设备离线报警详情'"
		:width="600"
		:visible="visible"
		:destroy-on-close="true"
		:footer-style="{ textAlign: 'right' }"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-descriptions :column="1" size="middle" bordered class="mb-2">
				<a-descriptions-item label="设备名称">{{ formData.deviceName }}</a-descriptions-item>
				<a-descriptions-item label="异常信息">{{ formData.alarmMsg }}</a-descriptions-item>
				<a-descriptions-item label="异常时间">{{ formData.createTime }}</a-descriptions-item>
				<a-descriptions-item label="处理状态">{{ formData.saveState }}</a-descriptions-item>
				<a-descriptions-item label="处理信息">{{ formData.saveMsg }}</a-descriptions-item>
				<a-descriptions-item label="处理时间">{{ formData.saveTime }}</a-descriptions-item>
				<a-descriptions-item label="处理图片">
					<a v-if="formData.savePicUrl" :href="formData.savePicUrl" target="_blank">
						<img :src="formData.savePicUrl" alt="avatar" style="max-height: 100px; max-width: 100px"/></a>
				</a-descriptions-item>
			</a-descriptions>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</a-drawer>
</template>

<script setup name="depotDeviceWarnForm">
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import {required} from '@/utils/formRules'
import depotDeviceWarnApi from '@/api/biz/depotDeviceWarnApi'
import sysConfig from "@/config";
// 抽屉状态
const visible = ref(false)
const emit = defineEmits({successful: null})
const formRef = ref()
// 表单数据
const formData = ref({})
const submitLoading = ref(false)

// 打开抽屉
const onOpen = (record) => {
	visible.value = true
	if (record) {
		let recordData = cloneDeep(record)
		formData.value = Object.assign({}, recordData)
		if (formData.value.savePicUrl) {
			// 让其回显
			formData.value.savePicUrl = sysConfig.API_URL + formData.value.savePicUrl
		}
	}
}
// 关闭抽屉
const onClose = () => {
	formRef.value.resetFields()
	formData.value = {}
	visible.value = false
}
// 抛出函数
defineExpose({
	onOpen
})
</script>
