// import { onMounted, ref, onBeforeUnmount, computed, reactive } from 'vue'
import { enumMaplistStore } from '@/store'

export function enumMap() {
	const StoreDEl = enumMaplistStore()
	const { enumMap, parentMap } = StoreDEl.enumMaplist
	const cocName = (id = '') => {
		const name = enumMap[id]
		return name
	}
	const cocID = (id) => {
		const name = enumMap[id]
		return id
	}
	const getEnumByEnumCode = (enumCode) => {
		for (const key of Object.keys(parentMap)) {
			const arr = parentMap[key]
			for (const enumData of arr) {
				if (enumData.enumid == enumCode) {
					// console.log(enumData)
					if (!enumData.enumname) return console.log('取不到')
					// console.log(enumData.enumname)
					return enumData.enumname
				}
			}
		}
		console.warn('没有找到 enum code', enumCode)
		return null
	}
	const getEnumListByEnumId = (enumId) => {
		return parentMap[enumId]
	}

	const YES_NO_3 = [
		{ value: '1', label: '能' },
		{ value: '0', label: '否' },
		{ value: '9', label: '其他或不确定' }
	]

	const cocDEl = (id) => {
		for (const item of YES_NO_3) {
			if (item.value == id) return item.label
		}
	}

	const LEVEL_TYPE_3 = [
		{ value: '1', label: 'Ⅰ级' },
		{ value: '2', label: 'Ⅱ级' },
		{ value: '3', label: 'Ⅲ级' },
		{ value: '4', label: 'Ⅳ级' }
	]

	const cocDElⅣ = (id) => {
		for (const item of LEVEL_TYPE_3) {
			if (item.value == id) return item.label
		}
	}

	const LEVEL_TYPE_5 = [
		{ value: '1', label: 'Ⅰ级' },
		{ value: '2', label: 'Ⅱ级' },
		{ value: '3', label: 'Ⅲ级' },
		{ value: '4', label: '无粮情检测技术' }
	]

	const cocDElⅣV = (id) => {
		for (const item of LEVEL_TYPE_5) {
			if (item.value == id) return item.label
		}
	}

	const TFXTXS = [
		{ value: '0', label: '竖向通风' },
		{ value: '1', label: '横向通风' },
		{ value: '2', label: '径向通风' },
		{ value: '3', label: '全网板通风' },
		{ value: '4', label: '其它' }
	]

	const cocTFXTXS = (id) => {
		for (const item of TFXTXS) {
			if (item.value == id) return item.label
		}
	}
	const DLMXS = [
		{ value: '01', label: '“一字型”挡粮板' },
		{ value: '02', label: '“三角形”挡粮门' },
		{ value: '03', label: '“弧形”挡粮门' },
		{ value: '04', label: '围包' },
		{ value: '05', label: '其它型式' }
	]
	const cocDLMXS = (id) => {
		for (const item of DLMXS) {
			if (item.value == id) return item.label
		}
	}

	const BUG_INSPECTION_TYPE = [
		{ value: '01', label: '远程检测预警' },
		{ value: '02', label: '人工手动筛查' },
		{ value: '03', label: '其它' }
	]
	const cocBUG_INSPECTION_TYPE = (id) => {
		for (const item of BUG_INSPECTION_TYPE) {
			if (item.value == id) return item.label
		}
	}

	const GRANARY_STATUS = [
		{ value: '1', label: '完好' },
		{ value: '2', label: '需小修' },
		{ value: '3', label: '需大修' },
		{ value: '4', label: '待报废' },
		{ value: '5', label: '待拆除' },
		{ value: '6', label: '死角仓' },
		{ value: '9', label: '其他' }
	]

	const cocGRANARY_STATUS = (id) => {
		for (const item of GRANARY_STATUS) {
			if (item.value == id) return item.label
		}
	}
	const PROPERTY_RIGHTS = [
		{ value: '1', label: '自有' },
		{ value: '2', label: '租赁' },
		{ value: '3', label: '共有' },
		{ value: '4', label: '混合' },
		{ value: '9', label: '其他' }
	]
	const cocPROPERTY_RIGHTS = (id) => {
		for (const item of PROPERTY_RIGHTS) {
			if (item.value == id) return item.label
		}
	}
	const YES_NO = [
		{ value: '1', label: '是' },
		{ value: '0', label: '否' }
	]
	const cocYES_NO = (id) => {
		for (const item of YES_NO) {
			if (item.value == id) return item.label
		}
	}

	const JYLB = [
		{ value: '01', label: '入仓验收' },
		{ value: '02', label: '出仓检验' },
		{ value: '03', label: '月末普检' },
		{ value: '04', label: '9 月末普检' },
		{ value: '05', label: '入仓初检' },
		{ value: '06', label: '月度检查' },
		{ value: '07', label: '3 月末库内普查' },
		{ value: '08', label: '9 月末库内普查' },
		{ value: '09', label: '定检' }
	]
	const cocJYLB = (id) => {
		for (const item of JYLB) {
			if (item.value == id) return item.label
		}
	}
	return {
		getEnumListByEnumId,
		cocJYLB,
		cocYES_NO,
		cocPROPERTY_RIGHTS,
		cocName,
		getEnumByEnumCode,
		cocDEl,
		cocDElⅣ,
		cocDElⅣV,
		cocTFXTXS,
		cocDLMXS,
		cocBUG_INSPECTION_TYPE,
		cocGRANARY_STATUS
	}
}
