let species = ['xmyl', 'dgyl', 'ddyl', 'ymyl', 'qtyl', 'xmfcpl', 'dmcpl', 'syycpl', 'qtcpl']
// 把接口返回的数组转为table的数组对象格式
export function storageDataFilter(data) {
	let arrData = []
	let rkc = {
		xmyl: { quantity: 0 },
		dgyl: { quantity: 0 },
		ddyl: { quantity: 0 },
		ymyl: { quantity: 0 },
		qtyl: { quantity: 0 },
		xmfcpl: { quantity: 0 },
		dmcpl: { quantity: 0 },
		syycpl: { quantity: 0 },
		qtcpl: { quantity: 0 },
		typeTetx: '日库存（吨）'
	}
	let rckl = {
		xmyl: { quantity: 0 },
		dgyl: { quantity: 0 },
		ddyl: { quantity: 0 },
		ymyl: { quantity: 0 },
		qtyl: { quantity: 0 },
		xmfcpl: { quantity: 0 },
		dmcpl: { quantity: 0 },
		syycpl: { quantity: 0 },
		qtcpl: { quantity: 0 },
		typeTetx: '日出库量（吨）'
	}
	let rrkl = {
		xmyl: { quantity: 0 },
		dgyl: { quantity: 0 },
		ddyl: { quantity: 0 },
		ymyl: { quantity: 0 },
		qtyl: { quantity: 0 },
		xmfcpl: { quantity: 0 },
		dmcpl: { quantity: 0 },
		syycpl: { quantity: 0 },
		qtcpl: { quantity: 0 },
		typeTetx: '日入库量（吨）'
	}
	let cknl = {
		xmyl: { quantity: 0 },
		dgyl: { quantity: 0 },
		ddyl: { quantity: 0 },
		ymyl: { quantity: 0 },
		qtyl: { quantity: 0 },
		xmfcpl: { quantity: 0 },
		dmcpl: { quantity: 0 },
		syycpl: { quantity: 0 },
		qtcpl: { quantity: 0 },
		typeTetx: '出库能力（吨）'
	}
	data.map((item) => {
		// 日库存
		if (item.type == '1') {
			rkc[species[item.grainVariety - 1]] = item
			// 日出库量
		} else if (item.type == '2') {
			rckl[species[item.grainVariety - 1]] = item
			// 日入库量
		} else if (item.type == '3') {
			rrkl[species[item.grainVariety - 1]] = item
			// 出库能力
		} else {
			cknl[species[item.grainVariety - 1]] = item
		}
	})

	arrData.push(rkc, rckl, rrkl, cknl)
	return arrData
}

// 把table的数组对象格式转为接口需要的数组
export function getStorageDataFilter(data) {
	let arr = []
	data.map((item) => {
		for (let key in item) {
			if (item[key].quantity > 0) {
				let obj = item[key]

				if (!obj.type) {
					if (item.typeTetx == '日库存（吨）') {
						obj.type = 1
					} else if (item.typeTetx == '日出库量（吨）') {
						obj.type = 2
					} else if (item.typeTetx == '日入库量（吨）') {
						obj.type = 3
					} else {
						obj.type = 4
					}
				}

				if (!obj.grainVariety) {
					obj.grainVariety = species.indexOf(key) + 1
				}
				arr.push(obj)
			}
		}
	})
	return arr
}
