<script setup>
	import { message } from 'ant-design-vue'
	import { getDetails } from '@/api/grainReserves/businessGslrLossCollect'

	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)
	}
	const isNormal = (type) => {
		switch (type) {
			case 1:
			case '1':
				return '正常'
			case 2:
			case '2':
				return '不正常'
			default:
				return ''
		}
	}
</script>

<template>
	<xn-form-container
		:title="损溢损失信息详情"
		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.sydh" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="业务日期">
						<a-input :disabled="readonly" :value="formData.businessDate" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="库区名称">
						<a-input :disabled="readonly" v-model:value="formData.orgName" />
					</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.storehouseName" />
					</a-form-item>
				</a-col>
				<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="品种">
						<a-input :disabled="readonly" v-model:value="formData.grainVarietyName" />
					</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.grainNatureName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="等级">
						<a-input :disabled="readonly" :value="formData.grainGradeName" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="入库时间">
						<a-input :disabled="readonly" v-model:value="formData.storageTime" />
					</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.netWeightIn" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="出库时间">
						<a-input :disabled="readonly" v-model:value="formData.outboundTime" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="出库净重">
						<a-input :disabled="readonly" v-model:value="formData.netWeightOut" />
					</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.storageYears" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="损溢是否正常">
						<a-input :disabled="readonly" :value="isNormal(formData.isNormalLoss)" />
					</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.moistureIn" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="出库水分">
						<a-input :disabled="readonly" v-model:value="formData.moistureOut" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="水分减量">
						<a-input :disabled="readonly" v-model:value="formData.moistureLoss" />
					</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.impurityIn" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="出库杂质">
						<a-input :disabled="readonly" v-model:value="formData.impurityOut" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="杂质减量">
						<a-input :disabled="readonly" v-model:value="formData.impurityReductionQuality" />
					</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.moistureImpurityLoss" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="实际损耗数量">
						<a-input :disabled="readonly" v-model:value="formData.actualLossQuantity" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="保管自然损耗">
						<a-input :disabled="readonly" v-model:value="formData.naturalLoss" />
					</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.excessLossQuantity" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="存储损耗">
						<a-input :disabled="readonly" v-model:value="formData.storageLoss" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="检查计算数">
						<a-input :disabled="readonly" v-model:value="formData.checkCalculateNumber" />
					</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.lossProfitReason" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="仓储审核人">
						<a-input :disabled="readonly" v-model:value="formData.warehouseAuditor" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="质检审核人">
						<a-input :disabled="readonly" v-model:value="formData.qualityAuditor" />
					</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.statisticsAuditor" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="会计审核人">
						<a-input :disabled="readonly" v-model:value="formData.accountingAuditor" />
					</a-form-item>
				</a-col>
				<a-col :span="8">
					<a-form-item label="领导审核人">
						<a-input :disabled="readonly" v-model:value="formData.leadershipAuditor" />
					</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.remark" />
					</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>
