util.js 1.93 KB
/**
 * 通用js方法封装处理
 */

// 时间格式化
export function formatTime(date) {
	if (date == null || date == "") return "";
	var date = new Date(date)
	var year = date.getFullYear()
	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
	var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
	var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
	var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
	return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}

// 日期格式化
export function formatDate(date) {
	if (date == null || date == "") return "";
	var date = new Date(date)
	var year = date.getFullYear()
	var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
	return year + '年' + month + '月' + day + '日'
}

// 回显数据字典
export function selectDictLabel(datas, value) {
	var actions = [];
	Object.keys(datas).some((key) => {
		if (datas[key].dictValue == ('' + value)) {
			actions.push(datas[key].dictLabel);
			return true;
		}
	})
	return actions.join('');
}

// 回显货主、入库类型、出库类型、出库流程、供应商字典、仓库、入库流程、盘点方式、物料类型
export function selectCommonLabel(datas, value) {
	let actions = [];
	Object.keys(datas).some((key) => {
		if (datas[key].code == (value)) {
			actions.push(datas[key].name);
			return true;
		}
	})
	return actions.join('');
}

// 数组去重
export function unique(array) {
	let newArr = [];
	array.forEach(el => {
		const result = newArr.findIndex(ol => {
			return el.id === ol.id
		})
		if (result !== -1) {
			newArr[result].qty = newArr[result].qty + el.qty

		} else {
			newArr.push(el)
		}
	})
	return newArr
}