vue-filter.js
7.53 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
const util = require('js/plugin/util');
module.exports = (Vue) => {
/**
* 替换参数
*
* @example
* value = /{width}/{height}/{mode}
*
* {value | resize 100 200 2} ==> /100/200/2
*/
Vue.filter('resize', (value, width, height, mode) => util.getImgUrl(value, width, height, mode));
/**
* 性别款式
*
* @example
*
* {value | gender}
*/
Vue.filter('clothingGenderIdentity', (value) => {
let ret = null;
switch (value) {
case 1:
ret = '男款';
break;
case 2:
ret = '女款';
break;
default:
ret = '通用';
}
return ret;
});
/**
* 转换为blk的url
*
* @param value
*/
Vue.filter('transformBlk', (value) => {
let protocol = value.match(/^(https?:)?\/\//);
protocol = protocol && protocol.length ? protocol[0] : '';
value = value.replace(protocol, '');
// 新品抢先看
let query = value.match(/^m\.yohobuy\.com\/product\/blknew(\?.*)?/);
if (query) {
query = query[1] || '';
return `${protocol}m.yohoblk.com/new${query}`;
}
// 全部品类
if (value === 'm.yohobuy.com/cate') {
return `${protocol}m.yohoblk.com/cate-all`;
}
// 全部品牌
if (value === 'm.yohobuy.com/brand' || value === 'm.yohobuy.com/brands') {
return `${protocol}m.yohoblk.com/brand`;
}
// 部分品牌
query = value.match(/^m\.yohobuy\.com\/product\/index\/brand\?(.*)?/);
query = query && query[1] || '';
if (query && query.indexOf('domain=') > -1) {
let domain = query.match(/domain=([^&]*)&?.*?/);
domain = domain[1] || '';
return `${protocol}m.yohoblk.com/product/shop/${domain}?${query}`;
}
let subDomain = value.match(/(.+)\.m\.yohobuy\.com/);
subDomain = subDomain ? subDomain[1] : '';
if (subDomain) {
if (subDomain === 'guang') {
// 逛
let editorialId = value.match(/guang\.m\.yohobuy\.com\/info\/index\?id=(\d{1,})/);
if (editorialId) {
editorialId = editorialId[1];
return `${protocol}m.yohoblk.com/editorial/${editorialId}.html`;
}
} else if (subDomain === 'list') {
// 品类
query = value.match(/\?.*/);
query = query ? query[0] : '';
return `${protocol}m.yohoblk.com/product/list${query}`;
} else {
// 品牌
query = value.match(/\?.*/);
query = query ? query[0] : '';
return `${protocol}m.yohoblk.com/product/shop/${subDomain}${query}`;
}
}
return `${protocol}${value}`;
});
/**
* 品牌URL
*
* @param value brand domain
*/
Vue.filter('brandUrl', (value, kind) => {
let url = `/product/shop/${value}`;
if (kind === 'shop') {
url = `/product/shop/favorite?id=${value || ''}`;
}
return url;
});
/**
* 产品 URL
*/
Vue.filter('goodsUrl', (product, kind) => {
let productId, goodsId, cnAlphabet;
switch (kind) {
case 'collection':
productId = product.product_id;
goodsId = product.goods_id;
cnAlphabet = product.cn_alphabet;
break;
default:
productId = product.product_id;
goodsId = product.goods_list.length ? product.goods_list[0].goods_id : '';
cnAlphabet = product.cn_alphabet;
}
return `/product/pro_${productId}_${goodsId}/${cnAlphabet}.html`;
});
/**
* 订单状态
* @example
* {value | order}
* 状态 0:待付款,1-3:待发货,4-5:待收货(0:未付款,1:已付款,2:备货中,3:配货中,4:已发货,5:运输中,6:已完成)
*/
Vue.filter('convertOrderState', (value) => {
let stateTxt = '';
if (typeof value !== 'undefined') {
value = parseInt(value, 10);
}
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;
default:
stateTxt = '';
break;
}
return stateTxt;
});
Vue.filter('toFixed', (value, num) => {
if (typeof value === 'undefined') {
return;
}
return Number(value).toFixed(num || 2);
});
/**
* 转换时间
* yyyy-MM-dd hh:mm:ss
*/
Vue.filter('convertTime', (value) => {
if (typeof 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() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return Y + M + D + h + m + s;
});
/**
* 格式化时间
*/
Vue.filter('formatUnixTime', (value) => {
// return moment.unix(value).format(format || 'YYYY-MM-DD HH:mm:ss');
if (typeof 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() < 10 ? '0' + date.getDate() : date.getDate();
let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
// let s = date.getSeconds();
// return M + '.' + D + ' ' + h + ' ' + ' ' + m + ' ' + s;
return `${M}.${D} ${h}:${m}`;
});
const zhDict = {
color: '颜色',
gender: '性别',
size: '尺寸',
brand: '品牌',
priceRange: '价格',
group_sort: '品类',
discount: '折扣',
style: '风格',
ageLevel: '年龄'
};
const enDict = {
color: 'Color',
gender: 'Gender',
size: 'Size',
brand: 'Brand',
priceRange: 'Price',
group_sort: 'Category',
discount: 'Sale',
style: 'Style',
ageLevel: 'Age'
};
Vue.filter('filter-cn', (value, prefix) => {
prefix = prefix || '';
value = zhDict[value] || '';
return prefix + value || '';
});
Vue.filter('filter-en-cn', value => {
const cn = zhDict[value] || '';
const en = enDict[value] || '';
return en + cn;
});
};