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
| // 提示框
| function modelShow(
| title = '提示',
| content = '确认执行此操作吗?',
| callback = () => {},
| showCancel = true,
| editable = false,
| cancelText = '取消',
| confirmText = '确定',
| placeholderText = '请输入取消原因'
| ) {
| uni.showModal({
| title: title,
| content: content,
| showCancel: showCancel,
| cancelText: cancelText,
| confirmText: confirmText,
| cancelText: cancelText,
| editable: editable,
| placeholderText: placeholderText,
| success: function(res) {
| if (res.confirm) {
| // 用户点击确定操作
| setTimeout(() => {
| callback(res.content)
| }, 500)
| } else if (res.cancel) {
| // 用户取消操作
| }
| }
| })
| }
|
|
| //货币格式化
| function formatMoney(number, places, symbol, thousand, decimal) {
| number = number || 0
| places = !isNaN((places = Math.abs(places))) ? places : 2
| symbol = symbol !== undefined ? symbol : '¥'
| thousand = thousand || ','
| decimal = decimal || '.'
| var negative = number < 0 ? '-' : '',
| i = parseInt((number = Math.abs(+number || 0).toFixed(places)), 10) + '',
| j = (j = i.length) > 3 ? j % 3 : 0
| return (
| symbol +
| negative +
| (j ? i.substr(0, j) + thousand : '') +
| i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) +
| (places ?
| decimal +
| Math.abs(number - i)
| .toFixed(places)
| .slice(2) :
| '')
| )
| }
|
| /**
| * 金额相加
| * @param {Object} value1
| * @param {Object} value2
| */
| function moneySum(value1, value2) {
| return (parseFloat(value1) + parseFloat(value2)).toFixed(2);
| }
| /**
| * 金额相减
| * @param {Object} value1
| * @param {Object} value2
| */
| function moneySub(value1, value2) {
| let res = (parseFloat(value1) - parseFloat(value2)).toFixed(2);
| return res > 0 ? res : 0;
| }
| /**
| * 显示消息提示框
| * @param {Object} params 参数
| */
| function showToast(params = {}) {
| params.title = params.title || ""
| params.icon = params.icon || "none"
| params.position = params.position || 'bottom'
| params.duration = 1500
| uni.showToast(params)
| }
|
| export {
| formatMoney,
| modelShow,
| moneySum,
| moneySub,
| showToast,
| }
|
|