Blame view

common/filters.js 3.17 KB
eb4f2617   chenbiao   add filters
1
2
3
4
5
  // 为空处理  return ‘-’
  const tranNull = value => {
  	if (value === null || value === undefined || value === '') return '-'
  	return value
  }
83c49479   chenbiao   add 7月需求
6
7
8
9
10
  // 为空处理  return ‘’
  const tranStrNull = value => {
  	if (value === null || value === undefined || value === '') return ''
  	return value
  }
eb4f2617   chenbiao   add filters
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
  
  /*
      @切割字符串
      @str原字符串
      @num字符位数
  */
  const cutString = (str, num) => {
  	var _str = "";
  	if (str == null) {
  		return "";
  	}
  	if (str.length >= num) {
  		var strN = str.substring(0, num);
  		strN += "...";
  		_str = strN;
  	} else {
  		_str = str;
  	}
  	return _str;
  }
  
  // 钱前面加“¥”
  const RMB = (value) => {
  	if (value === '--' || value === null || value === undefined) return value
  	return `¥${value}`
  }
  
00a21ab7   chenbiao   add 余额明细 接口联调
38
39
40
41
42
43
44
45
  // 处理金额两位小数
  const toFixed2 = value => {
  	if (!value) {
  		return '0.00';
  	} else {
  		return (value / 100).toFixed(2);
  	}
  
eb4f2617   chenbiao   add filters
46
47
  }
  
b398dc4a   chenbiao   add 我的钱包 接口联调
48
49
  // 钱保留两位小数+其他
  const ortherToFixed = num => {
00a21ab7   chenbiao   add 余额明细 接口联调
50
51
52
53
54
55
56
  	if (num === '0' || num === undefined || num === null || num === '' || num === NaN) {
  		return '0.00';
  	} else if (num === -1) {
  		return '其他';
  	} else {
  		return (num / 100).toFixed(2);
  	}
b398dc4a   chenbiao   add 我的钱包 接口联调
57
58
59
  }
  
  
eb4f2617   chenbiao   add filters
60
  // 数字每三位加个逗号
00a21ab7   chenbiao   add 余额明细 接口联调
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  const toThousands = (num) => {
  	var result = [],
  		counter = 0;
  	num = (num || 0).toString().split('');
  	for (var i = num.length - 1; i >= 0; i--) {
  		counter++;
  		result.unshift(num[i]);
  		if (!(counter % 3) && i != 0) {
  			result.unshift(',');
  		}
  	}
  	return result.join('');
  }
  
ed34839c   chenbiao   add 停车缴费 支付页面 接口联调
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
  // 1天1小时1分钟1秒
  const timeFormatter = value => {
  	let time = '';
  	if (null != value && "" != value) {
  		let timer = parseInt(value);
  		if (timer == 0) {
  			return '0秒';
  		}
  		let days = parseInt(timer / (60 * 60 * 24));
  		let hours = parseInt((timer % (60 * 60 * 24)) / (60 * 60));
  		let minutes = parseInt((timer % (60 * 60)) / (60))
  		let seconds = parseInt(timer % (60));		
  		if (days > 0) {
  			time = time + days +'天'; 
  		}
  		if (hours > 0) {
  			time = time + hours +'小时';
  		}
  		if (minutes > 0) {
  			time = time + minutes +'分钟';
  		}
  		if (seconds > 0) {
  			time = time + seconds +'秒';		
  		}
  		return time;
  	}else{
  		return '-'
00a21ab7   chenbiao   add 余额明细 接口联调
102
  	}
ed34839c   chenbiao   add 停车缴费 支付页面 接口联调
103
  	
00a21ab7   chenbiao   add 余额明细 接口联调
104
  }
eb4f2617   chenbiao   add filters
105
  
1bbce61f   刘淇   商户券
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  // 商户卡券类型
  const cardTypeFormate = num => {
  	console.log('1111111111111')
   //  1-单次券,2-时长券,3-满减券,4-金额券,5-包天券,6-折扣券
    if(num == '1'){
   		return '单次券'
    }
    if(num == 2){
      return '时长券'
    }
    if(num == 3){
      return '满减券'
    }
    if(num == 4){
      return '金额券'
    }
    if(num == 5){
      return '包天券'
    }
    if(num == 6){
      return '折扣券'
    }
  
  }
  
83c49479   chenbiao   add 7月需求
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  function formatDateYMD(value) {
  	if (value === null || value === undefined || value === ''){
  		return '-'
  	} else{
  		var date = new Date(value);
  		var y = date.getFullYear(),
  		  m = date.getMonth() + 1,
  		  d = date.getDate(),
  		  h = date.getHours(),
  		  i = date.getMinutes(),
  		  s = date.getSeconds();
  		if (m < 10) { m = '0' + m; }
  		if (d < 10) { d = '0' + d; }
  		if (h < 10) { h = '0' + h; }
  		if (i < 10) { i = '0' + i; }
  		if (s < 10) { s = '0' + s; }
  		var t = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
  		return t;
  	}
   
  }
1bbce61f   刘淇   商户券
152
  
eb4f2617   chenbiao   add filters
153
154
  export default {
  	tranNull,
83c49479   chenbiao   add 7月需求
155
  	tranStrNull,
eb4f2617   chenbiao   add filters
156
157
158
  	RMB,
  	cutString,
  	toFixed2,
b398dc4a   chenbiao   add 我的钱包 接口联调
159
  	ortherToFixed,
eb4f2617   chenbiao   add filters
160
  	toThousands,
ed34839c   chenbiao   add 停车缴费 支付页面 接口联调
161
  	timeFormatter,
83c49479   chenbiao   add 7月需求
162
163
    cardTypeFormate,
  	formatDateYMD,
eb4f2617   chenbiao   add filters
164
  }