Commit ab6fd305516e6e63fee6c0f481a3b21e9b87f826

Authored by luowenfeng
1 parent 198b1189

feature(uniapp商品): 商品功能完善

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuCreateOrUpdateReqVO.java
1 1 package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
2 2  
3 3 import io.swagger.annotations.ApiModel;
  4 +import io.swagger.annotations.ApiModelProperty;
4 5 import lombok.Data;
5 6 import lombok.EqualsAndHashCode;
6 7 import lombok.ToString;
7 8  
  9 +import javax.validation.constraints.NotEmpty;
  10 +
8 11 @ApiModel("管理后台 - 商品 SKU 创建/更新 Request VO")
9 12 @Data
10 13 @EqualsAndHashCode(callSuper = true)
11 14 @ToString(callSuper = true)
12 15 public class ProductSkuCreateOrUpdateReqVO extends ProductSkuBaseVO {
13 16  
  17 + @ApiModelProperty(value = "商品 id 更新时须有", example = "1")
  18 + private Long id;
  19 +
14 20 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java
... ... @@ -65,10 +65,21 @@ public class ProductSpuBaseVO {
65 65 @NotNull(message = "是否展示库存不能为空")
66 66 private Boolean showStock;
67 67  
  68 + @ApiModelProperty(value = "库存", required = true, example = "true")
  69 + private Integer totalStock;
  70 +
  71 + @ApiModelProperty(value = " 最小价格,单位使用:分", required = true, example = "1024")
  72 + private Integer minPrice;
  73 +
  74 + @ApiModelProperty(value = "最大价格,单位使用:分", required = true, example = "1024")
  75 + private Integer maxPrice;
  76 +
68 77 // ========== 统计相关字段 =========
69 78  
70 79 @ApiModelProperty(value = "虚拟销量", required = true, example = "1024")
71 80 @NotNull(message = "虚拟销量不能为空")
72 81 private Integer virtualSalesCount;
73 82  
  83 + @ApiModelProperty(value = "点击量", example = "1024")
  84 + private Integer clickCount;
74 85 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/SpuPageReqVO.java
... ... @@ -42,7 +42,7 @@ public class SpuPageReqVO extends PageParam {
42 42 private Integer quantity;
43 43  
44 44 @ApiModelProperty(value = "上下架状态: 0 上架(开启) 1 下架(禁用)")
45   - private Boolean status;
  45 + private Integer status;
46 46  
47 47 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
48 48 @ApiModelProperty(value = "创建时间")
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/spu/ProductSpuMapper.java
... ... @@ -19,16 +19,11 @@ public interface ProductSpuMapper extends BaseMapperX<ProductSpuDO> {
19 19 return selectPage(reqVO, new LambdaQueryWrapperX<ProductSpuDO>()
20 20 .likeIfPresent(ProductSpuDO::getName, reqVO.getName())
21 21 .eqIfPresent(ProductSpuDO::getSellPoint, reqVO.getSellPoint())
22   - .eqIfPresent(ProductSpuDO::getDescription, reqVO.getDescription())
23 22 .eqIfPresent(ProductSpuDO::getCategoryId, reqVO.getCategoryId())
24 23 .eqIfPresent(ProductSpuDO::getPicUrls, reqVO.getPicUrls())
25   - .eqIfPresent(ProductSpuDO::getSort, reqVO.getSort())
26   -// .eqIfPresent(ProductSpuDO::getLikeCount, reqVO.getLikeCount())
27   -// .eqIfPresent(ProductSpuDO::getPrice, reqVO.getPrice())
28   -// .eqIfPresent(ProductSpuDO::getQuantity, reqVO.getQuantity())
29 24 .eqIfPresent(ProductSpuDO::getStatus, reqVO.getStatus())
30 25 .betweenIfPresent(ProductSpuDO::getCreateTime, reqVO.getCreateTime())
31   - .orderByDesc(ProductSpuDO::getId));
  26 + .orderByDesc(ProductSpuDO::getSort));
32 27 }
33 28  
34 29 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
... ... @@ -90,17 +90,19 @@ public class ProductSpuServiceImpl implements ProductSpuService {
90 90 validateSpuExists(updateReqVO.getId());
91 91 // 校验分类
92 92 categoryService.validateProductCategory(updateReqVO.getCategoryId());
93   - // TODO @luowenfeng:校验品牌
  93 + // 校验品牌
  94 + brandService.validateProductBrand(updateReqVO.getBrandId());
94 95 // 校验SKU
95 96 List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = updateReqVO.getSkus();
96 97 // 多规格才需校验
97 98 productSkuService.validateProductSkus(skuCreateReqList, updateReqVO.getSpecType());
98   -
99 99 // 更新 SPU
100 100 ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
101   - // TODO @计算各种字段
  101 + updateObj.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice));
  102 + updateObj.setMaxPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice));
  103 + updateObj.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice));
  104 + updateObj.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
