<script setup>
import {doAudit, getDetails} from "@/api/basic.info/fumigationFilingApi";
import { message } from 'ant-design-vue'

const houseType = {
	2971: '平房仓',
	2972: '筒仓',
	2973: '浅圆仓',
	2974: '楼房仓',
	2975: '地下仓',
	2976: '气膜仓',
	2977: '球仓',
	2978: '其他粮仓',
	5211: '土堤仓',
	5212: '露天垛',
	5213: '席茓囤',
	5214: '简易囤',
}

const grainType = {
	2777: '大豆',
	3164: '小麦及混合小麦',
	3165: '玉米',
	3166: '稻谷',
	3167: '粟（谷子）',
	3168: '高粱',
	3169: '糙米',
	3170: '大麦和米大麦',
	3171: '不再细分的谷物和杂豆类等',
	3172: '其他谷物',
	7038: '小麦粉',
	7050: '浸出成品油',
	7051: '混合小麦粉',
	7052: '压榨成品油',
	7090: '不另分类的去壳谷物',
	7091: '不另分类的谷物粗粉和粗粒',
	7107: '大米及优质大米',
	7144: '原油',
}

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 = () => props.action === "view"
const isApprove = () => props.action === "approve"

const show = ref(props.visible)
const formData = ref({})
const getData = () => {
	getDetails({id: props.editData.id}).then(resp => {
		console.log(resp)
		formData.value = resp
	})
}

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

const readonly = ref(true)

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

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

const submitLoading = ref(false)

const audit = (status) => {
	submitLoading.value = true
	doAudit({id: props.editData.id, auditStatus: status}).then(resp => {
		emit('on-approve')
		onClose()
		// if(resp.code === 200) {
		//
		// }else {
		// 	message.error(resp.msg)
		// }

	}).finally(_ => {
		submitLoading.value = false
	})
}

const agree = () => {
	audit(1)
}

const reject = () => {
	audit(2)
}

</script>

