<template>
	<!--人员信息管理 -->
	<a-card :bordered="false">
		<div style="cursor: pointer; width: 80px" @click="delCode"><left-outlined />返回</div>
		<br />

		<a-form
			:model="formState"
			name="basic"
			autocomplete="off"
			@finish="onFinish"
			@finishFailed="onFinishFailed"
			v-if="formState"
		>
			<h3>日常检查</h3>
			<a-row>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="仓房名称"
						name="houseName"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!', trigger: 'change' }]"
					>
						<a-input disabled placeholder="请输入仓房名称" v-model:value="formState.houseName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="货位名称"
						name="warehouseName"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input disabled placeholder="请输入货位名称" v-model:value="formState.warehouseName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="粮油品种" name="subTypeName" :label-col="{ span: 10 }">
						<a-input disabled placeholder="请输入粮油品种" v-model:value="formState.subTypeName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="检查日期"
						name="checkTime"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!' }]"
					>
						<a-input disabled placeholder="请输入检查日期" v-model:value="formState.checkTime" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item
						class="form-item"
						label="检查人"
						name="checker"
						:label-col="{ span: 10 }"
						:rules="[{ required: true, message: '请输入!', trigger: 'change' }]"
					>
						<a-input placeholder="请输入检查人" disabled v-model:value="formState.checker" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="保管员" name="bgy" :label-col="{ span: 10 }">
						<a-input placeholder="请输入保管员" disabled v-model:value="formState.bgy" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-row>
				<a-col :span="8">
					<a-form-item class="form-item" label="参与人员" name="cyry" :label-col="{ span: 10 }">
						<a-input placeholder="请输入参与人员" disabled v-model:value="formState.cyry" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item class="form-item" label="天气情况" name="tqqk" :label-col="{ span: 10 }">
						<a-input placeholder="请输入天气情况" disabled v-model:value="formState.tqqk" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="粮温℃" name="lw" :label-col="{ span: 10 }">
						<a-input placeholder="请输入粮温" disabled v-model:value="formState.lw" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="仓温℃" name="cw" :label-col="{ span: 10 }">
						<a-input placeholder="请输入仓温" :disabled="code" v-model:value="formState.cw" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="气温℃" name="qw" :label-col="{ span: 10 }">
						<a-input placeholder="请输入气温" :disabled="code" v-model:value="formState.qw" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="仓内湿%" name="fulfilmentTimes" :label-col="{ span: 10 }">
						<a-input placeholder="请输入仓内湿" :disabled="code" v-model:value="formState.cns" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="仓外湿%" name="cws" :label-col="{ span: 10 }">
						<a-input placeholder="请输入仓外湿%" :disabled="code" v-model:value="formState.cws" />
					</a-form-item>
				</a-col>
			</a-row>
			<!--  -->
			<h3>虫害检查</h3>
			<a-row>
				<a-col :span="8">
					<a-form-item class="form-item" label="部位" name="pestsPosition" :label-col="{ span: 10 }">
						<a-input placeholder="请输入部位" :disabled="code" v-model:value="formState.pestsPosition" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="密度(头/公斤)" name="pestsDensity" :label-col="{ span: 10 }">
						<a-input placeholder="请输入密度(头/公斤)" :disabled="code" v-model:value="formState.pestsDensity" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="害虫虫种" name="pestsSpecies" :label-col="{ span: 10 }">
						<a-input placeholder="请输入害虫虫种" :disabled="code" v-model:value="formState.pestsSpecies" />
					</a-form-item>
				</a-col>
			</a-row>

			<!--  -->
			<h3>其他检查</h3>
			<a-row>
				<a-col :span="8">
					<a-form-item class="form-item" label="雨后检查" name="rainCheck" :label-col="{ span: 10 }">
						<a-input placeholder="请输入雨后检查" :disabled="code" v-model:value="formState.rainCheck" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="鼠雀检查" name="ratfinchCheck" :label-col="{ span: 10 }">
						<a-input placeholder="鼠雀检查" :disabled="code" :value="formState.ratfinchCheck == '0' ? '无' : '有'" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="是否结露" name="sfjl" :label-col="{ span: 10 }">
						<a-input placeholder="请输入是否结露" :disabled="code" :value="formState.sfjl == '0' ? '无' : '有'" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="霉变情况" name="lsmbqk" :label-col="{ span: 10 }">
						<a-input placeholder="请输入霉变情况" :disabled="code" :value="formState.lsmbqk == '0' ? '无' : '有'" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="门" name="rcdoor" :label-col="{ span: 10 }">
						<a-input placeholder="请输入门" :disabled="code" v-model:value="formState.rcdoor" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="窗" name="rcwindow" :label-col="{ span: 10 }">
						<a-input placeholder="请输入窗" :disabled="code" v-model:value="formState.rcwindow" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="灯" name="rclamp" :label-col="{ span: 10 }">
						<a-input placeholder="请输入灯" :disabled="code" v-model:value="formState.rclamp" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="仓房有无渗漏" name="cfywxl" :label-col="{ span: 10 }">
						<a-input placeholder="请输入仓房有无渗漏" :disabled="code" :value="formState.cfywxl == '0' ? '无' : '有'" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="卫生" name="rchygiene" :label-col="{ span: 10 }">
						<a-input placeholder="请输入卫生" :disabled="code" v-model:value="formState.rchygiene" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="查粮走道" name="rccorridor" :label-col="{ span: 10 }">
						<a-input placeholder="请输入查粮走道" :disabled="code" v-model:value="formState.rccorridor" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="是否返潮" name="sffc" :label-col="{ span: 10 }">
						<a-input placeholder="请输入是否返潮" :disabled="code" :value="formState.sffc == '0' ? '无' : '有'" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item class="form-item" label="其他检查" name="otherCheck" :label-col="{ span: 10 }">
						<a-input placeholder="请输入其他检查" :disabled="code" v-model:value="formState.otherCheck" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-row>
				<a-col :span="20">
					<a-form-item class="form-item" label="发现问题及处理情况" name="findQuestion" :label-col="{ span: 4 }">
						<a-textarea
							style="width: 100%; height: 50px"
							placeholder="请输入发现问题及处理情况"
							:disabled="code"
							v-model:value="formState.findQuestion"
						/>
					</a-form-item>
					<a-col :span="4"> </a-col>
				</a-col>
			</a-row>

			<a-form-item>
				<!-- <div class="item-submit">
					<a-button class="btn1" @click="delCode">取消</a-button>
					<a-button :disabled="code" class="btn1" type="primary" html-type="submit">保存</a-button>
				</div> -->
			</a-form-item>
		</a-form>
	</a-card>