102 105 ProductSpuMapper.updateById(updateObj);
103   -
104 106 // 更新 SKU
105 107 productSkuService.updateProductSkus(updateObj.getId(), updateReqVO.getSkus());
106 108 }
... ... @@ -149,7 +151,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
149 151 ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName());
150 152 propertyValues.add(tuple2);
151 153 });
152   - productPropertyViewRespVO.setPropertyValues(propertyValues);
  154 + productPropertyViewRespVO.setPropertyValues(propertyValues.stream().distinct().collect(Collectors.toList()));
153 155 productPropertyViews.add(productPropertyViewRespVO);
154 156 });
155 157 spuVO.setProductPropertyViews(productPropertyViews);
... ...
yudao-ui-admin/src/main.js
... ... @@ -16,7 +16,7 @@ import &#39;./permission&#39; // permission control
16 16 import './tongji' // 百度统计
17 17 import { getDicts } from "@/api/system/dict/data";
18 18 import { getConfigKey } from "@/api/infra/config";
19   -import { parseTime, resetForm, handleTree, addBeginAndEndTime} from "@/utils/ruoyi";
  19 +import { parseTime, resetForm, handleTree, addBeginAndEndTime, divide} from "@/utils/ruoyi";
20 20 import Pagination from "@/components/Pagination";
21 21 // 自定义表格工具扩展
22 22 import RightToolbar from "@/components/RightToolbar"
... ... @@ -36,6 +36,7 @@ Vue.prototype.getDictDataLabel = getDictDataLabel
36 36 Vue.prototype.DICT_TYPE = DICT_TYPE
37 37 Vue.prototype.handleTree = handleTree
38 38 Vue.prototype.addBeginAndEndTime = addBeginAndEndTime
  39 +Vue.prototype.divide = divide
39 40  
40 41 // 全局组件挂载
41 42 Vue.component('DictTag', DictTag)
... ...
yudao-ui-admin/src/utils/ruoyi.js
... ... @@ -222,3 +222,17 @@ export function getPath(path) {
222 222 }
223 223 return basePath + path;
224 224 }
  225 +
  226 +/**
  227 + * 除法保留两位小数
  228 + *
  229 + * @param {*} divisor 除数
  230 + * @param {*} dividend 被除数
  231 + * @returns
  232 + */
  233 + export function divide(divisor, dividend) {
  234 + if(divisor == null || dividend == null || dividend == 0){
  235 + return null;
  236 + }
  237 + return Math.floor(divisor/dividend*100)/100;
  238 +}