<template>
	<xn-form-container
		:title="'熏蒸备案详情' + props.action"
		width="80%"
		v-model:visible="show"
		:destroy-on-close="true"
		@close="onClose"
	>
		<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="熏蒸备案单号">
						<a-input :disabled="readonly" :value="formData.orderNumber"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="熏蒸作业库区">
						<a-input :disabled="readonly" :value="formData.orgName"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="单位负责人">
						<a-input :disabled="readonly" v-model:value="formData.dwfzr"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="详细地址">
						<a-input :disabled="readonly" v-model:value="formData.detailAddress"/>
					</a-form-item>
				</a-col>
			</a-row>

			<a-divider>仓房情况</a-divider>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="仓房名称">
						<a-input :disabled="readonly" v-model:value="formData.storehouseName"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓房类型">
						<a-input :disabled="readonly" :value="houseType[formData.storehouseType]"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓房容量">
						<a-input :disabled="readonly" v-model:value="formData.cfrl"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="货位名称">
						<a-input :disabled="readonly" v-model:value="formData.warehouseName"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓房总体积(m³)">
						<a-input :disabled="readonly" v-model:value="formData.outerWallArea"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="粮堆体积(m³)">
						<a-input :disabled="readonly" v-model:value="formData.ldtj"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="气密性">
						<a-input :disabled="readonly" v-model:value="formData.qmx"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="空间体积(m³)">
						<a-input :disabled="readonly" v-model:value="formData.binVolume"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="周围环境">
						<a-input :disabled="readonly" v-model:value="formData.zwhj"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="是否配套环流熏蒸设备">
						<a-input :disabled="readonly" v-model:value="formData.isDev"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-divider>粮情情况</a-divider>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="品种">
						<a-input :disabled="readonly" :value="grainType[formData.subType]"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="数量">
						<a-input :disabled="readonly" v-model:value="formData.numberUpdate"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="入仓时间">
						<a-input :disabled="readonly" v-model:value="formData.inputTime"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="水分(%)">
						<a-input :disabled="readonly" v-model:value="formData.water"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="杂质(%)">
						<a-input :disabled="readonly" v-model:value="formData.impurity"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="平均粮温(℃)">
						<a-input :disabled="readonly" v-model:value="formData.tavg"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="仓温(℃)">
						<a-input :disabled="readonly" v-model:value="formData.inTemp"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓湿(%)">
						<a-input :disabled="readonly" v-model:value="formData.inH"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="堆放形式">
						<a-input :disabled="readonly" v-model:value="formData.dfxs"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-divider>害虫情况</a-divider>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="害虫密度(头/kg)">
						<a-input :disabled="readonly" v-model:value="formData.hcmd"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="分虫种数">
						<a-input :disabled="readonly" v-model:value="formData.fczs"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="发生部位">
						<a-input :disabled="readonly" v-model:value="formData.fsbw"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="虫粮等级">
						<a-input :disabled="readonly" v-model:value="formData.cldj"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-divider>施药情况</a-divider>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="药剂名称">
						<a-input :disabled="readonly" v-model:value="formData.drugName"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="最高粮温(℃)">
						<a-input :disabled="readonly" v-model:value="formData.tmax"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="粮堆单位用药剂量(g/m)">
						<a-input :disabled="readonly" v-model:value="formData.dlyyjl"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="空间单位用药剂量( g/m³)">
						<a-input :disabled="readonly" v-model:value="formData.kjyyjl"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="总用药量(kg)">
						<a-input :disabled="readonly" v-model:value="formData.zyyl"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="施药方法">
						<a-input :disabled="readonly" v-model:value="formData.syff"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="散气时间">
						<a-input :disabled="readonly" v-model:value="formData.sqsj"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="密闭时间">
						<a-input :disabled="readonly" v-model:value="formData.mbsj"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="密闭方式">
						<a-input :disabled="readonly" v-model:value="formData.mbfs"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="熏蒸作业方式">
						<a-input :disabled="readonly" v-model:value="formData.xzzyfs"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="药剂来源">
						<a-input :disabled="readonly" v-model:value="formData.yjly"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="作业人员">
						<a-input :disabled="readonly" v-model:value="formData.zyrr"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="8">
					<a-form-item label="计划熏蒸日期">
						<a-input :disabled="readonly" v-model:value="formData.jhxzrq"/>
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="有效期(天)">
						<a-input :disabled="readonly" v-model:value="formData.yxq"/>
					</a-form-item>
				</a-col>
				<a-col :span="8"
				>
					<a-form-item label="警戒线距离">
						<a-input :disabled="readonly" v-model:value="formData.jjxjl"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="24">
					<a-form-item label="药剂残渣说明">
						<a-input :disabled="readonly" v-model:value="formData.yjczsm"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="24">
					<a-form-item label="粮油仓储单位意见">
						<a-input :disabled="readonly" v-model:value="formData.lyccdwyj"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="12">
					<a-form-item label="单位负责人">
						<a-input :disabled="readonly" v-model:value="formData.dwfzr"/>
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="日期">
						<a-input :disabled="readonly" v-model:value="formData.ccdwrq"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="24">
					<a-form-item label="备案机关意见">
						<a-input :disabled="readonly" v-model:value="formData.bajgyj"/>
					</a-form-item>
				</a-col>
			</a-row>
			<a-row :gutter="42">
				<a-col :span="12">
					<a-form-item label="经办人">
						<a-input :disabled="readonly" v-model:value="formData.jbr"/>
					</a-form-item>
				</a-col>
				<a-col :span="12">
					<a-form-item label="日期">
						<a-input :disabled="readonly" v-model:value="formData.jgrq"/>
					</a-form-item>
				</a-col>
			</a-row>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button v-show="isApprove()" style="margin-right: 8px" type="primary" @click="agree" :loading="submitLoading">
				通过
			</a-button>
			<a-button v-show="isApprove()" type="primary" @click="reject" :loading="submitLoading">驳回</a-button>
		</template>
	</xn-form-container>
</template>

<style scoped>

</style>
