潘超林 hai 1 mes
pai
achega
505317eb19

+ 8 - 9
src/views/member/module/basic-info.vue

@@ -253,15 +253,14 @@ export default {
       this.categoryName = categoryName;
 
       // 优化bannerList处理逻辑,确保pic始终在第一位
-      this.bannerList = pic
-        ? [
-            { fileUrl: pic, sort: 1 },
-            ...bannerList.filter((item) => item.fileUrl !== pic),
-          ]
-        : [...bannerList];
-
-      // 移除$forceUpdate,依赖Vue的响应式机制自动更新视图
-      // this.$forceUpdate();
+      if (pic) {
+        this.bannerList = pic
+          ? [
+              { fileUrl: pic, sort: 1 },
+              ...bannerList.filter((item) => item.fileUrl !== pic),
+            ]
+          : [...bannerList];
+      }
     },
 
     beforeAvatarUpload(file) {

+ 30 - 26
src/views/member/module/product-info.vue

@@ -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,27 @@ 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 transformList = (list = []) =>
+        Array.isArray(list)
+          ? list.map((item) => ({
+              url: item.fileUrl,
+              id: item.id,
+              sort: item.sort,
+            }))
+          : [];
 
-      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: transformList(record.spuDetailList),
+        specialList: transformList(record.specialList),
+      };
+
+      // 同步更新组件状态(如需独立维护)
+      this.spuDetailList = this.form.spuDetailList;
+      this.specialList = this.form.specialList;
     },
 
     formvalidate() {

+ 0 - 4
src/views/product/module/basic-info.vue

@@ -165,8 +165,6 @@
               v-model="bannerList"
               group="people"
               @change="draggableChange"
-              @start="start"
-              @end="end"
             >
               <div
                 class="item"
@@ -347,7 +345,6 @@ export default {
           sort: 1,
         });
       }
-
       // 触发强制更新(尽量避免使用)
       // this.$forceUpdate();
     },