... ...
yudao-ui-admin/src/views/mall/product/spu/index.vue
... ... @@ -17,14 +17,6 @@
17 17 @keyup.enter.native="handleQuery"
18 18 />
19 19 </el-form-item>
20   - <el-form-item label="卖点" prop="sellPoint">
21   - <el-input
22   - v-model="queryParams.sellPoint"
23   - placeholder="请输入卖点"
24   - clearable
25   - @keyup.enter.native="handleQuery"
26   - />
27   - </el-form-item>
28 20 <el-form-item label="分类id" prop="categoryId">
29 21 <el-input
30 22 v-model="queryParams.categoryId"
... ... @@ -33,22 +25,6 @@
33 25 @keyup.enter.native="handleQuery"
34 26 />
35 27 </el-form-item>
36   - <el-form-item label="价格(分)" prop="price">
37   - <el-input
38   - v-model="queryParams.price"
39   - placeholder="请输入价格 单位使用:分"
40   - clearable
41   - @keyup.enter.native="handleQuery"
42   - />
43   - </el-form-item>
44   - <el-form-item label="库存数量" prop="quantity">
45   - <el-input
46   - v-model="queryParams.quantity"
47   - placeholder="请输入库存数量"
48   - clearable
49   - @keyup.enter.native="handleQuery"
50   - />
51   - </el-form-item>
52 28 <el-form-item label="状态" prop="status">
53 29 <el-select
54 30 v-model="queryParams.status"
... ... @@ -115,8 +91,6 @@
115 91 <el-table v-loading="loading" :data="list">
116 92 <el-table-column label="主键" align="center" prop="id" />
117 93 <el-table-column label="商品名称" align="center" prop="name" />
118   - <!-- <el-table-column label="卖点" align="center" prop="sellPoint"/>-->
119   - <!-- <el-table-column label="描述" align="center" prop="description"/>-->
120 94 <el-table-column label="分类id" align="center" prop="categoryId" />
121 95 <el-table-column label="商品主图地址" align="center" prop="picUrls">
122 96 <template slot-scope="scope">
... ... @@ -129,10 +103,14 @@
129 103 </template>
130 104 </el-table-column>
131 105 <el-table-column label="排序字段" align="center" prop="sort" />
132   - <el-table-column label="点赞初始人数" align="center" prop="likeCount" />
133   - <el-table-column label="价格 (分)" align="center" prop="price" />
134   - <el-table-column label="库存数量" align="center" prop="quantity" />
135   - <!-- <el-table-column label="状态" align="center" prop="status"/>-->
  106 + <el-table-column label="点击量" align="center" prop="clickCount" />
  107 + <el-table-column label="价格区间" align="center" prop="price" />
  108 + <el-table-column label="总库存" align="center" prop="totalStock" />
  109 + <el-table-column label="状态" align="center" prop="status">
  110 + <template slot-scope="scope">
  111 + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  112 + </template>
  113 + </el-table-column>