</template>
<script setup>
	import { required } from '@/utils/formRules'
	import { onMounted } from 'vue'
	import { reactive, ref, watch } from 'vue'
	import { useRouter, useRoute } from 'vue-router'
	import { defineComponent } from 'vue'
	import business from '@/api/daily/daily.js'
	import { isInteger } from '@/utils/validator'

	const router = useRouter()
	const route = useRoute()
	const formState = ref({})

	const huiXian_managementDel = async () => {
		const res = await business.RCJCgetDailycheckDetail({ id: route.query.id })
		formState.value = res
	}
	const optionsGender = ref([])
	const getGender = async () => {
		const res = await business.XYDAXla()
		optionsGender.value = res
	}
	const code = ref(null)
	const codes = ref(null)
	watch(
		() => route.query.codeTTY,
		async (newVal) => {
			const codeDel = route.query.codeTTY
			if (codeDel == 1) {
				codes.value = true
				code.value = false
			} else if (Boolean(route.query.codeTTY) == true) {
				codes.value = true
				code.value = true
				await huiXian_managementDel()
				console.log(44)
			} else {
				codes.value = false
				code.value = false
			}
		},
		{ immediate: true, deep: true }
	)
	// onMounted(() => {})

	const handleChange = (val) => {
		const d = optionsGender.value.filter((item) => {
			return val == item.unitInfoId
		})
		Object.assign(formState.value, ...d)
	}
	// 新增
	const pustFrom = async (value) => {
		const res = await business.XYDAXadd(value)
	}
	// 编辑
	const pustEdit = async (value) => {
		const res = await business.XYDAXedit(value)
	}

	// 回显示
	const onFinish = (values) => {
		if (route.query.id) {
			pustEdit({ id: route.query.id, ...values })
		} else {
			pustFrom(formState.value)
		}
		delCode()
	}
	const delCode = () => {
		if (formState.value) {
			for (let key in formState.value) {
				formState.value[key] = ''
			}
		}
		router.back()
	}
	const onFinishFailed = (errorInfo) => {
		console.log('Failed:', errorInfo)
	}
</script>
<style lang="less" scoped>
	.item-submit {
		display: flex;
		justify-content: center;
		margin-top: 100px;
		.btn1 {
			width: 100px;
			margin-right: 20px;
		}
	}
	.ant-select {
		width: 250px;
	}
	.ant-input {
		width: 250px;
	}
	.ant-form-item-label {
		width: 150px;
	}
	h3 {
		margin-bottom: 30px;
	}
</style>
