ftdsy-attr 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/.idea/52Attr.iml +12 -0
- package/.idea/dictionaries +6 -0
- package/.idea/modules.xml +8 -0
- package/dist/ftdsy-attr.js +1740 -0
- package/dist/ftdsy-attr.js.map +1 -0
- package/dist/index.html +12 -0
- package/package.json +27 -0
- package/rollup.config.js +52 -0
- package/src/config/platform.js +101 -0
- package/src/main.js +590 -0
- package/src/platform/1688.js +0 -0
- package/src/platform/dy.js +156 -0
- package/src/platform/jd.js +0 -0
- package/src/platform/ks.js +0 -0
- package/src/platform/pdd.js +152 -0
- package/src/platform/sph.js +0 -0
- package/src/platform/tb.js +321 -0
- package/src/platform/tm.js +0 -0
- package/src/platform/xhs.js +0 -0
- package/src/platform/xp.js +0 -0
- package/src/tools/property.js +351 -0
- package/src/utils/utils.js +111 -0
|
@@ -0,0 +1,1740 @@
|
|
|
1
|
+
|
|
2
|
+
(function(l, r) { if (!l || l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (self.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.getElementsByTagName('head')[0].appendChild(r) })(self.document);
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function _arrayWithoutHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
10
|
+
}
|
|
11
|
+
function _iterableToArray(r) {
|
|
12
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
13
|
+
}
|
|
14
|
+
function _nonIterableSpread() {
|
|
15
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
16
|
+
}
|
|
17
|
+
function _toConsumableArray(r) {
|
|
18
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
19
|
+
}
|
|
20
|
+
function _typeof(o) {
|
|
21
|
+
"@babel/helpers - typeof";
|
|
22
|
+
|
|
23
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
24
|
+
return typeof o;
|
|
25
|
+
} : function (o) {
|
|
26
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
27
|
+
}, _typeof(o);
|
|
28
|
+
}
|
|
29
|
+
function _unsupportedIterableToArray(r, a) {
|
|
30
|
+
if (r) {
|
|
31
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
32
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
33
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var platformList = [{
|
|
38
|
+
id: 1,
|
|
39
|
+
title: '拼多多',
|
|
40
|
+
code: 'pdd',
|
|
41
|
+
shopType: 1
|
|
42
|
+
}, {
|
|
43
|
+
id: 2,
|
|
44
|
+
title: '淘宝',
|
|
45
|
+
code: 'tb',
|
|
46
|
+
shopType: 1
|
|
47
|
+
}, {
|
|
48
|
+
id: 2,
|
|
49
|
+
title: '天猫',
|
|
50
|
+
code: 'tm',
|
|
51
|
+
shopType: 2
|
|
52
|
+
}, {
|
|
53
|
+
id: 3,
|
|
54
|
+
title: '京东',
|
|
55
|
+
code: 'jd',
|
|
56
|
+
shopType: 1
|
|
57
|
+
}, {
|
|
58
|
+
id: 4,
|
|
59
|
+
title: '抖音',
|
|
60
|
+
code: 'dy',
|
|
61
|
+
shopType: 1
|
|
62
|
+
}, {
|
|
63
|
+
id: 5,
|
|
64
|
+
title: '虾皮',
|
|
65
|
+
code: 'xp',
|
|
66
|
+
shopType: 1
|
|
67
|
+
}, {
|
|
68
|
+
id: 6,
|
|
69
|
+
title: '小红书',
|
|
70
|
+
code: 'xhs',
|
|
71
|
+
shopType: 1
|
|
72
|
+
}, {
|
|
73
|
+
id: 7,
|
|
74
|
+
title: '快手',
|
|
75
|
+
code: 'ks',
|
|
76
|
+
shopType: 1
|
|
77
|
+
}, {
|
|
78
|
+
id: 8,
|
|
79
|
+
title: '52电商园',
|
|
80
|
+
code: 'dsy',
|
|
81
|
+
shopType: 1
|
|
82
|
+
}, {
|
|
83
|
+
id: 9,
|
|
84
|
+
title: '1688',
|
|
85
|
+
code: '1688',
|
|
86
|
+
shopType: 1
|
|
87
|
+
}, {
|
|
88
|
+
id: 10,
|
|
89
|
+
title: '虾皮本土',
|
|
90
|
+
code: 'xpbt',
|
|
91
|
+
shopType: 1
|
|
92
|
+
}, {
|
|
93
|
+
id: 11,
|
|
94
|
+
title: '淘工厂',
|
|
95
|
+
code: 'tgc',
|
|
96
|
+
shopType: 1
|
|
97
|
+
}, {
|
|
98
|
+
id: 12,
|
|
99
|
+
title: '微信小店',
|
|
100
|
+
code: 'sph',
|
|
101
|
+
shopType: 1
|
|
102
|
+
}, {
|
|
103
|
+
id: 13,
|
|
104
|
+
title: 'TikTok',
|
|
105
|
+
code: 'tk',
|
|
106
|
+
shopType: 1
|
|
107
|
+
}];
|
|
108
|
+
function checkPlatform(pt_type) {
|
|
109
|
+
var platform;
|
|
110
|
+
if (pt_type instanceof Number) {
|
|
111
|
+
// 通过平台id查询
|
|
112
|
+
platform = platformList.find(function (item) {
|
|
113
|
+
return item.id == pt_type;
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
// 通过平台code查询
|
|
117
|
+
platform = platformList.find(function (item) {
|
|
118
|
+
return item.code === pt_type;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return platform;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var utils = {
|
|
125
|
+
/**
|
|
126
|
+
* 获取2个字符串的相似度
|
|
127
|
+
* @param {string} str1 字符串1
|
|
128
|
+
* @param {string} str2 字符串2
|
|
129
|
+
* @returns {number} 相似度
|
|
130
|
+
*/
|
|
131
|
+
getStringSimilarity: function getStringSimilarity(str1, str2) {
|
|
132
|
+
var sameNum = 0;
|
|
133
|
+
//寻找相同字符
|
|
134
|
+
for (var i = 0; i < str1.length; i++) {
|
|
135
|
+
for (var j = 0; j < str2.length; j++) {
|
|
136
|
+
if (str1[i] === str2[j]) {
|
|
137
|
+
sameNum++;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//判断2个字符串哪个长度比较长
|
|
143
|
+
var length = str1.length > str2.length ? str1.length : str2.length;
|
|
144
|
+
return sameNum / length * 100 || 0;
|
|
145
|
+
},
|
|
146
|
+
/* 调用计算公式 */evil: function evil(str) {
|
|
147
|
+
var fn = Function;
|
|
148
|
+
return new fn('return ' + str)();
|
|
149
|
+
},
|
|
150
|
+
/* 检测值,true: 正常,false: 未选 */checkValue: function checkValue(value) {
|
|
151
|
+
try {
|
|
152
|
+
if (!value) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (value === '' || value === null || value === undefined) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (value instanceof Array) {
|
|
159
|
+
return value.length > 0;
|
|
160
|
+
}
|
|
161
|
+
if (value instanceof Object) {
|
|
162
|
+
return Object.keys(value).length > 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 其他情况
|
|
166
|
+
return true;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
//TODO handle the exception
|
|
169
|
+
console.log(error);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* 判断字符串中是否包含某些字符
|
|
175
|
+
*
|
|
176
|
+
* @param {String} text 检测字符串
|
|
177
|
+
* @param {Array} arr 检测内容字符串数组
|
|
178
|
+
* @param {string} type 检测方式,includeOne:包含一个,includeAll:包含全部,默认为 includeOne
|
|
179
|
+
* */
|
|
180
|
+
isTextInclude: function isTextInclude(text, arr) {
|
|
181
|
+
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'includeOne';
|
|
182
|
+
if (Object.prototype.toString.call(text) !== '[object String]') throw new Error('text 参数错误有误,只能是String类型');
|
|
183
|
+
if (Object.prototype.toString.call(arr) !== '[object Array]') throw new Error('arr 参数错误有误,只能是Array类型');
|
|
184
|
+
if (type === 'includeOne') {
|
|
185
|
+
return arr.some(function (i) {
|
|
186
|
+
return text.indexOf(i) > -1;
|
|
187
|
+
});
|
|
188
|
+
} else if (type === 'includeAll') {
|
|
189
|
+
return arr.filter(function (i) {
|
|
190
|
+
return text.indexOf(i) > -1;
|
|
191
|
+
}).length === arr.length;
|
|
192
|
+
} else {
|
|
193
|
+
throw new Error('type 参数错误有误,只能是includeOne或includeAll');
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* 获取文本长度
|
|
198
|
+
*
|
|
199
|
+
* @param {String} text 待检查的字符串
|
|
200
|
+
* @param {Number} max 当text不是字符时返回的数字
|
|
201
|
+
* */
|
|
202
|
+
getTextLength: function getTextLength(text) {
|
|
203
|
+
var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
204
|
+
if (Object.prototype.toString.call(text) === '[object String]') {
|
|
205
|
+
var length = 0;
|
|
206
|
+
for (var i = 0; i < text.length; i++) {
|
|
207
|
+
if (text.charAt(i).match(/[^\x00-\xff]/gi) != null) {
|
|
208
|
+
length += 2;
|
|
209
|
+
} else {
|
|
210
|
+
length += 1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return length;
|
|
214
|
+
} else if (max === undefined) {
|
|
215
|
+
throw new Error('getTextLength 参数必须为字符串');
|
|
216
|
+
}
|
|
217
|
+
return max;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
var pdd = {
|
|
222
|
+
createCategoryProperties: createCategoryProperties$3
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 根据拼多多分类规则与属性,生成自定义 上货属性
|
|
227
|
+
* */
|
|
228
|
+
function createCategoryProperties$3(categoryPropertys) {
|
|
229
|
+
// 是否包含了子分类
|
|
230
|
+
var hasChildren = false;
|
|
231
|
+
var propertys = categoryPropertys.filter(function (item) {
|
|
232
|
+
return !item.is_sale;
|
|
233
|
+
}).map(function (item) {
|
|
234
|
+
if ((item === null || item === void 0 ? void 0 : item.property_id) !== undefined && (item === null || item === void 0 ? void 0 : item.property_value) !== undefined && item.property_type !== undefined) {
|
|
235
|
+
if (item !== null && item !== void 0 && item.show_condition.length) {
|
|
236
|
+
// 有条件,即为 子属性
|
|
237
|
+
hasChildren = true;
|
|
238
|
+
}
|
|
239
|
+
return item;
|
|
240
|
+
}
|
|
241
|
+
var property_values = [];
|
|
242
|
+
if (item.values) {
|
|
243
|
+
// 选项列表
|
|
244
|
+
property_values = item.values.map(function (value) {
|
|
245
|
+
return {
|
|
246
|
+
name: value.value,
|
|
247
|
+
value_id: value.vid,
|
|
248
|
+
value: value.vid,
|
|
249
|
+
parent_value: value.parent_vids ? value.parent_vids : []
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
var property_type = 0;
|
|
254
|
+
var property_units = item.value_unit.filter(function (unitItem) {
|
|
255
|
+
return unitItem;
|
|
256
|
+
});
|
|
257
|
+
var property_unit = property_units.length ? property_units[0] : '';
|
|
258
|
+
var select_max_num = 0;
|
|
259
|
+
var input_max_num = 0;
|
|
260
|
+
var input_type = '';
|
|
261
|
+
var input_format = '';
|
|
262
|
+
var date_format = '';
|
|
263
|
+
if (item.choose_max_num == 0) {
|
|
264
|
+
// 文本
|
|
265
|
+
if (item.property_value_type == 5) {
|
|
266
|
+
// 日期(拼多多日期格式为‘yyyy-MM-dd’, 目前仅发现”生产日期“)
|
|
267
|
+
property_type = 5;
|
|
268
|
+
date_format = "yyyy-MM-dd";
|
|
269
|
+
} else if (property_unit) {
|
|
270
|
+
// 有带单位 (拼多多 仅发现整数输入)
|
|
271
|
+
property_type = 4;
|
|
272
|
+
input_type = 'number';
|
|
273
|
+
} else {
|
|
274
|
+
// 纯文本
|
|
275
|
+
property_type = 1;
|
|
276
|
+
input_max_num = Number(item.max_value); // “input_max_num“ 不可用,一直为0
|
|
277
|
+
}
|
|
278
|
+
} else if (item.choose_max_num == 1) {
|
|
279
|
+
// 单选
|
|
280
|
+
property_type = 2;
|
|
281
|
+
select_max_num = 1;
|
|
282
|
+
} else if (item.choose_max_num > 1) {
|
|
283
|
+
// 多选
|
|
284
|
+
property_type = 3;
|
|
285
|
+
select_max_num = item.choose_max_num;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 显示条件
|
|
289
|
+
var show_condition = [];
|
|
290
|
+
if (item.show_condition) {
|
|
291
|
+
// 当前属性,条件
|
|
292
|
+
show_condition = item.show_condition.map(function (conditionItem) {
|
|
293
|
+
return {
|
|
294
|
+
parent_property_id: conditionItem.parent_ref_pid,
|
|
295
|
+
parent_property_value: conditionItem.parent_vids
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (show_condition.length) {
|
|
300
|
+
// 有条件,即为 子属性
|
|
301
|
+
hasChildren = true;
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
property_id: item.ref_pid,
|
|
305
|
+
// 属性id
|
|
306
|
+
property_required: item.required,
|
|
307
|
+
// 是否必填
|
|
308
|
+
property_name: item.name,
|
|
309
|
+
// 属性名称
|
|
310
|
+
|
|
311
|
+
property_values: property_values,
|
|
312
|
+
// 属性可选值列表
|
|
313
|
+
property_type: property_type,
|
|
314
|
+
// 属性类型,0:未知 1:文本,2:单选,3:多选, 4:单位输入(数字)5:日期选择,6:组合多选
|
|
315
|
+
property_value: undefined,
|
|
316
|
+
// 属性值(根据具体属性类型,属性值类型不同)
|
|
317
|
+
|
|
318
|
+
property_unit: property_unit,
|
|
319
|
+
// 单位
|
|
320
|
+
property_units: property_units,
|
|
321
|
+
// 单位列表
|
|
322
|
+
|
|
323
|
+
select_max_num: select_max_num,
|
|
324
|
+
// 最多选择多少个选项(多选,组合多选使用)
|
|
325
|
+
select_custom: false,
|
|
326
|
+
// 是否支持自定义选项
|
|
327
|
+
|
|
328
|
+
input_max_num: input_max_num,
|
|
329
|
+
// 输入文本最大字数(纯文本输入使用)
|
|
330
|
+
input_num: 0,
|
|
331
|
+
// 当前文本输入字数
|
|
332
|
+
|
|
333
|
+
input_type: input_type,
|
|
334
|
+
// 输入类型(单位输入使用),number: 整数,float: 价格
|
|
335
|
+
|
|
336
|
+
input_format: input_format,
|
|
337
|
+
// 输入格式(单位输入使用)
|
|
338
|
+
input_min_value: '',
|
|
339
|
+
// 范围输入,最小值
|
|
340
|
+
input_max_value: '',
|
|
341
|
+
// 范围输入,最大值
|
|
342
|
+
|
|
343
|
+
date_format: date_format,
|
|
344
|
+
// 日期格式(日期使用)
|
|
345
|
+
|
|
346
|
+
has_children: false,
|
|
347
|
+
// 没有子属性,
|
|
348
|
+
show_condition: show_condition,
|
|
349
|
+
// 显示条件,有数据即为子属性
|
|
350
|
+
condition_values: [] // 子属性根据父属性筛选后的 选项列表
|
|
351
|
+
};
|
|
352
|
+
});
|
|
353
|
+
if (hasChildren) {
|
|
354
|
+
// 当前属性列表中存在 子属性,给子属性的父属性设置
|
|
355
|
+
propertys.forEach(function (item) {
|
|
356
|
+
if (item.show_condition.length) {
|
|
357
|
+
// 当前属性为 子属性, 找到父属性
|
|
358
|
+
item.show_condition.forEach(function (conditionItem) {
|
|
359
|
+
var result = propertys.find(function (propertyItem) {
|
|
360
|
+
return propertyItem.property_id === conditionItem.parent_property_id;
|
|
361
|
+
});
|
|
362
|
+
if (result) {
|
|
363
|
+
// 找到父属性,并设置父属性 有子属性标识
|
|
364
|
+
result.has_children = true;
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// 排序 子属性放至最前面 (方便后续分组)
|
|
369
|
+
var index = propertys.findIndex(function (propertyItem) {
|
|
370
|
+
return propertyItem.property_id === item.property_id;
|
|
371
|
+
});
|
|
372
|
+
if (index != -1) {
|
|
373
|
+
propertys.splice(index, 1);
|
|
374
|
+
propertys.unshift(item);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
// console.log("自定义属性列表", JSON.stringify(propertys))
|
|
380
|
+
return propertys;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
var tb = {
|
|
384
|
+
createCategoryProperties: createCategoryProperties$2
|
|
385
|
+
};
|
|
386
|
+
function createCategoryProperties$2(categoryPropertys) {
|
|
387
|
+
console.log(categoryPropertys);
|
|
388
|
+
var propertys = categoryPropertys.map(function (item) {
|
|
389
|
+
if (item !== null && item !== void 0 && item.property_id && item !== null && item !== void 0 && item.property_name && item !== null && item !== void 0 && item.property_type) {
|
|
390
|
+
// 已经转换为自定义完成
|
|
391
|
+
return item;
|
|
392
|
+
}
|
|
393
|
+
if (!item.values) {
|
|
394
|
+
item.values = [];
|
|
395
|
+
}
|
|
396
|
+
var property_required = false;
|
|
397
|
+
var select_max_num = 0;
|
|
398
|
+
var input_max_num = 0;
|
|
399
|
+
var has_children = false;
|
|
400
|
+
if (item.rules) {
|
|
401
|
+
var _item$rules;
|
|
402
|
+
// 属性有规则
|
|
403
|
+
var rule = ((_item$rules = item.rules) === null || _item$rules === void 0 ? void 0 : _item$rules.rule) || [];
|
|
404
|
+
var ruleList = [];
|
|
405
|
+
if (rule instanceof Array) {
|
|
406
|
+
ruleList = _toConsumableArray(rule);
|
|
407
|
+
} else {
|
|
408
|
+
ruleList = [rule];
|
|
409
|
+
}
|
|
410
|
+
ruleList.forEach(function (ruleItem) {
|
|
411
|
+
if (ruleItem.name === 'requiredRule') {
|
|
412
|
+
// 有找到必须标识
|
|
413
|
+
property_required = Boolean(ruleItem.value);
|
|
414
|
+
} else if (ruleItem.name === 'maxLengthRule') {
|
|
415
|
+
// 输入限制
|
|
416
|
+
input_max_num = Number(ruleItem.value);
|
|
417
|
+
} else if (ruleItem.name === 'maxInputNumRule') {
|
|
418
|
+
// 选择限制
|
|
419
|
+
select_max_num = Number(ruleItem.value);
|
|
420
|
+
} else if (ruleItem.name === 'devTipRule') {
|
|
421
|
+
// 有子属性
|
|
422
|
+
has_children = true;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// if (rule instanceof Array) {
|
|
427
|
+
// // 数组
|
|
428
|
+
|
|
429
|
+
// } else {
|
|
430
|
+
// // 对象
|
|
431
|
+
// if (rule.name === 'requiredRule') {
|
|
432
|
+
// // 有找到必须标识
|
|
433
|
+
// property_required = Boolean(rule.value)
|
|
434
|
+
// } else if (rule.name === 'maxLengthRule') {
|
|
435
|
+
// // 输入限制
|
|
436
|
+
// input_max_num = Number(rule.value)
|
|
437
|
+
// } else if (rule.name === 'maxInputNumRule') {
|
|
438
|
+
// // 选择限制
|
|
439
|
+
// select_max_num = Number(rule.value)
|
|
440
|
+
// }
|
|
441
|
+
// }
|
|
442
|
+
}
|
|
443
|
+
var property_values = [];
|
|
444
|
+
if (item.options) {
|
|
445
|
+
// 单选,多选
|
|
446
|
+
if (item.options.option) {
|
|
447
|
+
var option = item.options.option;
|
|
448
|
+
if (option instanceof Array) {
|
|
449
|
+
property_values = item.options.option.map(function (value) {
|
|
450
|
+
return {
|
|
451
|
+
name: value.displayName,
|
|
452
|
+
value_id: value.value,
|
|
453
|
+
value: value.value
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
} else {
|
|
457
|
+
property_values = [{
|
|
458
|
+
name: option.displayName,
|
|
459
|
+
value_id: option.value,
|
|
460
|
+
value: option.value
|
|
461
|
+
}];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
var property_unit = '';
|
|
466
|
+
var property_units = [];
|
|
467
|
+
var property_unit_type = '';
|
|
468
|
+
var input_format = ''; // 值输入格式,单值输入为空
|
|
469
|
+
var input_operator = ''; // 多值输入中间分隔符
|
|
470
|
+
var input_type = '';
|
|
471
|
+
var input_values = []; // 多值输入内容
|
|
472
|
+
|
|
473
|
+
var property_tips = '';
|
|
474
|
+
if (item !== null && item !== void 0 && item.properties) {
|
|
475
|
+
// 有属性限制
|
|
476
|
+
var property = item.properties.property;
|
|
477
|
+
if (property.unitNames) {
|
|
478
|
+
// 需要上传单位
|
|
479
|
+
var unit = property.unitNames.unitName;
|
|
480
|
+
if (unit instanceof Object) {
|
|
481
|
+
// 对象
|
|
482
|
+
property_unit = unit.value;
|
|
483
|
+
property_units = [unit.value];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (property.formats) {
|
|
487
|
+
// 输入格式
|
|
488
|
+
var format = property.formats.format;
|
|
489
|
+
// console.log(format)
|
|
490
|
+
format.forEach(function (formatItem, formatIndex) {
|
|
491
|
+
input_format += formatItem.text || '';
|
|
492
|
+
if (formatItem.type === 'input' && input_format && formatIndex != 0) {
|
|
493
|
+
// 多值
|
|
494
|
+
input_values.push({
|
|
495
|
+
title: format[formatIndex - 1].text || '',
|
|
496
|
+
value: ''
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (formatItem.type === 'operator') {
|
|
500
|
+
// 获取多值分割符
|
|
501
|
+
input_operator = formatItem.text;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (property.precision) {
|
|
506
|
+
// 输入限制(数字,小数点后几位,0为整数)
|
|
507
|
+
input_type = property.precision.value > 0 ? 'float' : 'number';
|
|
508
|
+
}
|
|
509
|
+
if (property.taoSirType) {
|
|
510
|
+
// 限制类型
|
|
511
|
+
property_unit_type = property.taoSirType.value;
|
|
512
|
+
}
|
|
513
|
+
if (property.tip) {
|
|
514
|
+
var _property$tip;
|
|
515
|
+
// 有提示语
|
|
516
|
+
property_tips = ((_property$tip = property.tip) === null || _property$tip === void 0 ? void 0 : _property$tip.value) || '';
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
var property_type = 0;
|
|
520
|
+
var date_format = '';
|
|
521
|
+
if (item.type === 'input') {
|
|
522
|
+
// 文本
|
|
523
|
+
|
|
524
|
+
select_max_num = 0;
|
|
525
|
+
if (property_unit) {
|
|
526
|
+
// 需要使用到 单位
|
|
527
|
+
if (property_unit_type == 'date') {
|
|
528
|
+
// 日期类型 (淘宝日期格式为‘yyyy-MM’, 目前仅发现”“)
|
|
529
|
+
property_type = 5;
|
|
530
|
+
if (property_unit === '年') {
|
|
531
|
+
date_format = 'yyyy';
|
|
532
|
+
} else if (property_unit === '年月') {
|
|
533
|
+
date_format = 'yyyy-MM';
|
|
534
|
+
} else if (property_unit === '年月日') {
|
|
535
|
+
date_format = 'yyyy-MM-dd';
|
|
536
|
+
} else {
|
|
537
|
+
date_format = 'yyyy-MM';
|
|
538
|
+
}
|
|
539
|
+
} else {
|
|
540
|
+
// 规格输入(数字、带单位)
|
|
541
|
+
if (input_format !== '') {
|
|
542
|
+
// 需要输入范围值
|
|
543
|
+
property_type = 8;
|
|
544
|
+
} else {
|
|
545
|
+
// 只需要输入一个值
|
|
546
|
+
property_type = 4;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
// 正常 纯文本
|
|
551
|
+
property_type = 1;
|
|
552
|
+
}
|
|
553
|
+
} else if (item.type === 'singleCheck') {
|
|
554
|
+
// 单选
|
|
555
|
+
property_type = 2;
|
|
556
|
+
select_max_num = 1;
|
|
557
|
+
} else if (item.type === 'multiCheck') {
|
|
558
|
+
// 多选
|
|
559
|
+
property_type = 3;
|
|
560
|
+
if (!select_max_num) {
|
|
561
|
+
// 没有现在,最多选5个
|
|
562
|
+
select_max_num = 5;
|
|
563
|
+
}
|
|
564
|
+
} else if (item.type === 'multiComplex') {
|
|
565
|
+
// 组合 (当前仅“材质成分”)
|
|
566
|
+
property_type = 6;
|
|
567
|
+
var field = item.fields.field;
|
|
568
|
+
|
|
569
|
+
// 材质(选项)
|
|
570
|
+
var material_prop_name = field.find(function (fieldItem) {
|
|
571
|
+
return fieldItem.id === 'material_prop_name';
|
|
572
|
+
});
|
|
573
|
+
// 含量(输入)
|
|
574
|
+
var material_prop_content = field.find(function (fieldItem) {
|
|
575
|
+
return fieldItem.id === 'material_prop_content';
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// 组合多选 选项内容
|
|
579
|
+
if (material_prop_name.options) {
|
|
580
|
+
if (material_prop_name.options.option) {
|
|
581
|
+
property_values = material_prop_name.options.option.map(function (value) {
|
|
582
|
+
return {
|
|
583
|
+
name: value.displayName,
|
|
584
|
+
value_id: value.value,
|
|
585
|
+
value: value.value,
|
|
586
|
+
disableContent: false,
|
|
587
|
+
// 是否需要成分
|
|
588
|
+
content: '' // 成分
|
|
589
|
+
};
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// 设置组合规则
|
|
595
|
+
if (material_prop_content.rules) {
|
|
596
|
+
// 有规则
|
|
597
|
+
if (material_prop_content.rules.rule) {
|
|
598
|
+
// 获取不可用
|
|
599
|
+
var disableRule = material_prop_content.rules.rule.find(function (rule) {
|
|
600
|
+
return rule.name === 'disableRule';
|
|
601
|
+
});
|
|
602
|
+
if (disableRule) {
|
|
603
|
+
// 有不可用的规则
|
|
604
|
+
var express = disableRule["depend-group"]["depend-express"];
|
|
605
|
+
if (express) {
|
|
606
|
+
// 获取到无需设置 成分的
|
|
607
|
+
express.forEach(function (expressItem) {
|
|
608
|
+
if (expressItem.fieldId === 'material_prop_name') {
|
|
609
|
+
property_values.push({
|
|
610
|
+
name: expressItem.value,
|
|
611
|
+
value_id: expressItem.value,
|
|
612
|
+
value: expressItem.value,
|
|
613
|
+
disableContent: true,
|
|
614
|
+
// 是否需要成分
|
|
615
|
+
content: '' // 成分
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
// console.log("材质面料选项", JSON.stringify(property_values))
|
|
624
|
+
|
|
625
|
+
if (!select_max_num) {
|
|
626
|
+
// 没有现在,最多选5个
|
|
627
|
+
select_max_num = 7;
|
|
628
|
+
}
|
|
629
|
+
property_tips = '最多设置' + select_max_num + '个';
|
|
630
|
+
}
|
|
631
|
+
var show_condition = [];
|
|
632
|
+
return {
|
|
633
|
+
property_id: item.id,
|
|
634
|
+
// 属性id
|
|
635
|
+
property_required: property_required,
|
|
636
|
+
// 是否必填
|
|
637
|
+
property_name: item.name,
|
|
638
|
+
// 属性名称
|
|
639
|
+
|
|
640
|
+
property_values: property_values,
|
|
641
|
+
// 属性可选值列表
|
|
642
|
+
property_type: property_type,
|
|
643
|
+
// 属性类型,0:未知 1:文本,2:单选,3:多选, 4:单位输入(数字)5:日期选择,6:组合多选
|
|
644
|
+
property_value: undefined,
|
|
645
|
+
// 属性值(根据具体属性类型,属性值类型不同)
|
|
646
|
+
|
|
647
|
+
property_unit: property_unit,
|
|
648
|
+
// 单位
|
|
649
|
+
property_units: property_units,
|
|
650
|
+
// 单位列表
|
|
651
|
+
|
|
652
|
+
select_max_num: select_max_num,
|
|
653
|
+
// 最多选择多少个选项(多选,组合多选使用)
|
|
654
|
+
select_custom: false,
|
|
655
|
+
// 是否支持自定义选项
|
|
656
|
+
|
|
657
|
+
input_max_num: input_max_num,
|
|
658
|
+
// 输入文本最大字数(纯文本输入使用)
|
|
659
|
+
input_num: 0,
|
|
660
|
+
// 当前文本输入字数
|
|
661
|
+
|
|
662
|
+
input_type: input_type,
|
|
663
|
+
// 输入类型(单位输入使用),number: 整数,float: 价格
|
|
664
|
+
|
|
665
|
+
input_format: input_format,
|
|
666
|
+
// 输入格式(单位输入使用)
|
|
667
|
+
input_values: input_values,
|
|
668
|
+
// 多值输入内容
|
|
669
|
+
input_operator: input_operator,
|
|
670
|
+
// 多值输入分格符
|
|
671
|
+
input_min_value: '',
|
|
672
|
+
// 范围输入,最小值
|
|
673
|
+
input_max_value: '',
|
|
674
|
+
// 范围输入,最大值
|
|
675
|
+
|
|
676
|
+
date_format: date_format,
|
|
677
|
+
// 日期格式(日期使用)
|
|
678
|
+
|
|
679
|
+
property_tips: property_tips,
|
|
680
|
+
// 提示
|
|
681
|
+
|
|
682
|
+
has_children: has_children,
|
|
683
|
+
// 没有子属性,
|
|
684
|
+
show_condition: show_condition,
|
|
685
|
+
// 显示条件,有数据即为子属性
|
|
686
|
+
condition_values: [] // 子属性根据父属性筛选后的 选项列表
|
|
687
|
+
};
|
|
688
|
+
});
|
|
689
|
+
console.log(propertys);
|
|
690
|
+
return propertys;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
var dy = {
|
|
694
|
+
createCategoryProperties: createCategoryProperties$1
|
|
695
|
+
};
|
|
696
|
+
function createCategoryProperties$1(categoryPropertys) {
|
|
697
|
+
var propertys = categoryPropertys.map(function (item) {
|
|
698
|
+
if ((item === null || item === void 0 ? void 0 : item.property_id) !== undefined && (item === null || item === void 0 ? void 0 : item.property_value) !== undefined && item.property_type !== undefined) {
|
|
699
|
+
return item;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// 属性可选选项
|
|
703
|
+
var property_values = [];
|
|
704
|
+
if (item.options) {
|
|
705
|
+
// 存在可选选项
|
|
706
|
+
property_values = item.options.map(function (value) {
|
|
707
|
+
return {
|
|
708
|
+
name: value.name,
|
|
709
|
+
value_id: value.value_id,
|
|
710
|
+
value: value.value,
|
|
711
|
+
parent_value: []
|
|
712
|
+
};
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
var property_type = 0;
|
|
716
|
+
var property_units = [];
|
|
717
|
+
var property_unit = '';
|
|
718
|
+
var select_max_num = 0;
|
|
719
|
+
var input_max_num = 0;
|
|
720
|
+
var input_type = '';
|
|
721
|
+
var input_format = '';
|
|
722
|
+
var date_format = '';
|
|
723
|
+
var measure_templates = {}; // 组合模版
|
|
724
|
+
|
|
725
|
+
if (item.type === 'text') {
|
|
726
|
+
// 文本
|
|
727
|
+
property_type = 1;
|
|
728
|
+
} else if (item.type === 'select') {
|
|
729
|
+
// 单选
|
|
730
|
+
property_type = 2;
|
|
731
|
+
select_max_num = 1;
|
|
732
|
+
} else if (item.type === 'multi_select') {
|
|
733
|
+
// 多选
|
|
734
|
+
property_type = 3;
|
|
735
|
+
select_max_num = item.multi_select_max;
|
|
736
|
+
} else if (item.type === 'measure') {
|
|
737
|
+
// 单位输入
|
|
738
|
+
property_type = 4;
|
|
739
|
+
if (item.measure_templates.length) {
|
|
740
|
+
var measure_templatesItem = item.measure_templates[0];
|
|
741
|
+
var moduleItem = measure_templatesItem.value_modules[0];
|
|
742
|
+
moduleItem.units.forEach(function (unit) {
|
|
743
|
+
property_units.push(unit.unit_name);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
property_unit = property_units[0];
|
|
747
|
+
} else if (item.type === 'multi_value_measure') {
|
|
748
|
+
// 组合多选 ('面料材质')
|
|
749
|
+
property_type = 6;
|
|
750
|
+
select_max_num = item.multi_select_max;
|
|
751
|
+
//
|
|
752
|
+
if (item.measure_templates.length) {
|
|
753
|
+
var _measure_templatesItem = item.measure_templates[0];
|
|
754
|
+
measure_templates = {
|
|
755
|
+
template_id: _measure_templatesItem.template_id,
|
|
756
|
+
value_modules: _measure_templatesItem.value_modules.map(function (moduleItem) {
|
|
757
|
+
return {
|
|
758
|
+
input_type: moduleItem.input_type,
|
|
759
|
+
module_id: moduleItem.module_id,
|
|
760
|
+
prefix: moduleItem.prefix,
|
|
761
|
+
suffix: moduleItem.suffix,
|
|
762
|
+
unit: moduleItem.units.length ? moduleItem.units[0] : {
|
|
763
|
+
unit_id: 0,
|
|
764
|
+
unit_name: ''
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
})
|
|
768
|
+
};
|
|
769
|
+
var _moduleItem = _measure_templatesItem.value_modules.find(function (moduleItem) {
|
|
770
|
+
return moduleItem.input_type === 'enum_diy';
|
|
771
|
+
});
|
|
772
|
+
if (_moduleItem) {
|
|
773
|
+
// 查询到需要的带单位的
|
|
774
|
+
_moduleItem.values;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
property_values = item.options.map(function (value) {
|
|
778
|
+
// let disableContent = measure_values.findIndex(valueItem => valueItem.value_name === value.name)
|
|
779
|
+
|
|
780
|
+
return {
|
|
781
|
+
name: value.name,
|
|
782
|
+
value_id: value.value_id,
|
|
783
|
+
value: value.value,
|
|
784
|
+
disableContent: false,
|
|
785
|
+
// 是否需要成分
|
|
786
|
+
content: '' // 成分
|
|
787
|
+
};
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
var show_condition = [];
|
|
791
|
+
return {
|
|
792
|
+
property_id: item.property_id,
|
|
793
|
+
// 属性id
|
|
794
|
+
property_required: item.required == 1,
|
|
795
|
+
// 是否必填
|
|
796
|
+
property_name: item.property_name,
|
|
797
|
+
// 属性名称
|
|
798
|
+
|
|
799
|
+
property_type: property_type,
|
|
800
|
+
// 属性类型,0:未知 1:文本,2:单选,3:多选, 4:单位输入(数字)5:日期选择,6:组合多选
|
|
801
|
+
property_value: undefined,
|
|
802
|
+
// 属性值(根据具体属性类型,属性值类型不同)
|
|
803
|
+
|
|
804
|
+
property_values: property_values,
|
|
805
|
+
// 属性可选值列表(单选、多选)
|
|
806
|
+
|
|
807
|
+
property_unit: property_unit,
|
|
808
|
+
// 单位
|
|
809
|
+
property_units: property_units,
|
|
810
|
+
// 单位列表
|
|
811
|
+
|
|
812
|
+
select_max_num: select_max_num,
|
|
813
|
+
// 最多选择多少个选项(多选,组合多选使用)
|
|
814
|
+
select_custom: false,
|
|
815
|
+
// 是否支持自定义选项
|
|
816
|
+
|
|
817
|
+
input_max_num: input_max_num,
|
|
818
|
+
// 输入文本最大字数(纯文本输入使用)
|
|
819
|
+
input_num: 0,
|
|
820
|
+
// 当前文本输入字数
|
|
821
|
+
|
|
822
|
+
input_type: input_type,
|
|
823
|
+
// 输入类型(单位输入使用),number: 整数,float: 价格
|
|
824
|
+
|
|
825
|
+
input_format: input_format,
|
|
826
|
+
// 输入格式(单位输入使用)
|
|
827
|
+
input_min_value: '',
|
|
828
|
+
// 范围输入,最小值
|
|
829
|
+
input_max_value: '',
|
|
830
|
+
// 范围输入,最大值
|
|
831
|
+
|
|
832
|
+
date_format: date_format,
|
|
833
|
+
// 日期格式(日期使用)
|
|
834
|
+
|
|
835
|
+
measure_templates: measure_templates,
|
|
836
|
+
// 属性模版 (组合模版)
|
|
837
|
+
|
|
838
|
+
has_children: false,
|
|
839
|
+
// 没有子属性,
|
|
840
|
+
show_condition: show_condition,
|
|
841
|
+
// 显示条件,有数据即为子属性
|
|
842
|
+
condition_values: [] // 子属性根据父属性筛选后的 选项列表
|
|
843
|
+
};
|
|
844
|
+
});
|
|
845
|
+
return propertys;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
var propertyTools = {
|
|
849
|
+
// 匹配文本输入
|
|
850
|
+
matchInputProperty: function matchInputProperty(propertyItem, goodsProperties, goods) {
|
|
851
|
+
// 进行包含匹配
|
|
852
|
+
var result = goodsProperties.findIndex(function (item) {
|
|
853
|
+
return item.attr_name.includes(propertyItem.property_name);
|
|
854
|
+
});
|
|
855
|
+
if (result != -1) {
|
|
856
|
+
// 能进行模糊匹配到, 直接文本直接赋值
|
|
857
|
+
var goodsProperty = goodsProperties[result];
|
|
858
|
+
goodsProperties.splice(result, 1); // 从匹配数据中移除
|
|
859
|
+
|
|
860
|
+
if (typeof goodsProperty.value === 'string') {
|
|
861
|
+
// 值为字符串
|
|
862
|
+
return goodsProperty.value;
|
|
863
|
+
}
|
|
864
|
+
if (_typeof(goodsProperty.value) === 'object') {
|
|
865
|
+
// 对象/数组
|
|
866
|
+
if (goodsProperty.value instanceof Array) {
|
|
867
|
+
// 数组
|
|
868
|
+
var property_values = [];
|
|
869
|
+
var reg = /(.*?)\[(\d+)%\]/;
|
|
870
|
+
goodsProperty.value.forEach(function (valueItem) {
|
|
871
|
+
if (typeof valueItem === 'string' && reg.test(valueItem)) {
|
|
872
|
+
// 为字符串,并且为 '其他材质[100%]'格式数据
|
|
873
|
+
var values = reg.exec(valueItem);
|
|
874
|
+
if (propertyItem.property_name.includes('含量')) {
|
|
875
|
+
// 含量,只取含量,不取材质
|
|
876
|
+
property_values.push(values[2]);
|
|
877
|
+
} else if (propertyItem.property_name.includes('材质成分')) {
|
|
878
|
+
// 材质成分,直接赋值
|
|
879
|
+
property_values.push(values[0]);
|
|
880
|
+
} else if (propertyItem.property_name.includes('材质')) {
|
|
881
|
+
// 材质,只取材质,不取含量
|
|
882
|
+
property_values.push(values[1]);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
return property_values.length ? property_values[0] : '';
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// 没有进行模糊匹配到,进行特殊处理
|
|
892
|
+
|
|
893
|
+
if (propertyItem.property_name.includes('CCC') || propertyItem.property_name.includes('3C')) {
|
|
894
|
+
// 玩具3C认证
|
|
895
|
+
result = goodsProperties.findIndex(function (item) {
|
|
896
|
+
return item.attr_name.includes('CCC') || item.attr_name.includes('3C');
|
|
897
|
+
});
|
|
898
|
+
if (result != -1) {
|
|
899
|
+
var _goodsProperty = goodsProperties[result];
|
|
900
|
+
goodsProperties.splice(result, 1); // 从匹配数据中移除
|
|
901
|
+
return _goodsProperty.value;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
if (propertyItem.property_name.includes('型号') && goods.cate_path.includes('3C数码配件')) {
|
|
905
|
+
return goods.goods_sn;
|
|
906
|
+
}
|
|
907
|
+
if (propertyItem.property_name.includes('生产厂家') && goods.cate_path.includes('3C数码配件')) {
|
|
908
|
+
return '国内';
|
|
909
|
+
}
|
|
910
|
+
return '';
|
|
911
|
+
},
|
|
912
|
+
/**
|
|
913
|
+
* 匹配单选
|
|
914
|
+
* @param {Boolean} isTemplate 是否模板匹配,true时以模板属性为主
|
|
915
|
+
* */
|
|
916
|
+
matchSingleSelectProperty: function matchSingleSelectProperty(isTemplate, propertyItem, goodsProperties) {
|
|
917
|
+
// 子属性 使用’condition_values‘,正常属性 使用’property_values‘
|
|
918
|
+
var property_values = propertyItem.show_condition.length ? propertyItem.condition_values : propertyItem.property_values;
|
|
919
|
+
if (property_values.length == 1) {
|
|
920
|
+
// 只有一个选项, 直接选
|
|
921
|
+
return property_values[0];
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// 模糊匹配
|
|
925
|
+
var index = goodsProperties.findIndex(function (item) {
|
|
926
|
+
return item.attr_name.includes(propertyItem.property_name);
|
|
927
|
+
});
|
|
928
|
+
if (index != -1) {
|
|
929
|
+
var attr = goodsProperties[index];
|
|
930
|
+
var valueItem = this.matchSingleSelectPropertyValue(property_values, attr);
|
|
931
|
+
if (valueItem) {
|
|
932
|
+
goodsProperties.splice(i, 1);
|
|
933
|
+
return valueItem;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// 使用相似度进行匹配
|
|
938
|
+
for (var i = 0; i < goodsProperties.length; i++) {
|
|
939
|
+
var _attr = goodsProperties[i];
|
|
940
|
+
var result = utils.getStringSimilarity(propertyItem.property_name, _attr.attr_name);
|
|
941
|
+
if (result >= 50) {
|
|
942
|
+
// 相似程度大于等50,进行匹配属性值
|
|
943
|
+
|
|
944
|
+
var _valueItem = this.matchSingleSelectPropertyValue(property_values, _attr);
|
|
945
|
+
if (_valueItem) {
|
|
946
|
+
goodsProperties.splice(i, 1);
|
|
947
|
+
return _valueItem;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// 指定修改
|
|
953
|
+
if (['产地'].includes(propertyItem.property_name)) {
|
|
954
|
+
//
|
|
955
|
+
var _valueItem2 = propertyItem.property_values.find(function (item) {
|
|
956
|
+
return item.name.includes('中国');
|
|
957
|
+
});
|
|
958
|
+
if (_valueItem2) {
|
|
959
|
+
return _valueItem2;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return {};
|
|
963
|
+
},
|
|
964
|
+
/**
|
|
965
|
+
* 匹配单选值
|
|
966
|
+
* @param {Array} propertyValues 属性值可选列表
|
|
967
|
+
* @param {Object} goodsAttr 参考属性值
|
|
968
|
+
* */
|
|
969
|
+
matchSingleSelectPropertyValue: function matchSingleSelectPropertyValue(propertyValues, goodsAttr) {
|
|
970
|
+
if (!goodsAttr || !Object.keys(goodsAttr).length) {
|
|
971
|
+
// 参考值为空
|
|
972
|
+
return {};
|
|
973
|
+
}
|
|
974
|
+
var valueItem = propertyValues.find(function (item) {
|
|
975
|
+
return item.name === goodsAttr.value;
|
|
976
|
+
});
|
|
977
|
+
if (valueItem) {
|
|
978
|
+
// 属性值全匹配正确
|
|
979
|
+
return valueItem;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// 属性值全字符匹配失败,进行字符包含匹配
|
|
983
|
+
valueItem = propertyValues.find(function (item) {
|
|
984
|
+
return item.name.includes(goodsAttr.value) || goodsAttr.value.includes(item.name);
|
|
985
|
+
});
|
|
986
|
+
if (valueItem) {
|
|
987
|
+
// 字符包含匹配正确
|
|
988
|
+
return valueItem;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
// 字符包含匹配失败,进行字符相似度匹配
|
|
992
|
+
var similarity = 0;
|
|
993
|
+
propertyValues.forEach(function (item) {
|
|
994
|
+
var result = utils.getStringSimilarity(item.name, goodsAttr.value);
|
|
995
|
+
if (result >= 50 && result > similarity) {
|
|
996
|
+
// 相似度大于50, 并且比之前相似度大(取最大相似值)
|
|
997
|
+
similarity = result;
|
|
998
|
+
valueItem = item;
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
if (valueItem) {
|
|
1002
|
+
// 相似度匹配大于50, 获取最相似的值)
|
|
1003
|
+
return valueItem;
|
|
1004
|
+
}
|
|
1005
|
+
return {};
|
|
1006
|
+
},
|
|
1007
|
+
/* 匹配多选 */matchMultipleSelectProperty: function matchMultipleSelectProperty(propertyItem, goodsProperties) {
|
|
1008
|
+
// 子属性 使用’condition_values‘,正常属性 使用’property_values‘
|
|
1009
|
+
var property_values = propertyItem.show_condition.length ? propertyItem.condition_values : propertyItem.property_values;
|
|
1010
|
+
if (['面料分类', '面料材质'].includes(propertyItem.property_name)) {
|
|
1011
|
+
// 多选 面料材质
|
|
1012
|
+
var index = goodsProperties.findIndex(function (item) {
|
|
1013
|
+
return ['面料分类', '面料材质'].includes(item.attr_name);
|
|
1014
|
+
});
|
|
1015
|
+
if (index != -1) {
|
|
1016
|
+
var attr = goodsProperties[index];
|
|
1017
|
+
goodsProperties.splice(index, 1);
|
|
1018
|
+
var value = [];
|
|
1019
|
+
if (attr.value instanceof Array) {
|
|
1020
|
+
// 数组(原商品属性多选),字符串数组
|
|
1021
|
+
attr.value.forEach(function (attrValue) {
|
|
1022
|
+
if (propertyItem.select_max_num > value.length) {
|
|
1023
|
+
// 未到限制多选数量,进行匹配
|
|
1024
|
+
var valueItem = property_values.find(function (valueItem) {
|
|
1025
|
+
return valueItem.name === attrValue;
|
|
1026
|
+
});
|
|
1027
|
+
if (valueItem) {
|
|
1028
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
1029
|
+
valueItem.isSelect = true;
|
|
1030
|
+
value.push(valueItem);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
} else {
|
|
1035
|
+
// 对象(原商品属性单选)
|
|
1036
|
+
if (propertyItem.select_max_num > value.length) {
|
|
1037
|
+
var valueItem = property_values.find(function (value) {
|
|
1038
|
+
return value.name === attr.value;
|
|
1039
|
+
});
|
|
1040
|
+
if (valueItem) {
|
|
1041
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
1042
|
+
valueItem.isSelect = true;
|
|
1043
|
+
value.push(valueItem);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return value;
|
|
1048
|
+
}
|
|
1049
|
+
return [];
|
|
1050
|
+
}
|
|
1051
|
+
return [];
|
|
1052
|
+
},
|
|
1053
|
+
/* 匹配组合多选(’材质成分‘) */matchMaterialQualityProperty: function matchMaterialQualityProperty(propertyItem, goodsProperties) {
|
|
1054
|
+
// 子属性 使用’condition_values‘,正常属性 使用’property_values‘
|
|
1055
|
+
var property_values = propertyItem.show_condition.length ? propertyItem.condition_values : propertyItem.property_values;
|
|
1056
|
+
var valueList = [];
|
|
1057
|
+
|
|
1058
|
+
// console.log("匹配材质成分", propertyItem.property_name)
|
|
1059
|
+
// console.log(JSON.stringify(goodsProperties))
|
|
1060
|
+
// 模糊匹配
|
|
1061
|
+
var index = goodsProperties.findIndex(function (item) {
|
|
1062
|
+
return item.attr_name.includes(propertyItem.property_name);
|
|
1063
|
+
});
|
|
1064
|
+
if (index != -1) {
|
|
1065
|
+
var attr = goodsProperties[index];
|
|
1066
|
+
var attrValue = [];
|
|
1067
|
+
console.log(attr.value, _typeof(attr.value));
|
|
1068
|
+
if (typeof attr.value === 'string') {
|
|
1069
|
+
// 字符串
|
|
1070
|
+
attrValue = attr.value.split(',');
|
|
1071
|
+
} else {
|
|
1072
|
+
// 数组
|
|
1073
|
+
attrValue = _toConsumableArray(attr.value);
|
|
1074
|
+
}
|
|
1075
|
+
if (attrValue) {
|
|
1076
|
+
attrValue.forEach(function (item) {
|
|
1077
|
+
if (item instanceof String) {
|
|
1078
|
+
var t = item.lastIndexOf('[');
|
|
1079
|
+
if (t != -1) {
|
|
1080
|
+
var attValue = item.slice(0, t);
|
|
1081
|
+
var attContent = item.slice(t + 1, item.length - 1).replace('%', '');
|
|
1082
|
+
var valueItem = property_values.find(function (item) {
|
|
1083
|
+
return item.name === attValue;
|
|
1084
|
+
});
|
|
1085
|
+
if (valueItem) {
|
|
1086
|
+
// 属性值全匹配正确
|
|
1087
|
+
valueItem.content = Number(attContent) ? Number(attContent) : 0;
|
|
1088
|
+
valueItem.isSelect = true;
|
|
1089
|
+
valueList.push(valueItem);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return valueList;
|
|
1097
|
+
},
|
|
1098
|
+
/* 计算属性各项属性数量,与选择数量 */calculateCategroyProperty: function calculateCategroyProperty(propertiesDatas) {
|
|
1099
|
+
var requiredTotal = 0;
|
|
1100
|
+
var selectCount = 0;
|
|
1101
|
+
propertiesDatas.required_list.forEach(function (item) {
|
|
1102
|
+
if (item.show) {
|
|
1103
|
+
requiredTotal++;
|
|
1104
|
+
if (item.property_type == 1 && item.property_value) {
|
|
1105
|
+
// 文本
|
|
1106
|
+
selectCount++;
|
|
1107
|
+
} else if (item.property_type == 2 && item.property_value && Object.keys(item.property_value).length) {
|
|
1108
|
+
// 单选
|
|
1109
|
+
selectCount++;
|
|
1110
|
+
} else if (item.property_type == 3 && item.property_value.length) {
|
|
1111
|
+
// 多选
|
|
1112
|
+
selectCount++;
|
|
1113
|
+
} else if (item.property_type == 4 && item.property_value && item.property_unit) {
|
|
1114
|
+
// 规格输入
|
|
1115
|
+
selectCount++;
|
|
1116
|
+
} else if (item.property_type == 5 && item.property_value) {
|
|
1117
|
+
// 日期选择
|
|
1118
|
+
selectCount++;
|
|
1119
|
+
} else if (item.property_type == 6 && item.property_value.length) {
|
|
1120
|
+
// 组合多选
|
|
1121
|
+
selectCount++;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
propertiesDatas.require_total = requiredTotal;
|
|
1126
|
+
propertiesDatas.require_count = selectCount;
|
|
1127
|
+
},
|
|
1128
|
+
/* 获取子属性 */getChildrenProperty: function getChildrenProperty(list, parentItem, children_list) {
|
|
1129
|
+
var index = children_list.length - 1;
|
|
1130
|
+
while (index >= 0) {
|
|
1131
|
+
var childrenItem = children_list[index];
|
|
1132
|
+
var result = childrenItem.show_condition.findIndex(function (conditionItem) {
|
|
1133
|
+
return conditionItem.parent_property_id == parentItem.property_id;
|
|
1134
|
+
});
|
|
1135
|
+
if (result != -1) {
|
|
1136
|
+
// 当前子属性,为当前属性的子属性
|
|
1137
|
+
|
|
1138
|
+
if (childrenItem.show_condition.length == 1) {
|
|
1139
|
+
// 子属性只有一个显示条件,直接添加
|
|
1140
|
+
children_list.splice(index, 1); // 移除属性列表
|
|
1141
|
+
|
|
1142
|
+
childrenItem.property_required = parentItem.property_required; // 子属性设置为必须项
|
|
1143
|
+
list.push(childrenItem);
|
|
1144
|
+
if (childrenItem.has_children) {
|
|
1145
|
+
// 需要重新调用赋值,打破当前循序重新开始遍历子属性
|
|
1146
|
+
this.getChildrenProperty(list, childrenItem, children_list);
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
} else {
|
|
1150
|
+
// 子属性有多个显示条件
|
|
1151
|
+
childrenItem.property_required = parentItem.property_required; // 先设置子属性为必填项,后续非必填筛选完成后,分别添加到列表最后面
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
index--;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
var main = {
|
|
1160
|
+
createCategoryProperties: createCategoryProperties
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
/*
|
|
1164
|
+
* 匹配属性值
|
|
1165
|
+
* @param {String} pt_type 平台编码(生成平台编码)
|
|
1166
|
+
* @param {Array} pt_attrs 平台属性列表(生成平台属性)
|
|
1167
|
+
* @param {Array} orgrin_attrs 匹配来源属性列表(来源属性,用于生成平台属性属性值匹配)
|
|
1168
|
+
* */
|
|
1169
|
+
function createCategoryProperties(cate, pt_type, pt_attrs) {
|
|
1170
|
+
var orgrin_attrs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
1171
|
+
var goods = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1172
|
+
return new Promise(function (resolve, reject) {
|
|
1173
|
+
try {
|
|
1174
|
+
var _checkPlatform;
|
|
1175
|
+
// console.log("待处理属性列表", pt_attrs)
|
|
1176
|
+
// console.log("来源属性", orgrin_attrs)
|
|
1177
|
+
|
|
1178
|
+
// 获取平台,检测平台是否正确
|
|
1179
|
+
var platform = ((_checkPlatform = checkPlatform(pt_type)) === null || _checkPlatform === void 0 ? void 0 : _checkPlatform.code) || '';
|
|
1180
|
+
console.log("开始进行匹配", JSON.stringify(cate), platform);
|
|
1181
|
+
var properties = [];
|
|
1182
|
+
switch (platform) {
|
|
1183
|
+
case 'pdd':
|
|
1184
|
+
// 拼多多
|
|
1185
|
+
properties = pdd.createCategoryProperties(pt_attrs);
|
|
1186
|
+
break;
|
|
1187
|
+
case 'tb':
|
|
1188
|
+
// 淘宝
|
|
1189
|
+
properties = tb.createCategoryProperties(pt_attrs);
|
|
1190
|
+
break;
|
|
1191
|
+
case 'tm':
|
|
1192
|
+
// 天猫
|
|
1193
|
+
break;
|
|
1194
|
+
case 'jd':
|
|
1195
|
+
// 京东
|
|
1196
|
+
break;
|
|
1197
|
+
case 'dy':
|
|
1198
|
+
// 抖音
|
|
1199
|
+
properties = dy.createCategoryProperties(pt_attrs);
|
|
1200
|
+
break;
|
|
1201
|
+
case 'xp':
|
|
1202
|
+
// 虾皮
|
|
1203
|
+
break;
|
|
1204
|
+
case 'xhs':
|
|
1205
|
+
// 小红书
|
|
1206
|
+
break;
|
|
1207
|
+
case 'ks':
|
|
1208
|
+
// 快手
|
|
1209
|
+
break;
|
|
1210
|
+
case 'dsy':
|
|
1211
|
+
// 电商园
|
|
1212
|
+
break;
|
|
1213
|
+
case '1688':
|
|
1214
|
+
// 1688
|
|
1215
|
+
break;
|
|
1216
|
+
case 'sph':
|
|
1217
|
+
// 微信小店
|
|
1218
|
+
break;
|
|
1219
|
+
case 'tk':
|
|
1220
|
+
// Tiktio
|
|
1221
|
+
break;
|
|
1222
|
+
default:
|
|
1223
|
+
// 其他类型,报错
|
|
1224
|
+
reject({
|
|
1225
|
+
msg: '检测不到类目来源平台!',
|
|
1226
|
+
code: -1,
|
|
1227
|
+
type: 'pt_type参数错误'
|
|
1228
|
+
});
|
|
1229
|
+
break;
|
|
1230
|
+
}
|
|
1231
|
+
console.log("待处理属性列表(转换后)", properties);
|
|
1232
|
+
|
|
1233
|
+
// 获取转换来源数据
|
|
1234
|
+
var attrs = checkOriginAttrs(orgrin_attrs, goods);
|
|
1235
|
+
console.log("来源属性(转换后)", attrs);
|
|
1236
|
+
var propertiesDatas = matchCategroyProperties(properties, attrs);
|
|
1237
|
+
console.log("匹配结果", JSON.stringify(propertiesDatas));
|
|
1238
|
+
resolve({
|
|
1239
|
+
msg: '成功',
|
|
1240
|
+
data: propertiesDatas,
|
|
1241
|
+
code: 1
|
|
1242
|
+
});
|
|
1243
|
+
} catch (err) {
|
|
1244
|
+
console.log(err);
|
|
1245
|
+
reject({
|
|
1246
|
+
msg: err.message,
|
|
1247
|
+
code: -1e4,
|
|
1248
|
+
type: '系统报错'
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/*
|
|
1255
|
+
* 检测并装换来源参数
|
|
1256
|
+
* */
|
|
1257
|
+
function checkOriginAttrs(orgrin_attrs, goods) {
|
|
1258
|
+
var attrs = orgrin_attrs.map(function (item) {
|
|
1259
|
+
if ((item === null || item === void 0 ? void 0 : item.property_id) !== undefined && (item === null || item === void 0 ? void 0 : item.property_value) !== undefined && item.property_type !== undefined) {
|
|
1260
|
+
// 当前属性为自定义属性
|
|
1261
|
+
var attrItem = {
|
|
1262
|
+
id: item.property_id,
|
|
1263
|
+
attr_name: item.property_name,
|
|
1264
|
+
value_id: '',
|
|
1265
|
+
value: ''
|
|
1266
|
+
};
|
|
1267
|
+
var property_type = (item === null || item === void 0 ? void 0 : item.property_type) || 0;
|
|
1268
|
+
if (property_type == 1 || property_type == 5) {
|
|
1269
|
+
// 纯文本、日期选择
|
|
1270
|
+
attrItem.value = (item === null || item === void 0 ? void 0 : item.property_value) || '';
|
|
1271
|
+
} else if (property_type == 2) {
|
|
1272
|
+
// 单选
|
|
1273
|
+
attrItem.value = (item === null || item === void 0 ? void 0 : item.property_value.name) || '';
|
|
1274
|
+
attrItem.value_id = (item === null || item === void 0 ? void 0 : item.property_value.value_id) || '';
|
|
1275
|
+
} else if (property_type == 3) {
|
|
1276
|
+
// 多选
|
|
1277
|
+
var valueList = (item === null || item === void 0 ? void 0 : item.property_value) || [];
|
|
1278
|
+
if (valueList.length) {
|
|
1279
|
+
attrItem.value = valueList.map(function (item) {
|
|
1280
|
+
return item.name;
|
|
1281
|
+
});
|
|
1282
|
+
attrItem.value_id = valueList.map(function (item) {
|
|
1283
|
+
return item.value_id;
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
} else if (property_type == 4) {
|
|
1287
|
+
// 输入 + 规格
|
|
1288
|
+
if (item !== null && item !== void 0 && item.property_value) {
|
|
1289
|
+
// 有输入值
|
|
1290
|
+
attrItem.value = (item === null || item === void 0 ? void 0 : item.property_value) || '' + (item === null || item === void 0 ? void 0 : item.property_unit) || '';
|
|
1291
|
+
}
|
|
1292
|
+
} else if (property_type == 6) ; else if (property_type == 7) {
|
|
1293
|
+
var _item$property_value, _item$property_value2, _item$property_value3, _item$property_value4, _item$property_value5;
|
|
1294
|
+
// 分级选择
|
|
1295
|
+
attrItem.value = item !== null && item !== void 0 && (_item$property_value = item.property_value) !== null && _item$property_value !== void 0 && _item$property_value.parent_id ? (item === null || item === void 0 || (_item$property_value2 = item.property_value) === null || _item$property_value2 === void 0 ? void 0 : _item$property_value2.parent_name) || '' + ' - ' + (item === null || item === void 0 || (_item$property_value3 = item.property_value) === null || _item$property_value3 === void 0 ? void 0 : _item$property_value3.name) || '' : (item === null || item === void 0 || (_item$property_value4 = item.property_value) === null || _item$property_value4 === void 0 ? void 0 : _item$property_value4.name) || '';
|
|
1296
|
+
attrItem.value_id = item === null || item === void 0 || (_item$property_value5 = item.property_value) === null || _item$property_value5 === void 0 ? void 0 : _item$property_value5.value_id;
|
|
1297
|
+
} else if (property_type == 8) {
|
|
1298
|
+
// 范围输入
|
|
1299
|
+
attrItem.value = (item === null || item === void 0 ? void 0 : item.property_value) || '' + (item === null || item === void 0 ? void 0 : item.property_unit) || '';
|
|
1300
|
+
}
|
|
1301
|
+
return attrItem;
|
|
1302
|
+
}
|
|
1303
|
+
return {
|
|
1304
|
+
id: (item === null || item === void 0 ? void 0 : item.id) || '',
|
|
1305
|
+
attr_name: item === null || item === void 0 ? void 0 : item.attr_name,
|
|
1306
|
+
value_id: (item === null || item === void 0 ? void 0 : item.value_id) || '',
|
|
1307
|
+
value: (item === null || item === void 0 ? void 0 : item.value) || ''
|
|
1308
|
+
};
|
|
1309
|
+
}).filter(function (item) {
|
|
1310
|
+
return item.value;
|
|
1311
|
+
});
|
|
1312
|
+
if (goods !== null && goods !== void 0 && goods.goodsSn) {
|
|
1313
|
+
// 有货号数据
|
|
1314
|
+
var result = attrs.find(function (item) {
|
|
1315
|
+
return item.attr_name.includes('货号');
|
|
1316
|
+
});
|
|
1317
|
+
if (result) {
|
|
1318
|
+
// 有货号的属性
|
|
1319
|
+
if (!(result !== null && result !== void 0 && result.value)) {
|
|
1320
|
+
// 货号没有值
|
|
1321
|
+
result.value = goods.goodsSn;
|
|
1322
|
+
}
|
|
1323
|
+
} else {
|
|
1324
|
+
// 没有货号属性,添加货号属性
|
|
1325
|
+
attrs.push({
|
|
1326
|
+
id: '',
|
|
1327
|
+
attr_name: '货号',
|
|
1328
|
+
value_id: '',
|
|
1329
|
+
value: goods.goodsSn
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (goods !== null && goods !== void 0 && goods.ccc_code) {
|
|
1334
|
+
// 商品有3c编码
|
|
1335
|
+
var _result = attrs.find(function (item) {
|
|
1336
|
+
return item.attr_name.includes('CCC') || item.attr_name.includes('3C');
|
|
1337
|
+
});
|
|
1338
|
+
if (_result) {
|
|
1339
|
+
// 有货号的属性
|
|
1340
|
+
if (!(_result !== null && _result !== void 0 && _result.value)) {
|
|
1341
|
+
// 货号没有值
|
|
1342
|
+
_result.value = goods.ccc_code;
|
|
1343
|
+
}
|
|
1344
|
+
} else {
|
|
1345
|
+
// 没有货号属性,添加货号属性
|
|
1346
|
+
attrs.push({
|
|
1347
|
+
id: '',
|
|
1348
|
+
attr_name: '3C证书',
|
|
1349
|
+
value_id: '',
|
|
1350
|
+
value: goods.ccc_code
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
return attrs;
|
|
1355
|
+
}
|
|
1356
|
+
function matchCategroyProperties(properties, attrs) {
|
|
1357
|
+
var goodsPropertys = [].concat(attrs || []);
|
|
1358
|
+
var propertiesDatas = {
|
|
1359
|
+
list: [],
|
|
1360
|
+
// 正常属性列表(不包含‘品牌’属性 以及 子属性)
|
|
1361
|
+
|
|
1362
|
+
require_total: 0,
|
|
1363
|
+
// 必填属性总数
|
|
1364
|
+
require_count: 0,
|
|
1365
|
+
// 必填属性已填数
|
|
1366
|
+
required_list: [],
|
|
1367
|
+
// 必填属性列表
|
|
1368
|
+
other_list: [],
|
|
1369
|
+
// 非必填属性列表
|
|
1370
|
+
children_list: [],
|
|
1371
|
+
// 子属性列表
|
|
1372
|
+
|
|
1373
|
+
brand_property: {},
|
|
1374
|
+
// '品牌'属性
|
|
1375
|
+
material_quality_property: {} // ‘材料成分’属性
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
// 第一步,先进行筛选,分出“品牌”属性,必填属性,非必填属性,子属性, 其中‘材料成分’属性外部登记(方便后期进行检测)
|
|
1379
|
+
properties.forEach(function (item) {
|
|
1380
|
+
if (item.property_name === '品牌') {
|
|
1381
|
+
// 品牌,跳过
|
|
1382
|
+
propertiesDatas.brand_property = item;
|
|
1383
|
+
} else if (item.show_condition.length) {
|
|
1384
|
+
// 子属性,有显示条件
|
|
1385
|
+
item.show = false;
|
|
1386
|
+
propertiesDatas.children_list.push(item);
|
|
1387
|
+
|
|
1388
|
+
// 子属性初始化
|
|
1389
|
+
if (item.property_type == 1 || item.property_type == 4 || item.property_type == 5 || item.property_type == 7 || item.property_type == 8) {
|
|
1390
|
+
// 纯文本,数字,日期
|
|
1391
|
+
item.property_value = '';
|
|
1392
|
+
} else if (item.property_type == 2) {
|
|
1393
|
+
// 单选
|
|
1394
|
+
item.property_value = {};
|
|
1395
|
+
} else if (item.property_type == 3) {
|
|
1396
|
+
// 多选
|
|
1397
|
+
item.property_value = [];
|
|
1398
|
+
}
|
|
1399
|
+
} else {
|
|
1400
|
+
// 固定属性,区分必填项,与 非必填项
|
|
1401
|
+
item.show = true;
|
|
1402
|
+
if (item.property_required) {
|
|
1403
|
+
// 必填
|
|
1404
|
+
propertiesDatas.required_list.push(item);
|
|
1405
|
+
} else {
|
|
1406
|
+
// 非必填
|
|
1407
|
+
propertiesDatas.other_list.push(item);
|
|
1408
|
+
}
|
|
1409
|
+
switch (item.property_type) {
|
|
1410
|
+
case 1:
|
|
1411
|
+
// 纯文本
|
|
1412
|
+
{
|
|
1413
|
+
item.property_value = propertyTools.matchInputProperty(item, goodsPropertys);
|
|
1414
|
+
// let index = goodsPropertys.findIndex(attr => attr.attr_name === item.property_name)
|
|
1415
|
+
// if (index != -1) {
|
|
1416
|
+
// // 匹配到,直接赋值
|
|
1417
|
+
// let attr = goodsPropertys[index]
|
|
1418
|
+
// // 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
1419
|
+
// goodsPropertys.splice(index, 1)
|
|
1420
|
+
// item.property_value = attr.value
|
|
1421
|
+
// } else {
|
|
1422
|
+
// // 没有匹配到,默认为空字符
|
|
1423
|
+
// item.property_value = ''
|
|
1424
|
+
// }
|
|
1425
|
+
// 输入文本数量
|
|
1426
|
+
item.input_num = utils.getTextLength(item.property_value);
|
|
1427
|
+
}
|
|
1428
|
+
break;
|
|
1429
|
+
case 2:
|
|
1430
|
+
// 单选类型 (根据可以选择的选项多少判断)
|
|
1431
|
+
{
|
|
1432
|
+
// 搜索关键词
|
|
1433
|
+
item.search_key = '';
|
|
1434
|
+
if (item.property_name === '货号') {
|
|
1435
|
+
// 货号(快手’货号‘属性为单选)
|
|
1436
|
+
|
|
1437
|
+
var property_value = item.property_values.find(function (property_value) {
|
|
1438
|
+
return property_value.name === goods.goods_sn;
|
|
1439
|
+
});
|
|
1440
|
+
if (!property_value) {
|
|
1441
|
+
// 原数据没有当前货号的选项,新增一个
|
|
1442
|
+
property_value = {
|
|
1443
|
+
name: goods.goods_sn,
|
|
1444
|
+
value_id: 0,
|
|
1445
|
+
value: 0,
|
|
1446
|
+
parent_value: []
|
|
1447
|
+
};
|
|
1448
|
+
item.property_values.unshift(property_value);
|
|
1449
|
+
}
|
|
1450
|
+
item.property_value = property_value;
|
|
1451
|
+
} else {
|
|
1452
|
+
// 其他
|
|
1453
|
+
|
|
1454
|
+
var index = goodsPropertys.findIndex(function (attr) {
|
|
1455
|
+
return attr.attr_name === item.property_name;
|
|
1456
|
+
});
|
|
1457
|
+
if (index != -1) {
|
|
1458
|
+
// 匹配到了
|
|
1459
|
+
var attr = goodsPropertys[index];
|
|
1460
|
+
// 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
1461
|
+
goodsPropertys.splice(index, 1);
|
|
1462
|
+
var property_values = item.show_condition.length ? item.condition_values : item.property_values;
|
|
1463
|
+
item.property_value = propertyTools.matchSingleSelectPropertyValue(property_values, attr);
|
|
1464
|
+
} else {
|
|
1465
|
+
// 未匹配到,默认为空对象
|
|
1466
|
+
item.property_value = {};
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
break;
|
|
1471
|
+
case 3:
|
|
1472
|
+
// 多选类型
|
|
1473
|
+
{
|
|
1474
|
+
// 搜索关键词
|
|
1475
|
+
item.search_key = '';
|
|
1476
|
+
var _index = goodsPropertys.findIndex(function (attr) {
|
|
1477
|
+
return attr.attr_name === item.property_name;
|
|
1478
|
+
});
|
|
1479
|
+
if (_index != -1) {
|
|
1480
|
+
// 匹配到了
|
|
1481
|
+
var _attr = goodsPropertys[_index];
|
|
1482
|
+
// 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
1483
|
+
goodsPropertys.splice(_index, 1);
|
|
1484
|
+
var value = [];
|
|
1485
|
+
if (_attr) {
|
|
1486
|
+
// 商品有该属性,进行匹配
|
|
1487
|
+
if (_attr.value instanceof Array) {
|
|
1488
|
+
// 数组(原商品属性多选),字符串数组
|
|
1489
|
+
_attr.value.forEach(function (attrValue) {
|
|
1490
|
+
if (item.select_max_num > value.length) {
|
|
1491
|
+
// 未到限制多选数量,进行匹配
|
|
1492
|
+
var valueItem = item.property_values.find(function (valueItem) {
|
|
1493
|
+
return valueItem.name === attrValue;
|
|
1494
|
+
});
|
|
1495
|
+
if (valueItem) {
|
|
1496
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
1497
|
+
valueItem.isSelect = true;
|
|
1498
|
+
value.push(valueItem);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
} else {
|
|
1503
|
+
// 对象(原商品属性单选)
|
|
1504
|
+
if (item.select_max_num > value.length) {
|
|
1505
|
+
var valueItem = item.property_values.find(function (value) {
|
|
1506
|
+
return value.name === _attr.value;
|
|
1507
|
+
});
|
|
1508
|
+
if (valueItem) {
|
|
1509
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
1510
|
+
valueItem.isSelect = true;
|
|
1511
|
+
value.push(valueItem);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
item.property_value = value ? value : [];
|
|
1517
|
+
} else {
|
|
1518
|
+
// 匹配不到
|
|
1519
|
+
item.property_value = [];
|
|
1520
|
+
}
|
|
1521
|
+
if (item.select_max_num) {
|
|
1522
|
+
// 有限制选择个数
|
|
1523
|
+
item.property_tips = "\u9650\u6700\u591A\u9009".concat(item.select_max_num, "\u4E2A");
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
break;
|
|
1527
|
+
case 4:
|
|
1528
|
+
// 输入,带单位
|
|
1529
|
+
{
|
|
1530
|
+
item.property_value = '';
|
|
1531
|
+
}
|
|
1532
|
+
break;
|
|
1533
|
+
case 5:
|
|
1534
|
+
// 日期
|
|
1535
|
+
{
|
|
1536
|
+
item.property_value = '';
|
|
1537
|
+
item.property_tips = '';
|
|
1538
|
+
}
|
|
1539
|
+
break;
|
|
1540
|
+
case 6:
|
|
1541
|
+
// 组合多选,目前仅’材质成分‘
|
|
1542
|
+
{
|
|
1543
|
+
// 外部登记出来,方便进行检测
|
|
1544
|
+
propertiesDatas.material_quality_property = item;
|
|
1545
|
+
if (item.select_max_num) {
|
|
1546
|
+
// 有限制选择个数
|
|
1547
|
+
item.property_tips = "\u9650\u6700\u591A\u9009".concat(item.select_max_num, "\u4E2A, \u4E14\u9700\u586B\u5199\u6BCF\u9879\u3010\u6750\u8D28\u3011\u7684\u542B\u91CF\uFF0C\u586B\u5199\u5B8C\u6210\u540E\u6750\u8D28\u6210\u5206\u5360\u6BD4\u603B\u548C\u5FC5\u987B\u4E3A100%");
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
break;
|
|
1551
|
+
case 7:
|
|
1552
|
+
// 日期
|
|
1553
|
+
{
|
|
1554
|
+
item.property_value = {};
|
|
1555
|
+
item.property_tips = '';
|
|
1556
|
+
}
|
|
1557
|
+
break;
|
|
1558
|
+
case 8:
|
|
1559
|
+
// 范围输入,带单位
|
|
1560
|
+
{
|
|
1561
|
+
item.property_value = '';
|
|
1562
|
+
}
|
|
1563
|
+
break;
|
|
1564
|
+
default:
|
|
1565
|
+
{
|
|
1566
|
+
item.property_type = 0;
|
|
1567
|
+
item.property_value = '';
|
|
1568
|
+
}
|
|
1569
|
+
break;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
// 第二步,进行数据重组排序,必填属性 与 非必填属性 加入子属性
|
|
1575
|
+
if (propertiesDatas.children_list.length) {
|
|
1576
|
+
// 有子属性, 需要将子属性添加到对应的属性下,子属性多条件显示,添加到列表最后
|
|
1577
|
+
// console.log("============= 当前分类存在子分类,需要进行处理 =============")
|
|
1578
|
+
var required_list = [];
|
|
1579
|
+
var other_list = [];
|
|
1580
|
+
var children_list = _toConsumableArray(propertiesDatas.children_list).sort(function (a, b) {
|
|
1581
|
+
return b.has_children;
|
|
1582
|
+
}); // 排序有子属性的排前
|
|
1583
|
+
|
|
1584
|
+
propertiesDatas.required_list.forEach(function (item) {
|
|
1585
|
+
// 加入新列表
|
|
1586
|
+
required_list.push(item);
|
|
1587
|
+
if (item.has_children) {
|
|
1588
|
+
// 有子分类,将子分类添加进列表来
|
|
1589
|
+
propertyTools.getChildrenProperty(required_list, item, children_list);
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
propertiesDatas.other_list.forEach(function (item) {
|
|
1593
|
+
// 加入临时 非必填属性列表
|
|
1594
|
+
other_list.push(item);
|
|
1595
|
+
if (item.has_children) {
|
|
1596
|
+
// 有子分类,将子分类添加进列表来
|
|
1597
|
+
propertyTools.getChildrenProperty(other_list, item, children_list);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
// 开始合并成新的完整属性列表
|
|
1602
|
+
children_list.forEach(function (item) {
|
|
1603
|
+
if (item.property_required) {
|
|
1604
|
+
required_list.push(item);
|
|
1605
|
+
} else {
|
|
1606
|
+
other_list.push(item);
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
propertiesDatas.required_list = required_list;
|
|
1610
|
+
propertiesDatas.other_list = other_list;
|
|
1611
|
+
|
|
1612
|
+
// console.log("排序完 必选项", JSON.stringify(required_list))
|
|
1613
|
+
// console.log('排序完 非必填项', JSON.stringify(other_list))
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// 第三步,合成完整的列表
|
|
1617
|
+
propertiesDatas.list = [].concat(_toConsumableArray(propertiesDatas.required_list), _toConsumableArray(propertiesDatas.other_list));
|
|
1618
|
+
|
|
1619
|
+
// 第四步,进行属性值匹配填写(必填项,非必填项,子项)
|
|
1620
|
+
propertiesDatas.list.forEach(function (item) {
|
|
1621
|
+
switch (item.property_type) {
|
|
1622
|
+
case 1:
|
|
1623
|
+
// 文本
|
|
1624
|
+
{
|
|
1625
|
+
if (!item.property_value) {
|
|
1626
|
+
// 没有选项,进行模糊匹配
|
|
1627
|
+
item.property_value = propertyTools.matchInputProperty(item, goodsPropertys);
|
|
1628
|
+
}
|
|
1629
|
+
if (item.property_required && item.property_value) {
|
|
1630
|
+
// 必填 且 有选中项,
|
|
1631
|
+
propertiesDatas.require_count++;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
break;
|
|
1635
|
+
case 2:
|
|
1636
|
+
// 单选
|
|
1637
|
+
{
|
|
1638
|
+
if (!item.property_value || !Object.keys(item.property_value).length) {
|
|
1639
|
+
// 没有选项,进行匹配
|
|
1640
|
+
item.property_value = propertyTools.matchSingleSelectProperty(false, item, goodsPropertys);
|
|
1641
|
+
}
|
|
1642
|
+
if (item.property_required && Object.keys(item.property_value).length) {
|
|
1643
|
+
// 必填 且 有选中项,
|
|
1644
|
+
propertiesDatas.require_count++;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
break;
|
|
1648
|
+
case 3:
|
|
1649
|
+
// 多选
|
|
1650
|
+
{
|
|
1651
|
+
if (!item.property_value || !item.property_value.length) {
|
|
1652
|
+
// 没有选项,进行匹配
|
|
1653
|
+
item.property_value = propertyTools.matchMultipleSelectProperty(item, goodsPropertys);
|
|
1654
|
+
}
|
|
1655
|
+
if (item.property_required && item.property_value.length) {
|
|
1656
|
+
// 必填 且 有选中项,
|
|
1657
|
+
propertiesDatas.require_count++;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
break;
|
|
1661
|
+
case 4:
|
|
1662
|
+
// 输入,带单位
|
|
1663
|
+
{
|
|
1664
|
+
// if (!item.property_value) {
|
|
1665
|
+
// // 没有选项,进行匹配
|
|
1666
|
+
// item.property_value = propertyTools.matchMultipleSelectProperty(item, goodsPropertys)
|
|
1667
|
+
// }
|
|
1668
|
+
if (item.property_required && item.property_value) {
|
|
1669
|
+
// 必填 且 有选中项,
|
|
1670
|
+
propertiesDatas.require_count++;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
break;
|
|
1674
|
+
case 5:
|
|
1675
|
+
// 日期
|
|
1676
|
+
{
|
|
1677
|
+
if (item.property_required && item.property_value) {
|
|
1678
|
+
// 必填 且 有选中项,
|
|
1679
|
+
propertiesDatas.require_count++;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
break;
|
|
1683
|
+
case 6:
|
|
1684
|
+
// 组合多选 ('材质成分')
|
|
1685
|
+
{
|
|
1686
|
+
if (!item.property_value || !item.property_value.length) {
|
|
1687
|
+
// 没有选项,进行匹配
|
|
1688
|
+
item.property_value = propertyTools.matchMaterialQualityProperty(item, goodsPropertys);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// item.property_value = []
|
|
1692
|
+
|
|
1693
|
+
if (item.property_required && item.property_value.length) {
|
|
1694
|
+
// 必填 且 有选中项,
|
|
1695
|
+
propertiesDatas.require_count++;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
break;
|
|
1699
|
+
}
|
|
1700
|
+
if (item.has_children) {
|
|
1701
|
+
// 当前属性有子属性,判断起是否显示
|
|
1702
|
+
|
|
1703
|
+
propertiesDatas.children_list.forEach(function (childrenItem) {
|
|
1704
|
+
var isShow = true;
|
|
1705
|
+
if (childrenItem.show_condition.length) {
|
|
1706
|
+
// 子属性 遍历显示条件
|
|
1707
|
+
var result = childrenItem.show_condition.find(function (conditionItem) {
|
|
1708
|
+
return item.property_id === conditionItem.parent_property_id;
|
|
1709
|
+
});
|
|
1710
|
+
if (result) {
|
|
1711
|
+
// 查询到为当前属性的子属性
|
|
1712
|
+
if (!Object.keys(item.property_value).length) {
|
|
1713
|
+
// 当前属性没有属性值,子属性不显示
|
|
1714
|
+
isShow = false;
|
|
1715
|
+
} else {
|
|
1716
|
+
// 当前属性有选择属性值
|
|
1717
|
+
if (result.parent_property_value.includes(item.property_value.value_id)) {
|
|
1718
|
+
// 当前子属性需显示,根据父属性选项,筛选子属性可使用的属性
|
|
1719
|
+
childrenItem.condition_values = childrenItem.property_values.filter(function (valueItem) {
|
|
1720
|
+
return !valueItem.parent_value || !valueItem.parent_value.length || valueItem.parent_value.length && valueItem.parent_value.includes(item.property_value.value_id);
|
|
1721
|
+
});
|
|
1722
|
+
} else {
|
|
1723
|
+
// 当前子属性不需要显示
|
|
1724
|
+
isShow = false;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
childrenItem.show = isShow;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
// 第五步,计算必填项数量
|
|
1735
|
+
propertyTools.calculateCategroyProperty(propertiesDatas);
|
|
1736
|
+
return propertiesDatas;
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
export { main as default };
|
|
1740
|
+
//# sourceMappingURL=ftdsy-attr.js.map
|