Skip to content

Commit d8d784a

Browse files
committed
feature(uniapp商品): 商品加载
1 parent 38532d0 commit d8d784a

File tree

3 files changed

+85
-98
lines changed

3 files changed

+85
-98
lines changed

src/api/mall/product/brand.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ export function getBrand(id) {
3434
})
3535
}
3636

37+
// 获得品牌list
38+
export function getBrandList() {
39+
return request({
40+
url: '/product/brand/list',
41+
method: 'get'
42+
})
43+
}
44+
45+
3746
// 获得品牌分页
3847
export function getBrandPage(query) {
3948
return request({

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

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179

180180

181181
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false" >
182-
<save @closeDialog="open = false; getList()"/>
182+
<save @closeDialog="closeDialog" :type="dialogType" :obj="dialogObj" v-if="open" />
183183
</el-dialog>
184184
</div>
185185
</template>
@@ -257,6 +257,10 @@ export default {
257257
title: "",
258258
// 是否显示弹出层
259259
open: false,
260+
// 弹出层类型
261+
dialogType: "add",
262+
// 弹出层参数
263+
dialogObj:{},
260264
dateRangeCreateTime: [],
261265
// 查询参数
262266
queryParams: {
@@ -570,75 +574,25 @@ export default {
570574
},
571575
/** 新增按钮操作 */
572576
handleAdd() {
573-
this.reset();
577+
this.dialogType = "add";
578+
this.dialogObj={};
574579
this.open = true;
575580
this.title = "添加商品spu";
576-
this.getPropertyPageList();
577581
},
578582
/** 修改按钮操作 */
579583
handleUpdate(row) {
580-
this.reset();
581-
const id = row.id;
582-
getSpu(id).then((response) => {
583-
let dataSpu = response.data;
584-
this.form = {
585-
id: dataSpu.id,
586-
name: dataSpu.name,
587-
sellPoint: dataSpu.sellPoint,
588-
description: dataSpu.sellPoint,
589-
categoryId: dataSpu.sellPoint,
590-
categoryIds: dataSpu.categoryIds,
591-
picUrls: dataSpu.picUrls,
592-
sort: dataSpu.sort,
593-
likeCount: dataSpu.likeCount,
594-
price: dataSpu.price,
595-
quantity: dataSpu.quantity,
596-
status: dataSpu.status,
597-
isShowTagInput: undefined,
598-
skus: [],
599-
skusList: dataSpu.skus,
600-
productPropertyViews: dataSpu.productPropertyViews,
601-
// skus:dataSpu.productSkuRespVOS,
602-
};
603-
this.getDataHandle();
604-
this.open = true;
605-
this.title = "修改商品spu";
606-
});
584+
this.dialogType = "upd";
585+
this.dialogObj.id = row.id;
586+
this.open = true;
587+
console.log("修改")
588+
this.title = "修改商品spu";
607589
},
608-
getDataHandle() {
609-
let that = this;
610-
let productPropertyViews = JSON.parse(
611-
JSON.stringify(this.form.productPropertyViews)
612-
);
613-
productPropertyViews = productPropertyViews.sort(
614-
(a, b) => a.propertyId - b.propertyId
615-
);
616-
productPropertyViews.forEach((item) => {
617-
item.propertyValues = item.propertyValues.sort((a, b) => a.v1 - b.v1);
618-
});
619-
let skuIds = [];
620-
for (let i = 0; i < productPropertyViews.length; i++) {
621-
let han = {
622-
name: productPropertyViews[i].name,
623-
propertyId: productPropertyViews[i].propertyId,
624-
selectValues: [],
625-
selectValueIds: [],
626-
};
627-
for (
628-
let j = 0;
629-
j < productPropertyViews[i].propertyValues.length;
630-
j++
631-
) {
632-
han.selectValues.push(productPropertyViews[i].propertyValues[j].v2);
633-
han.selectValueIds.push(productPropertyViews[i].propertyValues[j].v1);
634-
}
635-
skuIds.push(han);
636-
}
637-
this.skuTags = skuIds;
638-
this.unUseTags = this.allhistoryTags.filter((v) =>
639-
skuIds.every((val) => val.name != v.name)
640-
);
641-
this.getHandleTable();
590+
closeDialog(){
591+
console.log("关闭")
592+
this.dialogType = "add";
593+
this.dialogObj={};
594+
this.open = false;
595+
this.getList()
642596
},
643597
getHandleTable() {
644598
this.form.skus = [];
@@ -699,33 +653,6 @@ export default {
699653
}
700654
});
701655
},
702-
/** 提交按钮 */
703-
submitForm() {
704-
this.$refs["form"].validate((valid) => {
705-
if (!valid) {
706-
return;
707-
}
708-
this.form.picUrls = this.form.picUrls.split(",");
709-
this.form.categoryId =
710-
this.form.categoryIds[this.form.categoryIds.length - 1];
711-
this.form.status = Number(this.form.status);
712-
// 修改的提交
713-
if (this.form.id != null) {
714-
updateSpu(this.form).then((response) => {
715-
this.$modal.msgSuccess("修改成功");
716-
this.open = false;
717-
this.getList();
718-
});
719-
return;
720-
}
721-
// 添加的提交
722-
createSpu(this.form).then((response) => {
723-
this.$modal.msgSuccess("新增成功");
724-
this.open = false;
725-
this.getList();
726-
});
727-
});
728-
},
729656
/** 删除按钮操作 */
730657
handleDelete(row) {
731658
const id = row.id;

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@
193193
<!-- 销售设置 -->
194194
<el-tab-pane label="销售设置" name="fourth">
195195
<el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
196+
<el-form-item label="所属品牌" prop="brandId">
197+
<el-select v-model="baseForm.brandId" placeholder="请选择">
198+
<el-option
199+
v-for="item in brandList"
200+
:key="item.id"
201+
:label="item.name"
202+
:value="item.id">
203+
</el-option>
204+
</el-select>
205+
</el-form-item>
196206
<el-form-item label="虚拟销量" prop="virtualSalesCount">
197207
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
198208
</el-form-item>
@@ -221,8 +231,10 @@
221231
</template>
222232

223233
<script>
234+
235+
import {getBrandList} from "@/api/mall/product/brand";
224236
import {getProductCategoryList} from "@/api/mall/product/category";
225-
import {createSpu,} from "@/api/mall/product/spu";
237+
import {createSpu, getSpu} from "@/api/mall/product/spu";
226238
import {getPropertyPage,} from "@/api/mall/product/property";
227239
import Editor from "@/components/Editor";
228240
import ImageUpload from "@/components/ImageUpload";
@@ -232,6 +244,13 @@ export default {
232244
Editor,
233245
ImageUpload
234246
},
247+
props:{//props列表
248+
type:{
249+
type:String,
250+
default:"add" //定义参数默认值
251+
},
252+
obj: Object
253+
},
235254
data() {
236255
return {
237256
activeName: "base",
@@ -251,6 +270,7 @@ export default {
251270
status: 0,
252271
virtualSalesCount: 0,
253272
showStock: true,
273+
brandId: null
254274
},
255275
categoryList: [],
256276
// 价格库存
@@ -270,6 +290,7 @@ export default {
270290
// },
271291
],
272292
propertyPageList: [],
293+
brandList: [],
273294
specValue: null,
274295
275296
// 表单校验
@@ -283,11 +304,13 @@ export default {
283304
},
284305
};
285306
},
286-
287307
created() {
288-
308+
this.getListBrand();
289309
this.getListCategory();
290310
this.getPropertyPageList();
311+
if(this.type == 'upd'){
312+
this.updateType(this.obj.id)
313+
}
291314
},
292315
methods: {
293316
removeSpec(index){
@@ -351,6 +374,13 @@ export default {
351374
getProductCategoryList().then((response) => {
352375
this.categoryList = this.handleTree(response.data, "id", "parentId");
353376
});
377+
},
378+
/** 查询品牌列表 */
379+
getListBrand() {
380+
// 执行查询
381+
getBrandList().then((response) => {
382+
this.brandList = response.data;
383+
});
354384
},
355385
cancel() {
356386
this.$emit("closeDialog");
@@ -366,7 +396,13 @@ export default {
366396
rates.forEach(r => {
367397
let properties = []
368398
Array.of(r.spec).forEach(s => {
369-
Array.of(s).forEach((v, i) => {
399+
let obj;
400+
if (s instanceof Array) {
401+
obj = s;
402+
}else{
403+
obj = Array.of(s);
404+
}
405+
obj.forEach((v, i) => {
370406
console.log(this.dynamicSpec, r, s, v, i)
371407
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
372408
console.log(specValue)
@@ -382,9 +418,6 @@ export default {
382418
rates[0].name = this.baseForm.name;
383419
rates[0].status = this.baseForm.status;
384420
}
385-
386-
console.log(rates)
387-
388421
let form = this.baseForm
389422
if(form.picUrls instanceof Array){
390423
form.picUrls = form.picUrls.flatMap(m=>m.split(','))
@@ -422,6 +455,24 @@ export default {
422455
spec.specValue = obj.propertyValueList;
423456
this.dynamicSpec = dynamicSpec;
424457
this.buildRatesFormRates();
458+
},
459+
updateType(id){
460+
getSpu(id).then((response) =>{
461+
console.log(response)
462+
let data = response.data;
463+
this.baseForm.name=data.name;
464+
this.baseForm.sellPoint=data.sellPoint;
465+
this.baseForm.categoryIds=data.categoryIds;
466+
this.baseForm.sort=data.sort;
467+
this.baseForm.description=data.description;
468+
this.baseForm.picUrls=data.picUrls;
469+
this.baseForm.status=data.status;
470+
this.baseForm.virtualSalesCount=data.virtualSalesCount;
471+
this.baseForm.showStock=data.showStock;
472+
this.baseForm.brandId=data.brandId;
473+
this.ratesForm.spec=data.specType;
474+
this.ratesForm.rates=data.skus
475+
})
425476
}
426477
},
427478
};

0 commit comments

Comments
 (0)