util.js
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* 通用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
}