<script setup>
	import { message } from 'ant-design-vue'
	import { getById } from '@/api/storageJob/ventilation'

	const props = defineProps({
		visible: {
			type: Boolean,
			required: false,
			default: false
		},
		editData: {
			type: Object,
			required: false,
			default: null
		},
		action: {
			type: String,
			required: false,
			default: null
		}
	})

	const isView = computed(() => props.action === 'view')
	const isAdd = computed(() => props.action === 'add')
	const isEdit = computed(() => props.action === 'edit')
	const isApprove = computed(() => props.action === 'approve')
	const readonly = computed(() => {
		return isView.value || isApprove.value
	})

	const show = ref(props.visible)
	const formData = ref({})
	const getData = () => {
		getById(props.editData.id).then((resp) => {
			formData.value = resp
		})
	}

	watch(
		() => props.visible,
		(n, o) => {
			if (n) {
				getData()
			}
			show.value = n
		}
	)

	const emit = defineEmits(['update:visible', 'on-approve'])

	const close = () => emit('update:visible', false)

	const submitLoading = ref(false)

	const save = () => {
		close()
	}
</script>

<template>
	<xn-form-container title="详细信息" width="80%" v-model:visible="show" :destroy-on-close="true" @close="close">
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-divider>详细信息</a-divider>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风作业单号" name="tfzydh">
						<a-input :disabled="readonly" v-model:value="formData.tfzydh" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风日期" name="tfrq">
						<a-date-picker v-model:value="formData.tfrq" format="YYYY-MM-DD" :disabled="readonly" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓房名称" name="cfmc">
						<a-input :disabled="readonly" v-model:value="formData.cfmc" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风目的" name="tfmdName">
						<a-input :disabled="readonly" v-model:value="formData.tfmdName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="粮堆孔隙度" name="kxd">
						<a-input :disabled="readonly" v-model:value="formData.kxd" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风类型" name="tflxName">
						<a-input :disabled="readonly" v-model:value="formData.tflxName" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="风道型式" name="fdxsName">
						<a-input :disabled="readonly" v-model:value="formData.fdxsName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="风网设置方式" name="fwszfs">
						<a-input :disabled="readonly" v-model:value="formData.fwszfs" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="主风道截面积" name="zfdjmj">
						<a-input :disabled="readonly" v-model:value="formData.zfdjmj" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="支风道截面积" name="zfdjmjZhi">
						<a-input :disabled="readonly" v-model:value="formData.zfdjmjZhi" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="支风道总长度" name="zfdzcd">
						<a-input :disabled="readonly" v-model:value="formData.zfdzcd" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="风网开孔率" name="fwkkl">
						<a-input :disabled="readonly" v-model:value="formData.fwkkl" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="空气途径比" name="kqtjb">
						<a-input :disabled="readonly" v-model:value="formData.kqtjb" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风口设置个数" name="tfkszgs">
						<a-input :disabled="readonly" v-model:value="formData.tfkszgs" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风机型号" name="tfjxh">
						<a-input :disabled="readonly" v-model:value="formData.tfjxh" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风机台数" name="tfjts">
						<a-input :disabled="readonly" v-model:value="formData.tfjts" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="单台风机额定全压" name="dtfjedqy">
						<a-input :disabled="readonly" v-model:value="formData.dtfjedqy" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="单台风机额定风量" name="dtfjedfl">
						<a-input :disabled="readonly" v-model:value="formData.dtfjedfl" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="单台风机额定功率" name="dtfjedgl">
						<a-input :disabled="readonly" v-model:value="formData.dtfjedgl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="送风方式" name="sffsName">
						<a-input :disabled="readonly" v-model:value="formData.sffsName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="单台风机实测风量" name="dtfjscfl">
						<a-input :disabled="readonly" v-model:value="formData.dtfjscfl" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="单台风机轴功率" name="dtfjzgl">
						<a-input :disabled="readonly" v-model:value="formData.dtfjzgl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="总风量" name="zfl">
						<a-input :disabled="readonly" v-model:value="formData.zfl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="单位通风量" name="dwtfl">
						<a-input :disabled="readonly" v-model:value="formData.dwtfl" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="实测系统阻力" name="scxtzl">
						<a-input :disabled="readonly" v-model:value="formData.scxtzl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="总耗电量" name="zhdl">
						<a-input :disabled="readonly" v-model:value="formData.zhdl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="作业时气温" name="workTemp">
						<a-input :disabled="readonly" v-model:value="formData.workTemp" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="作业时气湿" name="workWet">
						<a-input :disabled="readonly" v-model:value="formData.workWet" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风时长" name="workTime">
						<a-input :disabled="readonly" v-model:value="formData.workTime" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="作业前平均粮温" name="tfqpjlw">
						<a-input :disabled="readonly" v-model:value="formData.tfqpjlw" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="结束后平均粮温" name="tfhpjlw">
						<a-input :disabled="readonly" v-model:value="formData.tfhpjlw" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="降温幅度" name="jwfd">
						<a-input :disabled="readonly" v-model:value="formData.jwfd" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="吨粮降温能耗" name="dljwnh">
						<a-input :disabled="readonly" v-model:value="formData.dljwnh" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="失水率" name="sslssl">
						<a-input :disabled="readonly" v-model:value="formData.sslssl" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="保水效果评价结果" name="bsxgpjjg">
						<a-input :disabled="readonly" v-model:value="formData.bsxgpjjg" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降温均匀性评价_整仓" name="jyxzx">
						<a-input :disabled="readonly" v-model:value="formData.jyxzx" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风降温均匀性评价_上层" name="jyxsc">
						<a-input :disabled="readonly" v-model:value="formData.jyxsc" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降温均匀性评价_中（间）层" name="jyxzc">
						<a-input :disabled="readonly" v-model:value="formData.jyxzc" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降温均匀性评价_下层" name="jyxxc">
						<a-input :disabled="readonly" v-model:value="formData.jyxxc" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="作业前平均水分" name="tfqpjsf">
						<a-input :disabled="readonly" v-model:value="formData.tfqpjsf" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="结束后平均水分" name="tfhpjsf">
						<a-input :disabled="readonly" v-model:value="formData.tfhpjsf" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="降水幅度" name="jsfd">
						<a-input :disabled="readonly" v-model:value="formData.jsfd" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="吨粮降水能耗" name="dljsnh">
						<a-input :disabled="readonly" v-model:value="formData.dljsnh" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降水均匀性分析_整仓" name="tfjjsjyxfxzc">
						<a-input :disabled="readonly" v-model:value="formData.tfjjsjyxfxzc" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降水均匀性分析_上层" name="tfjsjyxfxsc">
						<a-input :disabled="readonly" v-model:value="formData.tfjsjyxfxsc" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风降水均匀性分析_中（间）层" name="tfjsjyxfxzc">
						<a-input :disabled="readonly" v-model:value="formData.tfjsjyxfxzc" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风降水均匀性分析_下层" name="tfjsjyxfxxc">
						<a-input :disabled="readonly" v-model:value="formData.tfjsjyxfxxc" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="通风作业负责人" name="tfzyfzr">
						<a-input :disabled="readonly" v-model:value="formData.tfzyfzr" />
					</a-form-item>
				</a-col>
			</a-row>

			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="通风作业人员" name="tfzyry">
						<a-input :disabled="readonly" v-model:value="formData.tfzyry" />
					</a-form-item>
				</a-col>
			</a-row>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="close">关闭</a-button>
			<a-button v-if="!readonly" style="margin-right: 8px" type="primary" @click="save" :loading="submitLoading">
				保存
			</a-button>
		</template>
	</xn-form-container>
</template>

<style scoped></style>
