|
@@ -86,14 +86,21 @@ export default {
|
|
|
spuDesc: "",
|
|
|
spuStatus: 0,
|
|
|
},
|
|
|
- headers: { Auth: "Bearer " + getToken(), "Content-type": "multipart/form-data" },
|
|
|
+ headers: {
|
|
|
+ Auth: "Bearer " + getToken(),
|
|
|
+ "Content-type": "multipart/form-data",
|
|
|
+ },
|
|
|
spuDetailList: [],
|
|
|
specialList: [],
|
|
|
index: 0,
|
|
|
index1: 0,
|
|
|
rules: {
|
|
|
- spuDesc: [{ required: true, message: "商品介绍不能为空", trigger: "blur" }],
|
|
|
- spuStatus: [{ required: true, message: "发布状态不能为空", trigger: "blur" }],
|
|
|
+ spuDesc: [
|
|
|
+ { required: true, message: "商品介绍不能为空", trigger: "blur" },
|
|
|
+ ],
|
|
|
+ spuStatus: [
|
|
|
+ { required: true, message: "发布状态不能为空", trigger: "blur" },
|
|
|
+ ],
|
|
|
spuDetailList: [
|
|
|
{ required: true, message: "商品详情图不能为空", trigger: "blur" },
|
|
|
],
|
|
@@ -102,30 +109,34 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
getFormInfo(record) {
|
|
|
- this.form.spuDesc = record.spuDesc;
|
|
|
+ // 初始化数组(明确空值处理)
|
|
|
this.spuDetailList = [];
|
|
|
this.specialList = [];
|
|
|
- if (record.spuDetailList) {
|
|
|
- record.spuDetailList.forEach((e) => {
|
|
|
- this.spuDetailList.push({
|
|
|
- url: e.fileUrl,
|
|
|
- id: e.id,
|
|
|
- sort: e.sort,
|
|
|
+ // 统一处理列表数据(提取公共逻辑)
|
|
|
+ const processList = (sourceList, targetList) => {
|
|
|
+ if (Array.isArray(sourceList)) {
|
|
|
+ // 增加数组类型校验
|
|
|
+ sourceList.forEach((item) => {
|
|
|
+ targetList.push({
|
|
|
+ url: item.fileUrl,
|
|
|
+ id: item.id,
|
|
|
+ sort: item.sort,
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 处理 spuDetailList
|
|
|
+ processList(record.spuDetailList, this.spuDetailList);
|
|
|
+ // 处理 specialList
|
|
|
+ processList(record.specialList, this.specialList);
|
|
|
|
|
|
- if (record.specialList) {
|
|
|
- record.specialList.forEach((e) => {
|
|
|
- this.specialList.push({
|
|
|
- url: e.fileUrl,
|
|
|
- id: e.id,
|
|
|
- sort: e.sort,
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- this.form.specialList = this.specialList;
|
|
|
- this.form.spuDetailList = this.spuDetailList;
|
|
|
+ // 批量更新表单数据(减少赋值次数)
|
|
|
+ this.form = {
|
|
|
+ ...this.form,
|
|
|
+ spuDesc: record.spuDesc,
|
|
|
+ spuDetailList: this.spuDetailList,
|
|
|
+ specialList: this.specialList,
|
|
|
+ };
|
|
|
},
|
|
|
|
|
|
formvalidate() {
|