@@ -412,7 +409,6 @@ export default {
       this.form.bannerList = [];
       this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
       this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
-
       if (this.bannerList.length > 0) {
         console.log("bannerList", this.bannerList);
         for (let index = 0; index < this.bannerList.length; index++) {

+ 25 - 25
src/views/product/module/product-info.vue

@@ -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,36 +109,29 @@ 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 transformFileList = (list) =>
+        Array.isArray(list)
+          ? list.map((item) => ({
+              url: item.fileUrl,
+              id: item.id,
+              sort: item.sort,
+            }))
+          : [];
 
-      if (record.specialList) {
-        record.specialList.forEach((e) => {
-          this.specialList.push({
-            url: e.fileUrl,
-            id: e.id,
-            sort: e.sort,
-          });
-        });
-      }
+      // 转换并赋值商品详情和特殊列表
+      this.spuDetailList = transformFileList(record.spuDetailList);
+      this.specialList = transformFileList(record.specialList);
+
+      // 更新表单数据
       this.form.specialList = this.specialList;
       this.form.spuDetailList = this.spuDetailList;
     },
 
     formvalidate() {
       let that = this;
-      console.log(this.form);
-
       return new Promise((resolve) => {
         that.$refs.queryForm.validate((valid, row) => {
           if (valid) {

+ 0 - 1
src/views/product/updateProduct.vue

@@ -515,7 +515,6 @@ export default {
     },
     updateValue(val) {
       this.form = { ...this.form, ...val };
-
       if (this.form.saleType == 2) {
         this.$refs.salesRefs.setShowCom(true);
       } else if (this.form.scope == 0) {

+ 7 - 9
src/views/transmission/module/basic-info.vue

@@ -86,8 +86,6 @@
               v-model="bannerList"
               group="people"
               @change="draggableChange"
-              @start="start"
-              @end="end"
             >
               <div
                 class="item"
@@ -249,13 +247,13 @@ export default {
       // 更新分类名称
       this.categoryName = categoryName;
 
-      // 处理轮播图列表(pic优先显示在第一位)
-      this.bannerList = pic
-        ? [{ fileUrl: pic, sort: 1 }, ...bannerList]
-        : [...bannerList];
-
-      // 避免使用$forceUpdate,确保数据响应式更新
-      // this.$forceUpdate();
+      if (pic) {
+        // 确保 bannerList 为数组,若为 null/undefined 则转为空数组
+        this.bannerList = [{ fileUrl: pic, sort: 1 }, ...(bannerList || [])];
+      } else {
+        // 直接使用 bannerList 或空数组
+        this.bannerList = [...(bannerList || [])];
+      }
     },
     beforeAvatarUpload(file) {
       const isJPG = file.type === "image/jpeg" || "image/png" || "image/jpg";

+ 34 - 23
src/views/transmission/module/product-info.vue

@@ -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() {

+ 0 - 6
src/views/transmission/module/sales-info.vue

@@ -355,7 +355,6 @@ export default {
         ],
       },
       shopInfo: {},
-      saleType: undefined,
       sj: true,
       showCom: true,
       skuIds: [],
@@ -384,7 +383,6 @@ export default {
   methods: {
     cascaderChange(val) {
       const dom = document.getElementsByClassName("el-radio is-checked");
-      //这里我把dom打出来看了 最后一个选项才是我选中的节点 即[length-1] 有的博主写的是 第一个元素 即[0] 大家自行尝试
       let radioDom = dom[dom.length - 1];
       const brother = radioDom.nextElementSibling;
       brother.click();
@@ -392,10 +390,6 @@ export default {
       this.form.merchantClassifyName = nodes[0].label;
       this.form.merchantClassifyIds = val;
       this.form.merchantClassifyId = JSON.stringify(val);
-
-      console.log("this.form.merchantClassifyId", this.form.merchantClassifyId);
-
-      // this.form.merchantClassifyId = `["${this.form.merchantClassifyId.join('", "')}"]`;
       this.passValue();
     },
 

+ 13 - 11
src/views/transmission/updateProduct.vue

@@ -3,16 +3,16 @@
     <div style="width: 100%; height: 85vh; overflow: auto">
       <el-row style="padding-top: 20px">
         <el-col :span="24">
-          <el-descriptions title="基本信息" column="1"> </el-descriptions>
+          <el-descriptions title="基本信息" :column="1"> </el-descriptions>
           <basicInfo ref="basicRefs" @updateValue="updateValue"></basicInfo>
-          <el-descriptions title="销售信息" column="1"> </el-descriptions>
+          <el-descriptions title="销售信息" :column="1"> </el-descriptions>
           <salesInfo
             ref="salesRefs"
             @updateValue="updateValue"
             @skuRemove="skuRemove"
             :saleModels="form.saleModel"
           ></salesInfo>
-          <el-descriptions title="商品详情" column="1"> </el-descriptions>
+          <el-descriptions title="商品详情" :column="1"> </el-descriptions>
           <productInfo
             ref="productRefs"
             @updateValue="updateValue"
@@ -68,8 +68,8 @@
                   <span>¥</span>
                   <span
                     class="price"
-                    :key="item"
-                    v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
+                    :key="index"
+                    v-for="(item,index) in form.skuList ? form.skuList.slice(0, 1) : []"
                     >{{
                       item.skuPriceList ? item.skuPriceList[0].price : 0
                     }}元</span
@@ -271,13 +271,14 @@ export default {
   },
 
   created() {
-    window.addEventListener("beforeunload", function (e) {
-      this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
+    window.addEventListener("beforeunload", () => {
+      // 使用箭头函数保留 this 指向
+      this.$store.dispatch("tagsView/delView", this.$route);
       this.$router.replace({ path: "/product/product/index" });
     });
   },
   mounted() {
-    this.getInfo();
+
     if (
       (this.$route.query.params != "[object Object]" &&
         this.$route.query.params) ||
@@ -379,6 +380,7 @@ export default {
           }
         });
       }
+      this.getInfo();
     }
   },
   methods: {
@@ -498,9 +500,9 @@ export default {
             (res) => {}
           );
         }
-        if (this.form.bannerList?.length > 0) {
-          this.form.bannerList.shift();
-        }
+        // if (this.form.bannerList?.length > 0) {
+        //   this.form.bannerList.shift();
+        // }
         if (this.form.skuList.length < 1 || this.form.skuList === "") {
           this.$message.error(`规格不能为空`);
           return;