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
package/src/main.js
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
|
|
2
|
+
import { checkPlatform } from "./config/platform.js";
|
|
3
|
+
import utils from "./utils/utils.js";
|
|
4
|
+
|
|
5
|
+
import pdd from "./platform/pdd.js";
|
|
6
|
+
import tb from "./platform/tb.js";
|
|
7
|
+
import dy from "./platform/dy.js";
|
|
8
|
+
|
|
9
|
+
import propertyTools from "./tools/property.js";
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
createCategoryProperties
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* 匹配属性值
|
|
17
|
+
* @param {String} pt_type 平台编码(生成平台编码)
|
|
18
|
+
* @param {Array} pt_attrs 平台属性列表(生成平台属性)
|
|
19
|
+
* @param {Array} orgrin_attrs 匹配来源属性列表(来源属性,用于生成平台属性属性值匹配)
|
|
20
|
+
* */
|
|
21
|
+
function createCategoryProperties(cate, pt_type, pt_attrs, orgrin_attrs=[], goods={}) {
|
|
22
|
+
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
try {
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// console.log("待处理属性列表", pt_attrs)
|
|
28
|
+
// console.log("来源属性", orgrin_attrs)
|
|
29
|
+
|
|
30
|
+
// 获取平台,检测平台是否正确
|
|
31
|
+
let platform = checkPlatform(pt_type)?.code || ''
|
|
32
|
+
console.log("开始进行匹配", JSON.stringify(cate), platform)
|
|
33
|
+
|
|
34
|
+
let properties = []
|
|
35
|
+
|
|
36
|
+
switch (platform) {
|
|
37
|
+
case 'pdd':
|
|
38
|
+
// 拼多多
|
|
39
|
+
properties = pdd.createCategoryProperties(pt_attrs)
|
|
40
|
+
break;
|
|
41
|
+
case 'tb':
|
|
42
|
+
// 淘宝
|
|
43
|
+
properties = tb.createCategoryProperties(pt_attrs)
|
|
44
|
+
break;
|
|
45
|
+
case 'tm':
|
|
46
|
+
// 天猫
|
|
47
|
+
break;
|
|
48
|
+
case 'jd':
|
|
49
|
+
// 京东
|
|
50
|
+
break;
|
|
51
|
+
case 'dy':
|
|
52
|
+
// 抖音
|
|
53
|
+
properties = dy.createCategoryProperties(pt_attrs)
|
|
54
|
+
break;
|
|
55
|
+
case 'xp':
|
|
56
|
+
// 虾皮
|
|
57
|
+
break;
|
|
58
|
+
case 'xhs':
|
|
59
|
+
// 小红书
|
|
60
|
+
break;
|
|
61
|
+
case 'ks':
|
|
62
|
+
// 快手
|
|
63
|
+
break;
|
|
64
|
+
case 'dsy':
|
|
65
|
+
// 电商园
|
|
66
|
+
break;
|
|
67
|
+
case '1688':
|
|
68
|
+
// 1688
|
|
69
|
+
break;
|
|
70
|
+
case 'sph':
|
|
71
|
+
// 微信小店
|
|
72
|
+
break;
|
|
73
|
+
case 'tk':
|
|
74
|
+
// Tiktio
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
// 其他类型,报错
|
|
78
|
+
reject({
|
|
79
|
+
msg: '检测不到类目来源平台!',
|
|
80
|
+
code: -1,
|
|
81
|
+
type: 'pt_type参数错误'
|
|
82
|
+
})
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log("待处理属性列表(转换后)",properties)
|
|
87
|
+
|
|
88
|
+
// 获取转换来源数据
|
|
89
|
+
let attrs = checkOriginAttrs(orgrin_attrs, goods)
|
|
90
|
+
console.log("来源属性(转换后)", attrs)
|
|
91
|
+
|
|
92
|
+
let propertiesDatas = matchCategroyProperties(properties, attrs)
|
|
93
|
+
|
|
94
|
+
console.log("匹配结果", JSON.stringify(propertiesDatas))
|
|
95
|
+
|
|
96
|
+
resolve ({
|
|
97
|
+
msg: '成功',
|
|
98
|
+
data: propertiesDatas,
|
|
99
|
+
code: 1,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.log(err)
|
|
104
|
+
reject({
|
|
105
|
+
msg: err.message,
|
|
106
|
+
code: -10000,
|
|
107
|
+
type: '系统报错'
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* 检测并装换来源参数
|
|
115
|
+
* */
|
|
116
|
+
function checkOriginAttrs(orgrin_attrs, goods) {
|
|
117
|
+
|
|
118
|
+
var attrs = orgrin_attrs.map(item => {
|
|
119
|
+
|
|
120
|
+
if (item?.property_id !== undefined && item?.property_value !== undefined && item.property_type !== undefined) {
|
|
121
|
+
// 当前属性为自定义属性
|
|
122
|
+
var attrItem = {
|
|
123
|
+
id: item.property_id,
|
|
124
|
+
attr_name: item.property_name,
|
|
125
|
+
value_id: '',
|
|
126
|
+
value: '',
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let property_type = item?.property_type || 0
|
|
130
|
+
|
|
131
|
+
if (property_type == 1 || property_type == 5) {
|
|
132
|
+
// 纯文本、日期选择
|
|
133
|
+
attrItem.value = item?.property_value || ''
|
|
134
|
+
} else if (property_type == 2) {
|
|
135
|
+
// 单选
|
|
136
|
+
attrItem.value = item?.property_value.name || ''
|
|
137
|
+
attrItem.value_id = item?.property_value.value_id || ''
|
|
138
|
+
} else if (property_type == 3) {
|
|
139
|
+
// 多选
|
|
140
|
+
let valueList = item?.property_value || []
|
|
141
|
+
if (valueList.length) {
|
|
142
|
+
attrItem.value = valueList.map(item => item.name)
|
|
143
|
+
attrItem.value_id = valueList.map(item => item.value_id)
|
|
144
|
+
}
|
|
145
|
+
} else if (property_type == 4) {
|
|
146
|
+
// 输入 + 规格
|
|
147
|
+
if (item?.property_value) {
|
|
148
|
+
// 有输入值
|
|
149
|
+
attrItem.value = item?.property_value || '' + item?.property_unit || ''
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
} else if (property_type == 6) {
|
|
153
|
+
// 组合多选('面料材质')
|
|
154
|
+
} else if (property_type == 7) {
|
|
155
|
+
// 分级选择
|
|
156
|
+
attrItem.value = item?.property_value?.parent_id ? item?.property_value?.parent_name || '' + ' - ' + item?.property_value?.name || '' : item?.property_value?.name || ''
|
|
157
|
+
attrItem.value_id = item?.property_value?.value_id
|
|
158
|
+
} else if (property_type == 8) {
|
|
159
|
+
// 范围输入
|
|
160
|
+
attrItem.value = item?.property_value || '' + item?.property_unit || ''
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return attrItem
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
id: item?.id || '',
|
|
168
|
+
attr_name: item?.attr_name,
|
|
169
|
+
value_id: item?.value_id || '',
|
|
170
|
+
value: item?.value || '',
|
|
171
|
+
}
|
|
172
|
+
}).filter(item => item.value)
|
|
173
|
+
|
|
174
|
+
if (goods?.goodsSn) {
|
|
175
|
+
// 有货号数据
|
|
176
|
+
let result = attrs.find(item => item.attr_name.includes('货号'))
|
|
177
|
+
if (result) {
|
|
178
|
+
// 有货号的属性
|
|
179
|
+
if (!result?.value) {
|
|
180
|
+
// 货号没有值
|
|
181
|
+
result.value = goods.goodsSn
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
// 没有货号属性,添加货号属性
|
|
185
|
+
attrs.push({
|
|
186
|
+
id: '',
|
|
187
|
+
attr_name: '货号',
|
|
188
|
+
value_id: '',
|
|
189
|
+
value: goods.goodsSn,
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (goods?.ccc_code) {
|
|
195
|
+
// 商品有3c编码
|
|
196
|
+
let result = attrs.find(item => item.attr_name.includes('CCC') || item.attr_name.includes('3C'))
|
|
197
|
+
if (result) {
|
|
198
|
+
// 有货号的属性
|
|
199
|
+
if (!result?.value) {
|
|
200
|
+
// 货号没有值
|
|
201
|
+
result.value = goods.ccc_code
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
// 没有货号属性,添加货号属性
|
|
205
|
+
attrs.push({
|
|
206
|
+
id: '',
|
|
207
|
+
attr_name: '3C证书',
|
|
208
|
+
value_id: '',
|
|
209
|
+
value: goods.ccc_code,
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return attrs
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
function matchCategroyProperties(properties, attrs) {
|
|
220
|
+
|
|
221
|
+
let goodsPropertys = [].concat(attrs || [])
|
|
222
|
+
|
|
223
|
+
let propertiesDatas = {
|
|
224
|
+
list: [], // 正常属性列表(不包含‘品牌’属性 以及 子属性)
|
|
225
|
+
|
|
226
|
+
require_total: 0, // 必填属性总数
|
|
227
|
+
require_count: 0, // 必填属性已填数
|
|
228
|
+
required_list: [], // 必填属性列表
|
|
229
|
+
other_list: [], // 非必填属性列表
|
|
230
|
+
children_list: [] ,// 子属性列表
|
|
231
|
+
|
|
232
|
+
brand_property: {}, // '品牌'属性
|
|
233
|
+
material_quality_property: {}, // ‘材料成分’属性
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// 第一步,先进行筛选,分出“品牌”属性,必填属性,非必填属性,子属性, 其中‘材料成分’属性外部登记(方便后期进行检测)
|
|
237
|
+
properties.forEach(item => {
|
|
238
|
+
|
|
239
|
+
if (item.property_name === '品牌') {
|
|
240
|
+
// 品牌,跳过
|
|
241
|
+
propertiesDatas.brand_property = item
|
|
242
|
+
|
|
243
|
+
} else if (item.show_condition.length) {
|
|
244
|
+
// 子属性,有显示条件
|
|
245
|
+
item.show = false
|
|
246
|
+
propertiesDatas.children_list.push(item)
|
|
247
|
+
|
|
248
|
+
// 子属性初始化
|
|
249
|
+
if (item.property_type == 1 || item.property_type == 4 || item.property_type == 5 || item.property_type == 7 || item.property_type == 8) {
|
|
250
|
+
// 纯文本,数字,日期
|
|
251
|
+
item.property_value = ''
|
|
252
|
+
} else if (item.property_type == 2) {
|
|
253
|
+
// 单选
|
|
254
|
+
item.property_value = {}
|
|
255
|
+
} else if (item.property_type == 3) {
|
|
256
|
+
// 多选
|
|
257
|
+
item.property_value = []
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
} else {
|
|
261
|
+
// 固定属性,区分必填项,与 非必填项
|
|
262
|
+
item.show = true
|
|
263
|
+
if (item.property_required) {
|
|
264
|
+
// 必填
|
|
265
|
+
propertiesDatas.required_list.push(item)
|
|
266
|
+
} else {
|
|
267
|
+
// 非必填
|
|
268
|
+
propertiesDatas.other_list.push(item)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
switch (item.property_type) {
|
|
272
|
+
case 1: // 纯文本
|
|
273
|
+
{
|
|
274
|
+
item.property_value = propertyTools.matchInputProperty(item, goodsPropertys)
|
|
275
|
+
// let index = goodsPropertys.findIndex(attr => attr.attr_name === item.property_name)
|
|
276
|
+
// if (index != -1) {
|
|
277
|
+
// // 匹配到,直接赋值
|
|
278
|
+
// let attr = goodsPropertys[index]
|
|
279
|
+
// // 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
280
|
+
// goodsPropertys.splice(index, 1)
|
|
281
|
+
// item.property_value = attr.value
|
|
282
|
+
// } else {
|
|
283
|
+
// // 没有匹配到,默认为空字符
|
|
284
|
+
// item.property_value = ''
|
|
285
|
+
// }
|
|
286
|
+
// 输入文本数量
|
|
287
|
+
item.input_num = utils.getTextLength(item.property_value)
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case 2: // 单选类型 (根据可以选择的选项多少判断)
|
|
291
|
+
{
|
|
292
|
+
// 搜索关键词
|
|
293
|
+
item.search_key = ''
|
|
294
|
+
|
|
295
|
+
if (item.property_name === '货号') {
|
|
296
|
+
// 货号(快手’货号‘属性为单选)
|
|
297
|
+
|
|
298
|
+
let property_value = item.property_values.find(property_value => property_value.name === goods.goods_sn)
|
|
299
|
+
if (!property_value) {
|
|
300
|
+
// 原数据没有当前货号的选项,新增一个
|
|
301
|
+
property_value = {
|
|
302
|
+
name: goods.goods_sn,
|
|
303
|
+
value_id: 0,
|
|
304
|
+
value: 0,
|
|
305
|
+
parent_value: []
|
|
306
|
+
}
|
|
307
|
+
item.property_values.unshift(property_value)
|
|
308
|
+
}
|
|
309
|
+
item.property_value = property_value
|
|
310
|
+
} else {
|
|
311
|
+
// 其他
|
|
312
|
+
|
|
313
|
+
let index = goodsPropertys.findIndex(attr => attr.attr_name === item.property_name)
|
|
314
|
+
if (index != -1) {
|
|
315
|
+
// 匹配到了
|
|
316
|
+
let attr = goodsPropertys[index]
|
|
317
|
+
// 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
318
|
+
goodsPropertys.splice(index, 1)
|
|
319
|
+
|
|
320
|
+
let property_values = item.show_condition.length ? item.condition_values : item.property_values
|
|
321
|
+
item.property_value = propertyTools.matchSingleSelectPropertyValue(property_values, attr)
|
|
322
|
+
|
|
323
|
+
} else {
|
|
324
|
+
// 未匹配到,默认为空对象
|
|
325
|
+
item.property_value = {}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
case 3: // 多选类型
|
|
331
|
+
{
|
|
332
|
+
// 搜索关键词
|
|
333
|
+
item.search_key = ''
|
|
334
|
+
|
|
335
|
+
let index = goodsPropertys.findIndex(attr => attr.attr_name === item.property_name)
|
|
336
|
+
if (index != -1) {
|
|
337
|
+
// 匹配到了
|
|
338
|
+
let attr = goodsPropertys[index]
|
|
339
|
+
// 移除商品属性列表(减少后期匹配循环次数),目前不可能属性列表存在相同的属性名称
|
|
340
|
+
goodsPropertys.splice(index, 1)
|
|
341
|
+
|
|
342
|
+
let value = []
|
|
343
|
+
if (attr) {
|
|
344
|
+
// 商品有该属性,进行匹配
|
|
345
|
+
if (attr.value instanceof Array) {
|
|
346
|
+
// 数组(原商品属性多选),字符串数组
|
|
347
|
+
attr.value.forEach(attrValue => {
|
|
348
|
+
|
|
349
|
+
if (item.select_max_num > value.length) {
|
|
350
|
+
// 未到限制多选数量,进行匹配
|
|
351
|
+
let valueItem = item.property_values.find(valueItem => valueItem.name === attrValue)
|
|
352
|
+
if (valueItem) {
|
|
353
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
354
|
+
valueItem.isSelect = true
|
|
355
|
+
value.push(valueItem)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
} else {
|
|
360
|
+
// 对象(原商品属性单选)
|
|
361
|
+
if (item.select_max_num > value.length) {
|
|
362
|
+
let valueItem = item.property_values.find(value => value.name === attr.value)
|
|
363
|
+
if (valueItem) {
|
|
364
|
+
// 有匹配到属性值, 并且未到最大选中值
|
|
365
|
+
valueItem.isSelect = true
|
|
366
|
+
value.push(valueItem)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
item.property_value = value ? value : []
|
|
372
|
+
} else {
|
|
373
|
+
// 匹配不到
|
|
374
|
+
item.property_value = []
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (item.select_max_num) {
|
|
378
|
+
// 有限制选择个数
|
|
379
|
+
item.property_tips = `限最多选${item.select_max_num}个`
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
case 4: // 输入,带单位
|
|
384
|
+
{
|
|
385
|
+
item.property_value = ''
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
case 5: // 日期
|
|
389
|
+
{
|
|
390
|
+
item.property_value = ''
|
|
391
|
+
item.property_tips = ''
|
|
392
|
+
}
|
|
393
|
+
break;
|
|
394
|
+
case 6: // 组合多选,目前仅’材质成分‘
|
|
395
|
+
{
|
|
396
|
+
// 外部登记出来,方便进行检测
|
|
397
|
+
propertiesDatas.material_quality_property = item
|
|
398
|
+
if (item.select_max_num) {
|
|
399
|
+
// 有限制选择个数
|
|
400
|
+
item.property_tips = `限最多选${item.select_max_num}个, 且需填写每项【材质】的含量,填写完成后材质成分占比总和必须为100%`
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
case 7: // 日期
|
|
406
|
+
{
|
|
407
|
+
item.property_value = {}
|
|
408
|
+
item.property_tips = ''
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
case 8: // 范围输入,带单位
|
|
412
|
+
{
|
|
413
|
+
item.property_value = ''
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
default:
|
|
417
|
+
{
|
|
418
|
+
item.property_type = 0
|
|
419
|
+
item.property_value = ''
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
// 第二步,进行数据重组排序,必填属性 与 非必填属性 加入子属性
|
|
427
|
+
if (propertiesDatas.children_list.length) {
|
|
428
|
+
// 有子属性, 需要将子属性添加到对应的属性下,子属性多条件显示,添加到列表最后
|
|
429
|
+
// console.log("============= 当前分类存在子分类,需要进行处理 =============")
|
|
430
|
+
let required_list = []
|
|
431
|
+
let other_list = []
|
|
432
|
+
let children_list = [...propertiesDatas.children_list].sort((a, b) => { return b.has_children}) // 排序有子属性的排前
|
|
433
|
+
|
|
434
|
+
propertiesDatas.required_list.forEach(item => {
|
|
435
|
+
// 加入新列表
|
|
436
|
+
required_list.push(item)
|
|
437
|
+
if (item.has_children) {
|
|
438
|
+
// 有子分类,将子分类添加进列表来
|
|
439
|
+
propertyTools.getChildrenProperty(required_list, item, children_list)
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
propertiesDatas.other_list.forEach(item => {
|
|
444
|
+
// 加入临时 非必填属性列表
|
|
445
|
+
other_list.push(item)
|
|
446
|
+
if (item.has_children) {
|
|
447
|
+
// 有子分类,将子分类添加进列表来
|
|
448
|
+
propertyTools.getChildrenProperty(other_list, item, children_list)
|
|
449
|
+
}
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
// 开始合并成新的完整属性列表
|
|
453
|
+
children_list.forEach(item => {
|
|
454
|
+
|
|
455
|
+
if (item.property_required) {
|
|
456
|
+
required_list.push(item)
|
|
457
|
+
} else {
|
|
458
|
+
other_list.push(item)
|
|
459
|
+
}
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
propertiesDatas.required_list = required_list
|
|
463
|
+
propertiesDatas.other_list = other_list
|
|
464
|
+
|
|
465
|
+
// console.log("排序完 必选项", JSON.stringify(required_list))
|
|
466
|
+
// console.log('排序完 非必填项', JSON.stringify(other_list))
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 第三步,合成完整的列表
|
|
470
|
+
propertiesDatas.list = [...propertiesDatas.required_list, ...propertiesDatas.other_list]
|
|
471
|
+
|
|
472
|
+
// 第四步,进行属性值匹配填写(必填项,非必填项,子项)
|
|
473
|
+
propertiesDatas.list.forEach(item => {
|
|
474
|
+
|
|
475
|
+
switch (item.property_type){
|
|
476
|
+
case 1: // 文本
|
|
477
|
+
{
|
|
478
|
+
if (!item.property_value) {
|
|
479
|
+
// 没有选项,进行模糊匹配
|
|
480
|
+
item.property_value = propertyTools.matchInputProperty(item, goodsPropertys)
|
|
481
|
+
}
|
|
482
|
+
if (item.property_required && item.property_value) {
|
|
483
|
+
// 必填 且 有选中项,
|
|
484
|
+
propertiesDatas.require_count++
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
break;
|
|
488
|
+
case 2: // 单选
|
|
489
|
+
{
|
|
490
|
+
if (!item.property_value || !Object.keys(item.property_value).length) {
|
|
491
|
+
// 没有选项,进行匹配
|
|
492
|
+
item.property_value = propertyTools.matchSingleSelectProperty(false ,item, goodsPropertys)
|
|
493
|
+
}
|
|
494
|
+
if (item.property_required && Object.keys(item.property_value).length) {
|
|
495
|
+
// 必填 且 有选中项,
|
|
496
|
+
propertiesDatas.require_count++
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
500
|
+
case 3: // 多选
|
|
501
|
+
{
|
|
502
|
+
|
|
503
|
+
if (!item.property_value || !item.property_value.length) {
|
|
504
|
+
// 没有选项,进行匹配
|
|
505
|
+
item.property_value = propertyTools.matchMultipleSelectProperty(item, goodsPropertys)
|
|
506
|
+
}
|
|
507
|
+
if (item.property_required && item.property_value.length) {
|
|
508
|
+
// 必填 且 有选中项,
|
|
509
|
+
propertiesDatas.require_count++
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
break;
|
|
513
|
+
case 4: // 输入,带单位
|
|
514
|
+
{
|
|
515
|
+
|
|
516
|
+
// if (!item.property_value) {
|
|
517
|
+
// // 没有选项,进行匹配
|
|
518
|
+
// item.property_value = propertyTools.matchMultipleSelectProperty(item, goodsPropertys)
|
|
519
|
+
// }
|
|
520
|
+
if (item.property_required && item.property_value) {
|
|
521
|
+
// 必填 且 有选中项,
|
|
522
|
+
propertiesDatas.require_count++
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
break;
|
|
526
|
+
case 5: // 日期
|
|
527
|
+
{
|
|
528
|
+
if (item.property_required && item.property_value) {
|
|
529
|
+
// 必填 且 有选中项,
|
|
530
|
+
propertiesDatas.require_count++
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
break;
|
|
534
|
+
case 6: // 组合多选 ('材质成分')
|
|
535
|
+
{
|
|
536
|
+
if (!item.property_value || !item.property_value.length) {
|
|
537
|
+
// 没有选项,进行匹配
|
|
538
|
+
item.property_value = propertyTools.matchMaterialQualityProperty(item, goodsPropertys)
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// item.property_value = []
|
|
542
|
+
|
|
543
|
+
if (item.property_required && item.property_value.length) {
|
|
544
|
+
// 必填 且 有选中项,
|
|
545
|
+
propertiesDatas.require_count++
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (item.has_children) {
|
|
554
|
+
// 当前属性有子属性,判断起是否显示
|
|
555
|
+
|
|
556
|
+
propertiesDatas.children_list.forEach(childrenItem => {
|
|
557
|
+
let isShow = true
|
|
558
|
+
|
|
559
|
+
if (childrenItem.show_condition.length) {
|
|
560
|
+
// 子属性 遍历显示条件
|
|
561
|
+
let result = childrenItem.show_condition.find(conditionItem => item.property_id === conditionItem.parent_property_id)
|
|
562
|
+
if (result) {
|
|
563
|
+
// 查询到为当前属性的子属性
|
|
564
|
+
if (!Object.keys(item.property_value).length) {
|
|
565
|
+
// 当前属性没有属性值,子属性不显示
|
|
566
|
+
isShow = false
|
|
567
|
+
} else {
|
|
568
|
+
// 当前属性有选择属性值
|
|
569
|
+
if (result.parent_property_value.includes(item.property_value.value_id)) {
|
|
570
|
+
// 当前子属性需显示,根据父属性选项,筛选子属性可使用的属性
|
|
571
|
+
childrenItem.condition_values = childrenItem.property_values.filter(valueItem => !valueItem.parent_value || !valueItem.parent_value.length || (valueItem.parent_value.length && valueItem.parent_value.includes(item.property_value.value_id)))
|
|
572
|
+
} else {
|
|
573
|
+
// 当前子属性不需要显示
|
|
574
|
+
isShow = false
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
childrenItem.show = isShow
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
}
|
|
582
|
+
})
|
|
583
|
+
|
|
584
|
+
// 第五步,计算必填项数量
|
|
585
|
+
propertyTools.calculateCategroyProperty(propertiesDatas)
|
|
586
|
+
|
|
587
|
+
return propertiesDatas
|
|
588
|
+
|
|
589
|
+
}
|
|
590
|
+
|
|
File without changes
|