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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import customerDictConversionFilter from "../filtres/customer-dict-conversion.filter";
import mathService from "@/services/math.service";
class ListUtil {
/**
* @Description: 格式化金额
* @author LiuBo
* @date 2021/2/22
* @time 16:27
* @param value 金额数字
* @param precision 保留小数位
*/
doFormatMoney(value: any, precision?: number): string {
precision = precision || 2; // 默认保留两位小数
if (value != null && !isNaN(Number(value))) {
if (precision != null && precision !== 0) {
value = Number(value).toFixed(precision);
}
} else {
return value;
}
let val = String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
if (precision > 3) {
const idx = val.lastIndexOf(".");
val = val.substring(0, idx) + val.substring(idx).replace(/,/g, "");
}
return val;
}
/**
* @Description: 格式化金额
* @author LiuBo
* @date 2021/2/22
* @time 16:27
* @param precision 保留小数位
*/
customerFormatMoney(precision: number): any {
return (row: any, column: any, val: any): string => {
return listUtil.doFormatMoney(val, precision);
};
}
/**
* @Description: 列表中金额格式化方法
* @author LiuBo
* @date 2021/2/22
* @time 16:25
* @param row 列表行
* @param column 列表列
* @param cellValue 当前值
* @param index 当前列索引
* @param precision 保留小数位
*/
formatMoney(row: any, column: any, cellValue: any, index: any, precision?: number): string {
return listUtil.doFormatMoney(cellValue, precision);
}
/**
* @Description: 转换数据字典
* @author LiuBo
* @date 2021/2/22
* @time 21:43
* @param dicName 字典名称
*/
convertDic(dicName: string): any {
return (row: any, column: any, val: any) => {
if (!!val && val.indexOf(",") > 0) {
const dictValues = val.split(",");
const dictions: string[] = [];
dictValues.forEach((item: any) => {
dictions.push(customerDictConversionFilter(item, dicName));
});
// return dictions.join(',') || "字典项为空"; // 去掉‘字典项为空’的描述信息
return dictions.join(",") || "";
} else {
// return customerDictConversionFilter(val, dicName) || "字典项为空"; // 此处调用公共方法进行字典转译 // 去掉‘字典项为空’的描述信息
return customerDictConversionFilter(val, dicName) || ""; // 此处调用公共方法进行字典转译
}
};
}
/**
* @Description: 小数转换百分数
* @author chenminjie
* @date 2021/4/13
* @time 10:37
*/
formatPercent(row: any, column: any, cellValue: any): any {
if (cellValue != null && !isNaN(Number(cellValue)) && cellValue != "") {
return mathService.evaluate(`${cellValue}*${100}`, 4) + "%";
} else {
return "";
}
}
/**
* @Description: 小数转换百分数保留十四位小数
* @author wangyixin
* @date 2021/6/16
* @time 9:02
*/
formatPercentEight(row: any, column: any, cellValue: any): any {
if (cellValue != null && !isNaN(Number(cellValue)) && cellValue != "") {
return mathService.evaluate(`${cellValue}*${100}`, 14) + "%";
} else {
return "";
}
}
}
const listUtil = new ListUtil();
export default listUtil;