Skip to content

Commit ca83c28

Browse files
committed
feature(uniapp分类): review
1 parent 69aafaa commit ca83c28

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/views/mall/product/spu/save.vue

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
<el-tab-pane label="价格库存" name="rates" class="rates">
4040
<el-form ref="rates" :model="ratesForm" :rules="rules">
4141
<el-form-item label="启用多规格">
42-
<!-- TODO @luowenfeng: 1) activeSwitch 可以考虑改成; specSwitch, 更清晰一点, activeSwitch 太通用了; changeRadio 改成 changeSpecSwitch -->
43-
<el-switch v-model="activeSwitch" @change="changeRadio"></el-switch>
42+
<el-switch v-model="specSwitch" @change="changeSpecSwitch"></el-switch>
4443
</el-form-item>
4544

4645
<!-- 动态添加规格属性 -->
@@ -67,7 +66,7 @@
6766
<!-- 规格明细 -->
6867
<el-form-item label="规格明细">
6968
<el-table :data="ratesForm.rates" border style="width: 100%" ref="ratesTable">
70-
<template v-if="this.activeSwitch">
69+
<template v-if="this.specSwitch">
7170
<el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v => v.specName !== undefined)"
7271
:label="item.specName">
7372
<template slot-scope="scope">
@@ -81,7 +80,7 @@
8180
style="width: 100px; height: 50px"/>
8281
</template>
8382
</el-table-column>
84-
<template v-if="this.activeSwitch">
83+
<template v-if="this.specSwitch">
8584
<el-table-column label="sku名称" :render-header="addRedStar" key="91">
8685
<template slot-scope="scope">
8786
<el-form-item :prop="'rates.'+ scope.$index + '.name'"
@@ -148,13 +147,13 @@
148147
<el-input v-model="scope.row.barCode"></el-input>
149148
</template>
150149
</el-table-column>
151-
<template v-if="this.activeSwitch">
150+
<template v-if="this.specSwitch">
152151
<el-table-column fixed="right" label="操作" width="50" key="100">
153152
<template slot-scope="scope">
154153
<el-button @click="scope.row.status = 1" type="text" size="small"
155-
v-show="scope.row.status == undefined || scope.row.status == 0 ">禁用
154+
v-show="scope.row.status === undefined || scope.row.status === 0 ">禁用
156155
</el-button>
157-
<el-button @click="scope.row.status = 0" type="text" size="small" v-show="scope.row.status == 1">
156+
<el-button @click="scope.row.status = 0" type="text" size="small" v-show="scope.row.status === 1">
158157
启用
159158
</el-button>
160159
</template>
@@ -220,7 +219,7 @@ export default {
220219
},
221220
data() {
222221
return {
223-
activeSwitch: false,
222+
specSwitch: false,
224223
activeName: "base",
225224
propName: {
226225
checkStrictly: true,
@@ -287,7 +286,7 @@ export default {
287286
methods: {
288287
removeSpec(index) {
289288
this.dynamicSpec.splice(index, 1);
290-
this.changeRadio()
289+
this.changeSpecSwitch()
291290
},
292291
// 必选标识
293292
addRedStar(h, {column}) {
@@ -296,10 +295,10 @@ export default {
296295
h('span', ' ' + column.label)
297296
];
298297
},
299-
changeRadio() {
300-
this.activeSwitch ? this.ratesForm.spec = 2 : this.ratesForm.spec = 1;
298+
changeSpecSwitch() {
299+
this.specSwitch ? this.ratesForm.spec = 2 : this.ratesForm.spec = 1;
301300
this.$refs.ratesTable.doLayout();
302-
if (this.ratesForm.spec == 1) {
301+
if (this.ratesForm.spec === 1) {
303302
this.ratesForm.rates = [{}]
304303
} else {
305304
this.ratesForm.rates = []
@@ -380,7 +379,7 @@ export default {
380379
})
381380
382381
// 动态规格调整字段
383-
if (this.activeSwitch) {
382+
if (this.specSwitch) {
384383
rates.forEach(r => {
385384
let properties = []
386385
Array.of(r.spec).forEach(s => {
@@ -391,7 +390,7 @@ export default {
391390
obj = Array.of(s);
392391
}
393392
obj.forEach((v, i) => {
394-
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
393+
let specValue = this.dynamicSpec[i].specValue.find(o => o.name === v);
395394
let propertie = {};
396395
propertie.propertyId = this.dynamicSpec[i].specId;
397396
propertie.valueId = specValue.id;
@@ -414,17 +413,20 @@ export default {
414413
}
415414
form.skus = rates;
416415
form.specType = this.ratesForm.spec;
417-
form.categoryId = form.categoryIds[this.baseForm.categoryIds.length - 1];
416+
417+
let category = form.categoryIds instanceof Array ? form.categoryIds: Array.of(form.categoryIds)
418+
console.log(category)
419+
form.categoryId = category[category.length - 1];
418420
419421
if (form.id == null) {
420-
createSpu(form).then((response) => {
422+
createSpu(form).then(() => {
421423
this.$modal.msgSuccess("新增成功");
422424
})
423425
.then(()=>{
424426
this.cancel();
425427
})
426428
} else {
427-
updateSpu(form).then((response) => {
429+
updateSpu(form).then(() => {
428430
this.$modal.msgSuccess("修改成功");
429431
})
430432
.then(()=>{
@@ -443,8 +445,8 @@ export default {
443445
},
444446
// 添加规格项目
445447
changeSpec(val) {
446-
let obj = this.propertyPageList.find(o => o.id == val);
447-
let spec = this.dynamicSpec.find(o => o.specId == val)
448+
let obj = this.propertyPageList.find(o => o.id === val);
449+
let spec = this.dynamicSpec.find(o => o.specId === val)
448450
spec.specId = obj.id;
449451
spec.specName = obj.name;
450452
spec.specValue = obj.values;
@@ -471,8 +473,8 @@ export default {
471473
r.price = this.divide(r.price, 100)
472474
r.costPrice = this.divide(r.costPrice, 100)
473475
})
474-
if (this.ratesForm.spec == 2) {
475-
this.activeSwitch = true;
476+
if (this.ratesForm.spec === 2) {
477+
this.specSwitch = true;
476478
data.productPropertyViews.forEach(p => {
477479
let obj = {};
478480
obj.specId = p.propertyId;
@@ -483,7 +485,7 @@ export default {
483485
data.skus.forEach(s => {
484486
s.spec = [];
485487
s.properties.forEach(sp => {
486-
let spec = data.productPropertyViews.find(o => o.propertyId == sp.propertyId).propertyValues.find(v => v.id == sp.valueId).name;
488+
let spec = data.productPropertyViews.find(o => o.propertyId === sp.propertyId).propertyValues.find(v => v.id === sp.valueId).name;
487489
s.spec.push(spec)
488490
})
489491
})

0 commit comments

Comments
 (0)