vue-filter.js
2.28 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
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
108
109
110
111
112
let Vue = require('yoho-vue');
/**
* 替换参数
*
* @example
* value = /{width}/{height}/{mode}
*
* {value | resize 100 200 2} ==> /100/200/2
*/
Vue.filter('resize', (value, width, height, mode)=> {
return value ? value.replace(/(\{width}|\{height}|\{mode})/g, function($0) {
const dict = {
'{width}': width,
'{height}': height,
'{mode}': mode || 2
};
return dict[$0];
}) : '';
});
/**
* 性别款式
*
* @example
*
* {value | gender}
*/
Vue.filter('clothingGenderIdentity', (value)=> {
let ret = null;
switch (value) {
case 1:
ret = '男款';
break;
case 2:
ret = '女款';
break;
default:
ret = '通用';
}
return ret;
});
/**
* 品牌URL
*
* @param value brand domain
*/
Vue.filter('brandUrl', (value)=> {
return `/brand?domain=${value}`;
});
/**
* 订单状态
* @example
* {value | order}
* 状态 0:待付款,1-3:待发货,4-5:待收货(0:未付款,1:已付款,2:备货中,3:配货中,4:已发货,5:运输中,6:已完成)
*/
Vue.filter('convertOrderState', (value) => {
let stateTxt = '';
if (value !== undefined) {
value = parseInt(value);
}
switch (value) {
case 0:
stateTxt = '待付款';
break;
case 1:
stateTxt = '待发货';
break;
case 2:
stateTxt = '待发货';
break;
case 3:
stateTxt = '待发货';
break;
case 4:
stateTxt = '待收货';
break;
case 5:
stateTxt = '待发货';
break;
case 6:
stateTxt = '已完成';
break;
}
return stateTxt;
});
/**
* 转换时间
* yyyy-MM-dd hh:mm:ss
*/
Vue.filter('convertTime', (value) => {
if (value === undefined) {
return;
}
let date = new Date(parseFloat(value) * 1000);
let Y = date.getFullYear() + '-';
let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
let D = date.getDate() + ' ';
let h = date.getHours() + ':';
let m = date.getMinutes() + ':';
let s = date.getSeconds();
return Y + M + D + h + m + s;
});