// 数字展示成金额
export function moneyFormat(value, precision = 2) {
	//0
	let num = value
	if (num == 0) {
		return num.toLocaleString();
	}
	if (num) {
		num = typeof num == 'string' ? parseFloat(num) : num
		num = num.toFixed(precision);
		num = parseFloat(num);
		num = num.toLocaleString();
		return num;

	} else {
		return num = null;
	}
}

export function dateFormatFunc(date) {
	if (date != null) {
		const pattern = /(\d{4})(\d{2})(\d{2})/
		let formatedDate = date.replace(pattern, '$1-$2-$3')
		return formatedDate
	}
}

export function datetimeFormat(datetime) {
	//replace方法需要datetime判空 否则前端error 无法展示查询出的数据
	if (datetime != null) {
		const pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
		let formatedDatetime = datetime.replace(pattern, '$1-$2-$3 $4:$5:$6')
		return formatedDatetime
	}
}

export function monthFormat(month) {
	if (month != null) {
		const pattern = /(\d{4})(\d{2})/
		return month.replace(pattern, '$1-$2')
	}
}

export function bopcurFormatFunc(value, config) {
	var obj = {};
	obj = config.find(function (item) {
		return item.value === value;
	});
	if (obj != undefined) {
		return obj.label;
	} else {
		return "";
	}
}

export function instFormat(value, config) {
	var obj = {};
	obj = config.find(function (item) {
		return item.instCode === value;
	});
	if (obj != undefined) {
		return obj.instName;
	} else {
		return "";
	}
}