136 114 <el-table-column
137 115 label="创建时间"
138 116 align="center"
... ... @@ -186,29 +164,10 @@
186 164  
187 165 <script>
188 166 import {
189   - createSpu,
190   - updateSpu,
191 167 deleteSpu,
192   - getSpu,
193 168 getSpuPage,
194 169 exportSpuExcel,
195 170 } from "@/api/mall/product/spu";
196   -import {
197   - createProductCategory,
198   - deleteProductCategory,
199   - exportCategoryExcel,
200   - getProductCategory,
201   - getProductCategoryList,
202   - updateProductCategory,
203   -} from "@/api/mall/product/category";
204   -import {
205   - createProperty,
206   - updateProperty,
207   - deleteProperty,
208   - getProperty,
209   - getPropertyPage,
210   - exportPropertyExcel,
211   -} from "@/api/mall/product/property";
212 171  
213 172 import Editor from "@/components/Editor";
214 173 import ImageUpload from "@/components/ImageUpload";
... ... @@ -237,11 +196,6 @@ export default {
237 196 selectObect: [],
238 197 },
239 198 skuTags: [],
240   - propName: {
241   - checkStrictly: true,
242   - label: "name",
243   - value: "id",
244   - },
245 199 categoryList: [],
246 200 // 遮罩层
247 201 loading: true,
... ... @@ -277,251 +231,13 @@ export default {
277 231 quantity: null,
278 232 status: null,
279 233 },
280   - // 表单参数
281   - form: {
282   - id: undefined,
283   - name: undefined,
284   - sellPoint: undefined,
285   - description: undefined,
286   - categoryId: undefined,
287   - categoryIds: [],
288   - picUrls: undefined,
289   - sort: undefined,
290   - likeCount: undefined,
291   - price: undefined,
292   - quantity: undefined,
293   - status: undefined,
294   - isShowTagInput: undefined,
295   - skus: [],
296   - },
297   - // 表单校验
298   - rules: {
299   - sellPoint: [
300   - { required: true, message: "卖点不能为空", trigger: "blur" },
301   - ],
302   - description: [
303   - { required: true, message: "描述不能为空", trigger: "blur" },
304   - ],
305   - categoryIds: [
306   - { required: true, message: "分类id不能为空", trigger: "blur" },
307   - ],
308   - picUrls: [{ required: true, message: "商品主图地址", trigger: "blur" }],
309   - sort: [
310   - { required: true, message: "排序字段不能为空", trigger: "blur" },
311   - ],
312   - },
313 234 tagIndex: 0,
314 235 };
315 236 },
316 237 created() {
317 238 this.getList();
318   - this.getPropertyPageList();
319   - this.getListCategory();
320 239 },
321 240 methods: {
322   - getTableSpecData() {
323   - return this.value;
324   - },
325   - tableSpanMethod({ row, column, rowIndex, columnIndex }) {},
326   - changeSkuStatus(tagIndex) {
327   - if (this.form.skus[tagIndex].status == 0) {
328   - this.form.skus[tagIndex].status = 1;
329   - } else {
330   - this.form.skus[tagIndex].status = 0;
331   - }
332   - },
333   - skuAddProdName() {
334   - if (this.initing) {
335   - return;
336   - }
337   - let skuList = [];
338   - for (let i = 0; i < this.value.length; i++) {
339   - const sku = Object.assign({}, this.value[i]);
340   - if (!sku.properties) {
341   - return;
342   - }
343   - sku.skuName = "";
344   - let properties = sku.properties.split(";");
345   - for (const propertiesKey in properties) {
346   - sku.skuName += properties[propertiesKey].split(":")[1] + " ";
347   - }
348   - sku.prodName = this.prodName + " " + sku.skuName;
349   - skuList.push(sku);
350   - }
351   - this.$emit("input", skuList);
352   - },
353   - handleTagClose(tagIndex, tagItemIndex) {},
354   - //确定添加sku规格
355   - addTag() {
356   - let skus = this.unUseTags.map(function (item, index) {
357   - return item.name;
358   - });
359   - let index = skus.indexOf(this.addTagInput.name);
360   -
361   - this.addTagInput.propertyId = this.unUseTags[index].id;
362   - for (let i = 0; i < this.addTagInput.selectValues.length; i++) {
363   - for (
364   - let j = 0;
365   - j < this.unUseTags[index].propertyValueList.length;
366   - j++
367   - ) {
368   - if (
369   - this.addTagInput.selectValues[i] ===
370   - this.unUseTags[index].propertyValueList[j].name
371   - ) {
372   - this.addTagInput.selectValueIds.push(
373   - this.unUseTags[index].propertyValueList[j].id
374   - );
375   - this.addTagInput.selectObect.push({
376   - id: this.unUseTags[index].propertyValueList[j].id,
377   - name: this.unUseTags[index].propertyValueList[j].name,
378   - });
379   - }
380   - }
381   - }
382   - let addTagInput = JSON.parse(JSON.stringify(this.addTagInput));
383   - this.skuTags.push(addTagInput);
384   -
385   - // if (this.skuTags.length > 1) {
386   - this.skuTags = this.skuTags.sort((a, b) => a.propertyId - b.propertyId);
387   - this.skuTags.forEach(function (item, index) {
388   - item.selectObect = item.selectObect.sort((a, b) => a.id - b.id);
389   - });
390   -
391   - for (let i = 0; i < this.skuTags.length; i++) {
392   - let selectValueIds = [];
393   - let selectValues = [];
394   - for (let j = 0; j < this.skuTags[i].selectObect.length; j++) {
395   - selectValueIds.push(this.skuTags[i].selectObect[j].id);
396   - selectValues.push(this.skuTags[i].selectObect[j].name);
397   - }
398   - this.skuTags[i].selectValues = selectValues;
399   - this.skuTags[i].selectValueIds = selectValueIds;
400   - }
401   -
402   - this.unUseTags.splice(index, 1);
403   - this.isShowTagInput = false;
404   - this.getTable();
405   - },
406   - getTable() {
407   - this.form.skus = [];
408   - let skuTags = JSON.parse(JSON.stringify(this.skuTags));
409   - let sku1s = [];
410   - let skuIds = [];
411   - let propertyIds = [];
412   - let propertyNames = [];
413   - for (let i = 0; i < skuTags.length; i++) {
414   - sku1s.push(skuTags[i].selectValues);
415   - skuIds.push(skuTags[i].selectValueIds);
416   - propertyIds.push(skuTags[i].propertyId);
417   - propertyNames.push(skuTags[i].name);
418   - }
419   -
420   - let skuAll = sku1s.reduce(
421   - (x, y) => {
422   - let arr = [];
423   - x.forEach((m) => y.forEach((y) => arr.push(m.concat([y]))));
424   - return arr;
425   - },
426   - [[]]
427   - );
428   -
429   - let skuIdAll = skuIds.reduce(
430   - (x, y) => {
431   - let arr = [];
432   - x.forEach((m) => y.forEach((y) => arr.push(m.concat([y]))));
433   - return arr;
434   - },
435   - [[]]
436   - );
437   -
438   - for (let i = 0; i < skuAll.length; i++) {
439   - let han = {
440   - propertyNames: propertyNames,
441   - propertyIds: propertyIds,
442   - propertyChildNames: skuAll[i],
443   - propertyChildIds: skuIdAll[i],
444   - properties: [],
445   - picUrl: "",
446   - costPrice: "",
447   - originalPrice: "",
448   - spuId: "",
449   - prodName: "",
450   - price: "",
451   - barCode: "",
452   - status: "0",
453   - };
454   - this.form.skus.push(han);
455   - }
456   - this.form.skus.forEach((x) => {
457   - x.properties = [];
458   - for (let i = 0; i < x.propertyIds.length; i++) {
459   - x.properties.push({
460   - propertyId: x.propertyIds[i],
461   - valueId: x.propertyChildIds[i],
462   - });
463   - }
464   - });
465   - },
466   - hideTagInput() {
467   - this.isShowTagInput = false;
468   - this.addTagInput = {
469   - name: "",
470   - propertyId: "",
471   - selectValues: [],
472   - selectValueIds: [],
473   - selectObect: [],
474   - };
475   - },
476   - shopTagInput() {
477   - if (this.unUseTags.length <= 0) {
478   - return this.$message.error("规格已经添加完毕");
479   - }
480   - this.isShowTagInput = true;
481   - this.addTagInput = {
482   - name: "",
483   - propertyId: "",
484   - selectValues: [],
485   - selectValueIds: [],
486   - selectObect: [],
487   - };
488   - },
489   - //删除已选的规格
490   - removeTag(row) {
491   - let skus = this.allhistoryTags.map(function (item, index) {
492   - return item.name;
493   - });
494   - let index = skus.indexOf(this.skuTags[row].name);
495   - this.unUseTags.push(this.allhistoryTags[index]);
496   - this.skuTags.splice(row, 1);
497   - this.getTable();
498   - },
499   - handleTagClick(row) {
500   - for (let i = 0; i < this.propertyPageList.length; i++) {
501   - if (row == this.propertyPageList[i].name) {
502   - this.dbTagValues = this.propertyPageList[i].propertyValueList;
503   - }
504   - }
505   - },
506   - /** 查询规格 */
507   - getPropertyPageList() {
508   - // 执行查询
509   - getPropertyPage().then((response) => {
510   - this.propertyPageList = response.data.list;
511   -
512   - this.unUseTags = this.propertyPageList.map(function (item, index) {
513   - return item;
514   - });
515   - this.allhistoryTags = JSON.parse(JSON.stringify(this.unUseTags));
516   - });
517   - },
518   - /** 查询分类 */
519   - getListCategory() {
520   - // 执行查询
521   - getProductCategoryList().then((response) => {
522   - this.categoryList = this.handleTree(response.data, "id", "parentId");
523   - });
524   - },
525 241 /** 查询列表 */
526 242 getList() {
527 243 this.loading = true;
... ... @@ -530,37 +246,20 @@ export default {
530 246 this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
531 247 // 执行查询
532 248 getSpuPage(params).then((response) => {
  249 + response.data.list.forEach(element => {
  250 + element.price = this.divide(element.minPrice, 100)+"~"+this.divide(element.maxPrice, 100)
  251 + });
533 252 this.list = response.data.list;
534 253 this.total = response.data.total;
535 254 this.loading = false;
536 255 });
537 256 },
  257 +
538 258 /** 取消按钮 */
539 259 cancel() {
540 260 this.open = false;
541 261 this.reset();
542 262 },
543   - /** 表单重置 */
544   - reset() {
545   - this.form = {
546   - id: undefined,
547   - name: undefined,
548   - sellPoint: undefined,
549   - description: undefined,
550   - categoryId: undefined,
551   - categoryIds: [],
552   - picUrls: undefined,
553   - sort: undefined,
554   - likeCount: undefined,
555   - price: undefined,
556   - quantity: undefined,
557   - status: undefined,
558   - isShowTagInput: undefined,
559   - skus: [],
560   - };
561   - this.skuTags = [];
562   - this.resetForm("form");
563   - },
564 263 /** 搜索按钮操作 */
565 264 handleQuery() {
566 265 this.queryParams.pageNo = 1;
... ... @@ -594,65 +293,6 @@ export default {
594 293 this.open = false;
595 294 this.getList()
596 295 },
597   - getHandleTable() {
598   - this.form.skus = [];
599   - let skuTags = JSON.parse(JSON.stringify(this.skuTags));
600   - let sku1s = [];
601   - let skuIds = [];
602   - let propertyIds = [];
603   - let propertyNames = [];
604   - for (let i = 0; i < skuTags.length; i++) {
605   - sku1s.push(skuTags[i].selectValues);
606   - skuIds.push(skuTags[i].selectValueIds);
607   - propertyIds.push(skuTags[i].propertyId);
608   - propertyNames.push(skuTags[i].name);
609   - }
610   - let skuAll = sku1s.reduce(
611   - (x, y) => {
612   - let arr = [];
613   - x.forEach((m) => y.forEach((y) => arr.push(m.concat([y]))));
614   - return arr;
615   - },
616   - [[]]
617   - );
618   -
619   - let skuIdAll = skuIds.reduce(
620   - (x, y) => {
621   - let arr = [];
622   - x.forEach((m) => y.forEach((y) => arr.push(m.concat([y]))));
623   - return arr;
624   - },
625   - [[]]
626   - );
627   -
628   - for (let i = 0; i < skuAll.length; i++) {
629   - let han = {
630   - propertyNames: propertyNames,
631   - propertyIds: propertyIds,
632   - propertyChildNames: skuAll[i],
633   - propertyChildIds: skuIdAll[i],
634   - properties: this.form.skusList[i].properties,
635   - picUrl: this.form.skusList[i].picUrl,
636   - costPrice: this.form.skusList[i].costPrice,
637   - originalPrice: this.form.skusList[i].originalPrice,
638   - spuId: this.form.skusList[i].spuId,
639   - prodName: this.form.skusList[i].prodName,
640   - price: this.form.skusList[i].price,
641   - barCode: this.form.skusList[i].barCode,
642   - status: this.form.skusList[i].status,
643   - };
644   - this.form.skus.push(han);
645   - }
646   - this.form.skus.forEach((x) => {
647   - x.properties = [];
648   - for (let i = 0; i < x.propertyIds.length; i++) {
649   - x.properties.push({
650   - propertyId: x.propertyIds[i],
651   - valueId: x.propertyChildIds[i],
652   - });
653   - }
654   - });
655   - },
656 296 /** 删除按钮操作 */
657 297 handleDelete(row) {
658 298 const id = row.id;
... ...
yudao-ui-admin/src/views/mall/product/spu/save.vue
... ... @@ -234,7 +234,7 @@
234 234  
235 235 import {getBrandList} from "@/api/mall/product/brand";
236 236 import {getProductCategoryList} from "@/api/mall/product/category";
237   -import {createSpu, getSpu} from "@/api/mall/product/spu";
  237 +import {createSpu, updateSpu, getSpu} from "@/api/mall/product/spu";
238 238 import {getPropertyPage,} from "@/api/mall/product/property";
239 239 import Editor from "@/components/Editor";
240 240 import ImageUpload from "@/components/ImageUpload";
... ... @@ -261,6 +261,7 @@ export default {
261 261 },
262 262 // 基础设置
263 263 baseForm: {
  264 + id: null,
264 265 name: null,
265 266 sellPoint: null,
266 267 categoryIds: null,
... ... @@ -391,6 +392,14 @@ export default {
391 392 return;
392 393 }
393 394 let rates = this.ratesForm.rates;
  395 +
  396 + // 价格元转分
  397 + rates.forEach(r=>{
  398 + r.marketPrice = r.marketPrice*100;
  399 + r.price = r.price*100;
  400 + r.costPrice = r.costPrice*100;
  401 + })
  402 +
394 403 // 动态规格调整字段
395 404 if (this.ratesForm.spec == 2) {
396 405 rates.forEach(r => {
... ... @@ -403,9 +412,7 @@ export default {
403 412 obj = Array.of(s);
404 413 }
405 414 obj.forEach((v, i) => {
406   - console.log(this.dynamicSpec, r, s, v, i)
407 415 let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
408   - console.log(specValue)
409 416 let propertie = {};
410 417 propertie.propertyId = this.dynamicSpec[i].specId;
411 418 propertie.valueId = specValue.id;
... ... @@ -419,6 +426,7 @@ export default {
419 426 rates[0].status = this.baseForm.status;
420 427 }
421 428 let form = this.baseForm
  429 +
422 430 if(form.picUrls instanceof Array){
423 431 form.picUrls = form.picUrls.flatMap(m=>m.split(','))
424 432 }else if(form.picUrls.split(',') instanceof Array){
... ... @@ -426,18 +434,23 @@ export default {
426 434 }else{
427 435 form.picUrls = Array.of(form.picUrls)
428 436 }
429   -
  437 + console.log(rates)
430 438 form.skus = rates;
431 439 form.specType = this.ratesForm.spec;
432 440 form.categoryId = form.categoryIds[this.baseForm.categoryIds.length - 1];
433   - createSpu(form).then((response) => {
434   - console.log(response)
435   - this.$modal.msgSuccess("新增成功");
436   - this.$emit("closeDialog");
437   - }).catch((err) => {
438   - console.log(this.baseForm.picUrls)
439   - });
  441 +
  442 +
  443 + if(form.id == null){
  444 + createSpu(form).then((response) => {
  445 + this.$modal.msgSuccess("新增成功");
  446 + })
  447 + }else{
  448 + updateSpu(form).then((response) => {
  449 + this.$modal.msgSuccess("修改成功");
  450 + })
  451 + }
440 452 });
  453 + this.$emit("closeDialog");
441 454 },
442 455 /** 查询规格 */
443 456 getPropertyPageList() {
... ... @@ -458,8 +471,8 @@ export default {
458 471 },
459 472 updateType(id){
460 473 getSpu(id).then((response) =>{
461   - console.log(response)
462 474 let data = response.data;
  475 + this.baseForm.id=data.id;
463 476 this.baseForm.name=data.name;
464 477 this.baseForm.sellPoint=data.sellPoint;
465 478 this.baseForm.categoryIds=data.categoryIds;
... ... @@ -471,6 +484,11 @@ export default {
471 484 this.baseForm.showStock=data.showStock;
472 485 this.baseForm.brandId=data.brandId;
473 486 this.ratesForm.spec=data.specType;
  487 + data.skus.forEach(r=>{
  488 + r.marketPrice = this.divide(r.marketPrice, 100)
  489 + r.price = this.divide(r.price, 100)
  490 + r.costPrice = this.divide(r.costPrice, 100)
  491 + })
474 492 if(this.ratesForm.spec == 2){
475 493 data.productPropertyViews.forEach(p=>{
476 494 let obj = {};
... ... @@ -487,7 +505,6 @@ export default {
487 505 })
488 506 })
489 507 }
490   - console.log(data.skus);
491 508 this.ratesForm.rates=data.skus
492 509 })
493 510 }
... ...