step2.vue
15.7 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<template>
<div>
<Form ref="product" :model="product" :label-width="70" :rules="ruleValidate">
<Row>
<div class="create-group">
<span class="create-group-indicator"></span>
<span class="create-group-title">基础信息</span>
<span class="create-group-sub-title">(该信息必须项编缉完成后可以保存, 可以将商品发货入仓)</span>
</div>
</Row>
<Row> <div class="create-item-title">商品基本信息</div> </Row>
<Form-item label="品牌"> <span>{{product.brandName}}</span> </Form-item>
<Form-item label="类目"> <span>{{sortName}}</span> </Form-item>
<Form-item label="商品名称" prop="productName">
<input-safe v-model="product.productName" placeholder="请输入..." style="width: 400px;"/>
</Form-item>
<Form-item label="商品卖点">
<input-safe v-model="product.phrase" :maxlength="12" placeholder="最多12个字符" style="width: 400px;"/>
</Form-item>
<Form-item label="商家商品编码" prop="factoryCode">
<input-safe v-model="product.factoryCode" placeholder="请输入..." style="width: 400px;"/>
</Form-item>
<Form-item label="货品年" prop="goodsYears">
<Date-picker :value="product.goodsYears" @on-change="clickGoodsYear" type="year" placeholder="选择年" style="width: 400px">
</Date-picker>
</Form-item>
<Form-item label="货品季" prop="goodsSeason">
<select-season v-model="product.goodsSeason"></select-season>
</Form-item>
<Form-item label="上市日期" prop="expectSaleTimeStr">
<Date-picker :value="product.expectSaleTimeStr" @on-change="clickSaleDate" type="date" placeholder="选择日期" style="width: 400px"></Date-picker>
</Form-item>
<Form-item label="性别" prop="gender">
<radio-gender v-model="product.gender"></radio-gender>
</Form-item>
<Form-item label="适销季" prop="seasons">
<radio-season v-model="product.seasons"></radio-season>
</Form-item>
<Form-item label="年龄层" prop="ageLevel">
<checkbox-age v-model="product.ageLevel"></checkbox-age>
</Form-item>
<Row>
<div class="create-item-title">商品规格
<span class="create-group-sub-title">(颜色名称只能填写中文,最多5个汉字。款型编码和条码只能填写英文和数字,不区分大小写)</span>
</div>
</Row>
<Form-item label="颜色" prop="selectColor">
<checkbox-color v-model="product.selectColor" @on-add="addColor" @on-remove="removeColor"></checkbox-color>
</Form-item>
<Form-item label="尺寸" prop="selectSize">
<checkbox-size v-model="product.selectSize" :sort-id="product.smallSortId" @on-add="addSize" @on-remove="removeSize"></checkbox-size>
</Form-item>
<Form-item >
<table-good-size ref="sellerGoods" v-model="table.data"></table-good-size>
</Form-item>
<Row> <div class="create-item-title">商品价格</div> </Row>
<Form-item label="吊牌价" prop="retailPrice">
<input-safe v-model="product.retailPrice" :number="true" placeholder="请输入..." style="width: 400px;"/>
</Form-item>
<Form-item label="销售价" prop="salesPrice">
<input-safe v-model="product.salesPrice" :number="true" placeholder="请输入..." style="width: 400px;"/>
</Form-item>
</Form>
<div style="text-align: center">
<Button type="primary" @click="nextStep(1)" size="large">下一步</Button>
<Button type="primary" @click="nextStep(0)" size="large">保存并退出</Button>
</div>
</div>
</template>
<script>
import _ from 'lodash';
import ProductCreateService from 'services/product/product-create-service';
import {step2} from '../store';
const makeColor = () => {
return {
factoryCode: '',
factoryGoodsName: '',
goodsColorImage: '',
goodsName: '',
colorId: '',
isDefault: 'Y',
goodsSizeList: []
};
};
export default {
props: ['step', 'product'],
created() {
this.productCreateService = new ProductCreateService();
},
data() {
return step2.call(this);
},
mounted: function() {
},
methods: {
beforeSubmit: function() {
const handleColor = (color) => {
let newColor = makeColor();
newColor.goodsName = color.goodsName.name;
newColor.isDefault = color.goodsName.isDefault ? 'Y' : 'N';
newColor.factoryGoodsName = color.factoryGoodsName || color.goodsName.name;
newColor.factoryCode = color.factoryCode;
newColor.goodsColorImage = color.goodsColorImage.value;
newColor.colorId = color.colorId;
let goodsSizeList = [];
color.operator.forEach((op, i) => {
if (!op.value) {
return;
}
let goodsSize = {};
goodsSize.sizeId = color.sizeId[i].id;
goodsSize.factoryCode = color.sizeCode[i].name;
goodsSizeList.push(goodsSize);
});
newColor.goodsSizeList = goodsSizeList;
return newColor;
};
this.refreshTable();
this.product.sellerGoodsInfoStr = JSON.stringify(this.table.data.map(handleColor));
},
phraseCheckSensitive() {
let contentModel = {
phrase: this.product.phrase
};
return new Promise((resolve, reject) => {
this.productCreateService.sensitiveWord(contentModel).then((resData) => {
if (resData.code === 200) {
if (resData.data && _.get(resData.data, 'phrase') && resData.data.phrase.length > 0) {
this.$Notice.error({
title: '商品卖点存在违禁词',
desc: resData.data.phrase
});
reject();
} else {
resolve();
}
} else {
this.$Notice.error({
title: '商品卖点文字校验错误',
desc: resData.message
});
reject();
}
});
});
},
submit: function() {
return this.validate().then(() => {
this.beforeSubmit();
this.phraseCheckSensitive();
return this.productCreateService.saveBaseProductInfo(this.product);
}, () => {
this.$Message.error('请填写必填项!');
});
},
nextStep: function(go) {
this.$Loading.start();
this.submit().then((result) => {
this.$Loading.finish();
if (result.code === 200) {
this.$Notice.success({
title: '新建商品基础信息成功!'
});
this.product.productId = result.data.id;
this.product.productSkn = result.data.productSkn;
this.product.goods = result.data.sellerGoodList.map(this.productCreateService.handleGoods);
if (go) {
this.goNext();
} else {
this.saveAndQuit();
}
} else {
this.$Notice.error({
title: result.message,
desc: result.data.join('\n')
});
}
}).catch(() => {
this.$Loading.finish();
});
},
goNext: function() {
this.step.value = 2;
this.$router.push({name: 'product.create.step3'});
},
saveAndQuit: function() {
this.$router.push({name: 'product.offsale'});
},
clickGoodsYear: function(value) {
this.product.goodsYears = value;
},
clickSaleDate: function(value) {
this.product.expectSaleTimeStr = value;
},
initDefault: function() {
let init = _.some(this.table.data, (c) => {
return c.goodsName.isDefault;
});
if (init) {
return;
}
if (_.isEmpty(this.table.data)) {
return;
}
_.first(this.table.data).goodsName.isDefault = true;
},
addColor: function(color) {
this.refreshTable();
this.addColorData(color);
this.table.selectedColors.push(color);
this.initDefault();
},
removeColor(color) {
let findColorIndex = this.table.selectedColors.findIndex((c) => {
return c.id === color.id;
});
if (findColorIndex !== -1) {
this.removeColorData(color);
this.table.selectedColors.splice(findColorIndex, 1);
}
},
addColorData: function(color) {
let newColor = {
goodsName: {
name: color.colorName,
isDefault: false,
},
factoryGoodsName: '',
goodsColorImage: {
value: '',
showValidate: false,
validate: false
},
factoryCode: '',
colorId: color.id,
sizeId: [],
sizeCode: [],
operator: []
};
if (this.table.selectedSizes.length > 0) {
this.table.selectedSizes.forEach((size) => {
this.addSizeData(newColor, size);
});
}
this.table.data.push(newColor);
},
removeColorData: function(color) {
let index = this.table.data.findIndex((d) => {
return d.colorId === color.id;
});
this.table.data.splice(index, 1);
},
addSize: function(sizes) {
this.refreshTable();
let changeSize = _.first(sizes);
this.table.selectedSizes.push(changeSize);
this.table.data.forEach((c) => {
this.addSizeData(c, changeSize);
});
},
removeSize: function(sizes) {
this.refreshTable();
let changeSize = _.first(sizes);
this.table.data.forEach((c) => {
this.removeSizeData(c, changeSize);
});
},
removeSizeData: function(color, findSize) {
let index = color.sizeId.findIndex((s) => {
return s.id === findSize.id;
});
if (index !== -1) {
color.sizeId.splice(index, 1);
color.sizeCode.splice(index, 1);
color.operator.splice(index, 1);
this.table.selectedSizes.splice(index, 1);
}
},
addSizeData: function(color, findSize) {
color.sizeId.push({
id: findSize.id,
name: findSize.sizeName
});
color.sizeCode.push({
name: '',
validate: false,
showValidate: false
});
color.operator.push({
value: true
});
},
refreshTable() {
this.$refs.sellerGoods.syncData();
},
validateOtherProps: function() {
return new Promise((resolve) => {
this.$refs.product.validate((valid) => {
if (valid) {
this.table.showValidateOtherProps = false;
resolve(true);
} else {
this.table.showValidateOtherProps = true;
resolve(false);
}
});
});
},
validateTable: function() {
let _this = this;
return new Promise(function(resolve) {
let errors = [];
_this.table.data.forEach((color, i) => {
let operators = color.operator;
let sizeCodes = color.sizeCode;
operators.forEach((o, j) => {
if (o.value) {
if (!sizeCodes[j].name) {
sizeCodes[j].showValidate = true;
sizeCodes[j].validate = true;
errors.push({row: i, index: j, message: '不能为空'});
} else {
sizeCodes[j].showValidate = false;
}
}
});
let enableCoverOperator = _.some(operators, o => o.value);
if (enableCoverOperator && !color.goodsColorImage.value) {
color.goodsColorImage.showValidate = true;
color.goodsColorImage.validate = true;
errors.push({row: i, message: '商品封面不能为空', field: 'goodsColorImage.name'});
} else {
color.goodsColorImage.showValidate = false;
}
});
if (errors.length !== 0) {
_this.table.showValidateTable = false;
return resolve(false);
} else {
_this.table.showValidateTable = true;
return resolve(true);
}
});
},
validateColor: function() {
let _this = this;
return new Promise((resolve) => {
if (_this.table.selectedColors.length === 0) {
this.table.showValidateColor = true;
return resolve(false);
}
this.table.showValidateColor = false;
return resolve(true);
});
},
validateSize: function() {
return new Promise((resolve, reject) => {
if (this.table.selectedSizes.length === 0) {
this.table.showValidateSize = true;
return reject(false);
}
this.table.showValidateSize = false;
return resolve(true);
});
},
validate: function() {
this.refreshTable();
return Promise.all([
this.validateOtherProps(),
this.validateColor(),
this.validateSize(),
this.validateTable()
]).then((valid) => {
if (valid[0] && valid[1] && valid[2] && valid[3]) {
return Promise.resolve();
} else {
return Promise.reject();
}
});
}
},
computed: {
sortName: function() {
return this.product.maxSortName + '/' + this.product.middleSortName + '/' + this.product.smallSortName;
}
}
};
</script>
<style lang="scss">
</style>