潘超林 1 月之前
父節點
當前提交
af879e0e1f

+ 1 - 1
.env.development

@@ -5,7 +5,7 @@ VUE_APP_TITLE = 农商网商家管理系统
 ENV = 'development'
 
 # 农商网商家管理系统/开发环境
-VUE_APP_BASE_API = '/shop'
+VUE_APP_BASE_API = '/dev-api'
 
 VUE_APP_NSY_UPLOAD_API="https://app.sxdirectpurchase.com"
 

+ 11 - 10
src/components/Map/map.vue

@@ -15,7 +15,11 @@
         style="width: 90%"
       >
       </el-input>
-      <el-button type="primary" icon="el-icon-search" @click="autoInput"></el-button>
+      <el-button
+        type="primary"
+        icon="el-icon-search"
+        @click="autoInput"
+      ></el-button>
     </div>
 
     <!-- <el-select v-model="value" filterable placeholder="请选择" :filter-method="autoInput">
@@ -100,7 +104,8 @@ export default {
         });
         placeSearch.search(keywords);
         placeSearch.on("markerClick", function (e) {
-          e.data.address =
+          let obj = { ...e.data };
+          obj.address =
             e.data.pname +
             "" +
             e.data.cityname +
@@ -110,12 +115,9 @@ export default {
             e.data.address +
             "" +
             e.data.name;
-
-          console.log("s", e.data);
-          e.data.cityCode = e.data.adcode.substring(0, 4) + "00";
-          that.addressParams = e.data;
-          console.log("z", that.addressParams);
-          that.address = e.data.address;
+          e.data.cityCode = obj.adcode.substring(0, 4) + "00";
+          that.addressParams = obj;
+          that.address = obj.address;
         });
       });
     },
@@ -183,8 +185,7 @@ export default {
       }
       if (!this.marker) {
         this.marker = new AMap.Marker({
-          icon:
-            "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
+          icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
           position: [e.lnglat.lng, e.lnglat.lat],
           imageSize: new AMap.Size(12, 12),
           offset: new AMap.Pixel(-13, -30),

+ 1 - 1
src/views/manage/shopInfo.vue

@@ -1,6 +1,6 @@
 <template>
   <div style="padding: 20px">
-    <el-tabs v-model="activeName" @tab-click="handleClick">
+    <el-tabs v-model="activeName">
       <el-tab-pane label="基本信息" :name="1">
         <div style="padding: 20px">
           <el-descriptions title="基本信息" :column="1">

+ 1 - 0
src/views/manage/shopInfoCommon/shopDialog.vue

@@ -13,6 +13,7 @@
           size="small"
           :inline="true"
           label-width="68px"
+          @submit.prevent
         >
           <el-form-item label="" prop="key">
             <el-input

+ 4 - 0
src/views/member/createProduct.vue

@@ -352,6 +352,10 @@ export default {
         this.$message.error(`商品规格不能为空`);
         return;
       }
+      if (!this.form.shippingAddrBean.provinceCode) {
+        this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
+        return;
+      }
       if (this.form.categoryId?.length > 0) {
         this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
       }

+ 83 - 36
src/views/member/module/basic-info.vue

@@ -22,6 +22,7 @@
         <el-form-item prop="categoryId">
           <span slot="label">商品分类</span>
           <el-cascader
+            :filterable="true"
             v-model="form.categoryId"
             ref="formCascader"
             :placeholder="categoryName ? categoryName : '请选择分类'"
@@ -96,7 +97,11 @@
               @start="start"
               @end="end"
             >
-              <div class="item" v-for="(item, index) in this.bannerList" :key="index">
+              <div
+                class="item"
+                v-for="(item, index) in this.bannerList"
+                :key="index"
+              >
                 <div class="fmt" v-if="index == 0">封面图</div>
                 <div class="gb" @click="removeImg(index)">X</div>
                 <img
@@ -159,7 +164,10 @@ export default {
         presaleEndTime: "",
       },
       bannerList: [],
-      headers: { Auth: "Bearer " + getToken(), "Content-type": "multipart/form-data" },
+      headers: {
+        Auth: "Bearer " + getToken(),
+        "Content-type": "multipart/form-data",
+      },
       categoryprops: {
         checkStrictly: true,
         lazy: true,
@@ -168,18 +176,34 @@ export default {
         value: "value",
       },
       rules: {
-        saleType: [{ required: true, message: "销售方式不能为空", trigger: "blur" }],
-        saleModel: [{ required: true, message: "销售模式不能为空", trigger: "blur" }],
-        categoryId: [{ required: true, message: "分类不能为空", trigger: "blur" }],
-        title: [{ required: true, message: "商品名称不能为空", trigger: "blur" }],
-        giftDesc: [{ required: true, message: "礼包描述不能为空", trigger: "blur" }],
+        saleType: [
+          { required: true, message: "销售方式不能为空", trigger: "blur" },
+        ],
+        saleModel: [
+          { required: true, message: "销售模式不能为空", trigger: "blur" },
+        ],
+        categoryId: [
+          { required: true, message: "分类不能为空", trigger: "blur" },
+        ],
+        title: [
+          { required: true, message: "商品名称不能为空", trigger: "blur" },
+        ],
+        giftDesc: [
+          { required: true, message: "礼包描述不能为空", trigger: "blur" },
+        ],
         bannerList: [
-          { required: true, message: "商品图最低上传两张图片", trigger: "blur" },
+          {
+            required: true,
+            message: "商品图最低上传两张图片",
+            trigger: "blur",
+          },
         ],
         carpoolSuccessTime: [
           { required: true, message: "拼车成功时间不能为空", trigger: "blur" },
         ],
-        datePicker: [{ required: true, message: "预售时间不能为空", trigger: "blur" }],
+        datePicker: [
+          { required: true, message: "预售时间不能为空", trigger: "blur" },
+        ],
       },
       index: 0,
       shopInfo: {},
@@ -190,32 +214,54 @@ export default {
   created() {},
 
   methods: {
-    getFormInfo(record) {
-      this.form.datePicker = [];
-      this.form.categoryId = record.categoryId;
-      this.form.categoryIds = record.categoryIds;
-      this.form.carpoolSuccessTime = record.carpoolSuccessTime;
-      this.form.scope = record.scope;
-      this.form.saleType = record.saleType;
-      this.form.saleModel = record.saleModel;
-      this.form.title = record.title;
-      this.form.giftDesc = record.giftDesc;
-      this.form.vid = record.vid;
-      this.form.bannerList = record.bannerList;
-      this.form.pic = record.pic;
-      this.form.categoryName = record.categoryName;
-      this.categoryName = record.categoryName;
-      this.bannerList = [];
-      if (this.form.bannerList?.length > 0) {
-        this.bannerList = this.form.bannerList;
-      }
-      if (this.form.pic) {
-        this.bannerList.unshift({
-          fileUrl: record.pic,
-          sort: 1,
-        });
-      }
-      this.$forceUpdate();
+    getFormInfo(record = {}) {
+      // 解构赋值并设置默认值,避免多次访问record对象
+      const {
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList = [],
+        pic,
+        categoryName,
+      } = record;
+
+      // 使用对象展开语法批量更新表单数据,保持响应式
+      this.form = {
+        ...this.form,
+        datePicker: [],
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList,
+        pic,
+        categoryName,
+      };
+
+      // 同步更新局部变量
+      this.categoryName = categoryName;
+
+      // 优化bannerList处理逻辑,确保pic始终在第一位
+      this.bannerList = pic
+        ? [
+            { fileUrl: pic, sort: 1 },
+            ...bannerList.filter((item) => item.fileUrl !== pic),
+          ]
+        : [...bannerList];
+
+      // 移除$forceUpdate,依赖Vue的响应式机制自动更新视图
+      // this.$forceUpdate();
     },
 
     beforeAvatarUpload(file) {
@@ -269,7 +315,8 @@ export default {
         console.log("bannerList", this.bannerList);
         for (let index = 0; index < this.bannerList.length; index++) {
           this.form.bannerList.push({
-            fileUrl: this.bannerList[index].url || this.bannerList[index].fileUrl,
+            fileUrl:
+              this.bannerList[index].url || this.bannerList[index].fileUrl,
             sort: this.bannerList[index].name,
           });
         }

+ 40 - 12
src/views/member/updateProduct.vue

@@ -13,7 +13,10 @@
             :saleModels="form.saleModel"
           ></salesInfo>
           <el-descriptions title="商品详情" column="1"> </el-descriptions>
-          <productInfo ref="productRefs" @updateValue="updateValue"></productInfo>
+          <productInfo
+            ref="productRefs"
+            @updateValue="updateValue"
+          ></productInfo>
 
           <div class="dialog-footer" style="text-align: center">
             <el-button @click="submitCancel">取 消</el-button>
@@ -67,7 +70,9 @@
                     class="price"
                     :key="item"
                     v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
-                    >{{ item.skuPriceList ? item.skuPriceList[0].price : 0 }}元</span
+                    >{{
+                      item.skuPriceList ? item.skuPriceList[0].price : 0
+                    }}元</span
                   >
 
                   <span>/{{ form.unit }}</span>
@@ -80,7 +85,9 @@
               <div v-for="(item, index) in form.skuList" :key="index">
                 <div class="price_info">
                   <span
-                    >{{ item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : "" }}
+                    >{{
+                      item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : ""
+                    }}
                     {{
                       item.skuSpecsList[0].specsValue
                         ? item.skuSpecsList[0].specsValue
@@ -117,7 +124,8 @@
                     }}/{{ form.unit }}起购</span
                   >
                   <span style="font-size: 14px"
-                    >库存:{{ item.stock + item.predictStocks }}{{ form.unit }}</span
+                    >库存:{{ item.stock + item.predictStocks
+                    }}{{ form.unit }}</span
                   >
                 </div>
               </div>
@@ -135,7 +143,11 @@
                   <el-col :span="24">
                     <el-form-item label="发货地" prop="spuName">
                       <div style="width: 185px">
-                        {{ form.shippingAddrBean ? form.shippingAddrBean.addr : "" }}
+                        {{
+                          form.shippingAddrBean
+                            ? form.shippingAddrBean.addr
+                            : ""
+                        }}
                         {{
                           form.shippingAddrBean
                             ? form.shippingAddrBean.addrDetail
@@ -267,11 +279,15 @@ export default {
   mounted() {
     this.getInfo();
     if (
-      (this.$route.query.params != "[object Object]" && this.$route.query.params) ||
+      (this.$route.query.params != "[object Object]" &&
+        this.$route.query.params) ||
       JSON.parse(localStorage.getItem("productInfo"))
     ) {
       let info = {};
-      if (this.$route.query.params != "[object Object]" && this.$route.query.params) {
+      if (
+        this.$route.query.params != "[object Object]" &&
+        this.$route.query.params
+      ) {
         info = this.$route.query.params;
       } else {
         info = JSON.parse(localStorage.getItem("productInfo"));
@@ -406,12 +422,15 @@ export default {
     submitFormDraft() {
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
       // if (this.form.bannerList?.length > 0) {
       //   this.form.bannerList.shift();
@@ -450,23 +469,32 @@ export default {
 
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
 
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
 
       if (this.form.id) {
         if (this.skulist?.length > 0) {
-          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then((res) => {});
+          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then(
+            (res) => {}
+          );
         }
         if (this.form.skuList.length < 1 || this.form.skuList === "") {
           this.$message.error(`规格不能为空`);
           return;
         }
+        if (!this.form.shippingAddrBean.provinceCode) {
+          this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
+          return;
+        }
         updateGoods(this.form).then((res) => {
           if (res.code == 200) {
             this.btnLading = false;

+ 38 - 11
src/views/product/createProduct.vue

@@ -13,7 +13,10 @@
             :saleModels="form.saleModel"
           ></salesInfo>
           <el-descriptions title="商品详情" column="1"> </el-descriptions>
-          <productInfo @updateValue="updateValue" ref="productRefs"></productInfo>
+          <productInfo
+            @updateValue="updateValue"
+            ref="productRefs"
+          ></productInfo>
 
           <div class="dialog-footer" style="text-align: center">
             <el-button @click="submitCancel">取 消</el-button>
@@ -21,7 +24,9 @@
               >发 布</el-button
             >
 
-            <el-button type="primary" @click="submitFormDraft">存入草稿箱</el-button>
+            <el-button type="primary" @click="submitFormDraft"
+              >存入草稿箱</el-button
+            >
           </div>
         </el-col>
         <phoneView style="position: absolute; bottom: 50px; right: 50px">
@@ -63,7 +68,9 @@
                     class="price"
                     :key="item"
                     v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
-                    >{{ item.skuPriceList ? item.skuPriceList[0].price : 0 }}元</span
+                    >{{
+                      item.skuPriceList ? item.skuPriceList[0].price : 0
+                    }}元</span
                   >
 
                   <span>/{{ form.unit }}</span>
@@ -76,7 +83,9 @@
               <div v-for="(item, index) in form.skuList" :key="index">
                 <div class="price_info">
                   <span
-                    >{{ item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : "" }}
+                    >{{
+                      item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : ""
+                    }}
                     {{
                       item.skuSpecsList[0].specsValue
                         ? item.skuSpecsList[0].specsValue
@@ -113,7 +122,8 @@
                     }}/{{ form.unit }}起购</span
                   >
                   <span style="font-size: 14px"
-                    >库存:{{ item.stock + item.predictStocks }}{{ form.unit }}</span
+                    >库存:{{ item.stock + item.predictStocks
+                    }}{{ form.unit }}</span
                   >
                 </div>
               </div>
@@ -131,7 +141,11 @@
                   <el-col :span="24">
                     <el-form-item label="发货地" prop="spuName">
                       <div style="width: 185px">
-                        {{ form.shippingAddrBean ? form.shippingAddrBean.addr : "" }}
+                        {{
+                          form.shippingAddrBean
+                            ? form.shippingAddrBean.addr
+                            : ""
+                        }}
                         {{
                           form.shippingAddrBean
                             ? form.shippingAddrBean.addrDetail
@@ -229,7 +243,10 @@
 <script>
 import { getStoreInfo } from "@/api/common/index";
 import { publishGoods } from "@/api/publish/index";
-import { saveGoodsDraft, queryUserRelevanceTemplate } from "@/api/manage/product";
+import {
+  saveGoodsDraft,
+  queryUserRelevanceTemplate,
+} from "@/api/manage/product";
 import basicInfo from "./module/basic-info.vue";
 import productInfo from "./module/product-info.vue";
 import salesInfo from "./module/sales-info.vue";
@@ -266,14 +283,17 @@ export default {
     },
     submitFormDraft() {
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
       if (this.form.categoryIds.length < 1) {
         this.form.categoryIds = "";
       }
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
@@ -352,12 +372,19 @@ export default {
         this.$message.error(`商品规格不能为空`);
         return;
       }
+      if (!this.form.shippingAddrBean.provinceCode) {
+        this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
+        return;
+      }
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }

+ 51 - 39
src/views/product/module/basic-info.vue

@@ -79,6 +79,7 @@
         <el-form-item prop="categoryId">
           <span slot="label">商品分类</span>
           <el-cascader
+            :filterable="true"
             v-model="form.categoryId"
             ref="formCascader"
             :placeholder="categoryName ? categoryName : '请选择分类'"
@@ -180,8 +181,6 @@
                 />
               </div>
             </draggable>
-            <!-- <div class="fmt" v-if="index == 0">封面图</div>
-                <img :src="item.url" style="width: 70px; height: 75px" /> -->
             <el-upload
               list-type="picture-card"
               :file-list="bannerList"
@@ -288,54 +287,69 @@ export default {
 
   methods: {
     getFormInfo(record, type) {
-      if (type != "cg") {
-        this.actionType = "edit";
-      } else {
-        this.actionType = "";
-      }
+      // 重置表单基础数据
+      this.actionType = type === "cg" ? "" : "edit";
       this.form.datePicker = [];
-      this.form.categoryId = record.categoryId;
-      this.form.categoryIds = record.categoryIds;
-      this.form.carpoolSuccessTime = record.carpoolSuccessTime;
-      this.form.scope = record.scope;
-      this.form.saleType = record.saleType;
-      this.form.saleModel = record.saleModel;
-      this.form.title = record.title;
-      this.form.giftDesc = record.giftDesc;
-      this.form.vid = record.vid;
-      this.form.bannerList = record.bannerList;
-      this.form.pic = record.pic;
-      this.form.categoryName = record.categoryName;
-      this.categoryName = record.categoryName;
-      if (record.presaleEndTime && record.presaleStartTime) {
-        this.form.presaleStartTime = moment(record.presaleStartTime).format(
-          "yyyy-MM-DD HH:mm:ss"
-        );
-        this.form.presaleEndTime = moment(record.presaleEndTime).format(
-          "yyyy-MM-DD HH:mm:ss"
-        );
+      // 解构赋值与默认值处理
+      const {
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList = [],
+        pic,
+        categoryName,
+        presaleStartTime,
+        presaleEndTime,
+      } = record || {};
+      // 更新表单数据
+      this.form = {
+        ...this.form,
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList,
+        pic,
+        categoryName,
+        presaleStartTime: presaleStartTime
+          ? moment(presaleStartTime).format("yyyy-MM-DD HH:mm:ss")
+          : "",
+        presaleEndTime: presaleEndTime
+          ? moment(presaleEndTime).format("yyyy-MM-DD HH:mm:ss")
+          : "",
+      };
+
+      // 更新日期选择器
+      if (presaleStartTime && presaleEndTime) {
         this.$nextTick(() => {
           this.$set(this.form, "datePicker", [
             this.form.presaleStartTime,
             this.form.presaleEndTime,
           ]);
         });
-      } else {
-        this.form.presaleStartTime = "";
-        this.form.presaleEndTime = "";
-      }
-      this.bannerList = [];
-      if (this.form.bannerList?.length > 0) {
-        this.bannerList = this.form.bannerList;
       }
-      if (this.form.pic) {
+      // 更新轮播图列表(优化添加逻辑)
+      this.bannerList = [...bannerList];
+      if (pic) {
         this.bannerList.unshift({
-          fileUrl: record.pic,
+          fileUrl: pic,
           sort: 1,
         });
       }
 
-      this.$forceUpdate();
+      // 触发强制更新(尽量避免使用)
+      // this.$forceUpdate();
     },
 
     beforeAvatarUpload(file) {
@@ -395,8 +409,6 @@ export default {
     },
 
     passValue() {
-      console.log(this.form);
-
       this.form.bannerList = [];
       this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
       this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();

+ 2 - 2
src/views/product/module/sales-info.vue

@@ -511,6 +511,7 @@
         <el-form-item prop="merchantClassifyIds">
           <span slot="label">店铺内所属分类</span>
           <el-cascader
+            :filterable="true"
             v-model="form.merchantClassifyIds"
             ref="formCascader"
             :placeholder="
@@ -732,8 +733,7 @@ export default {
       this.addr = record.shippingAddr;
       this.form.expressType = record.expressType;
       this.form.shareRate = record.shareRate;
-
-      this.form.merchantClassifyIds = record.merchantClassifyIds;
+      this.form.merchantClassifyIds = record.merchantClassifyId;
       this.form.merchantClassifyId = record.merchantClassifyId;
       this.form.shippingAddrBean = {
         addr: record.shippingAddr,

+ 40 - 19
src/views/product/updateProduct.vue

@@ -13,7 +13,10 @@
             :saleModels="form.saleModel"
           ></salesInfo>
           <el-descriptions title="商品详情" column="1"> </el-descriptions>
-          <productInfo ref="productRefs" @updateValue="updateValue"></productInfo>
+          <productInfo
+            ref="productRefs"
+            @updateValue="updateValue"
+          ></productInfo>
 
           <div class="dialog-footer" style="text-align: center">
             <el-button @click="submitCancel">取 消</el-button>
@@ -67,7 +70,9 @@
                     class="price"
                     :key="item"
                     v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
-                    >{{ item.skuPriceList ? item.skuPriceList[0].price : 0 }}元</span
+                    >{{
+                      item.skuPriceList ? item.skuPriceList[0].price : 0
+                    }}元</span
                   >
 
                   <span>/{{ form.unit }}</span>
@@ -80,7 +85,9 @@
               <div v-for="(item, index) in form.skuList" :key="index">
                 <div class="price_info">
                   <span
-                    >{{ item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : "" }}
+                    >{{
+                      item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : ""
+                    }}
                     {{
                       item.skuSpecsList[0].specsValue
                         ? item.skuSpecsList[0].specsValue
@@ -117,7 +124,8 @@
                     }}/{{ form.unit }}起购</span
                   >
                   <span style="font-size: 14px"
-                    >库存:{{ item.stock + item.predictStocks }}{{ form.unit }}</span
+                    >库存:{{ item.stock + item.predictStocks
+                    }}{{ form.unit }}</span
                   >
                 </div>
               </div>
@@ -135,7 +143,11 @@
                   <el-col :span="24">
                     <el-form-item label="发货地" prop="spuName">
                       <div style="width: 185px">
-                        {{ form.shippingAddrBean ? form.shippingAddrBean.addr : "" }}
+                        {{
+                          form.shippingAddrBean
+                            ? form.shippingAddrBean.addr
+                            : ""
+                        }}
                         {{
                           form.shippingAddrBean
                             ? form.shippingAddrBean.addrDetail
@@ -267,11 +279,15 @@ export default {
   mounted() {
     this.getInfo();
     if (
-      (this.$route.query.params != "[object Object]" && this.$route.query.params) ||
+      (this.$route.query.params != "[object Object]" &&
+        this.$route.query.params) ||
       JSON.parse(localStorage.getItem("productInfo"))
     ) {
       let info = {};
-      if (this.$route.query.params != "[object Object]" && this.$route.query.params) {
+      if (
+        this.$route.query.params != "[object Object]" &&
+        this.$route.query.params
+      ) {
         info = this.$route.query.params;
       } else {
         info = JSON.parse(localStorage.getItem("productInfo"));
@@ -367,7 +383,6 @@ export default {
   },
   methods: {
     skuRemove(list) {
-      console.log("list", list);
       this.skulist = list;
     },
     getInfo() {
@@ -406,12 +421,15 @@ export default {
     submitFormDraft() {
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
       // if (this.form.bannerList?.length > 0) {
       //   this.form.bannerList.shift();
@@ -443,25 +461,30 @@ export default {
         this.$message.error(`商品规格不能为空`);
         return;
       }
-      // if (this.form.bannerList?.length > 0) {
-      //   this.form.bannerList.shift();
-      // }
+      if (!this.form.shippingAddrBean.provinceCode) {
+        this.$message.error(`请选择发货地址的省市区!`);
+        return;
+      }
       this.btnLading = true;
-
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
 
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
 
       if (this.form.id) {
         if (this.skulist?.length > 0) {
-          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then((res) => {});
+          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then(
+            (res) => {}
+          );
         }
         if (this.form.skuList.length < 1 || this.form.skuList === "") {
           this.$message.error(`规格不能为空`);
@@ -519,8 +542,6 @@ export default {
         });
       }
       this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
-
-      console.log("1231231", this.form);
     },
     unique(arr) {
       const res = new Map();

+ 4 - 0
src/views/transmission/createProduct.vue

@@ -369,6 +369,10 @@ export default {
         this.$message.error(`商品规格不能为空`);
         return;
       }
+      // if (!this.form.shippingAddrBean.provinceCode) {
+      //   this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
+      //   return;
+      // }
       if (this.form.categoryId?.length > 0) {
         this.form.categoryId =
           this.form.categoryId[this.form.categoryId.length - 1];

+ 82 - 42
src/views/transmission/module/basic-info.vue

@@ -28,6 +28,7 @@
         <el-form-item prop="categoryId">
           <span slot="label">商品分类</span>
           <el-cascader
+            :filterable="true"
             class="fl"
             v-model="form.categoryId"
             ref="formCascader"
@@ -88,7 +89,11 @@
               @start="start"
               @end="end"
             >
-              <div class="item" v-for="(item, index) in this.bannerList" :key="index">
+              <div
+                class="item"
+                v-for="(item, index) in this.bannerList"
+                :key="index"
+              >
                 <div class="fmt" v-if="index == 0">封面图</div>
                 <div class="gb" @click="removeImg(index)">X</div>
                 <img
@@ -150,7 +155,10 @@ export default {
         presaleEndTime: "",
       },
       bannerList: [],
-      headers: { Auth: "Bearer " + getToken(), "Content-type": "multipart/form-data" },
+      headers: {
+        Auth: "Bearer " + getToken(),
+        "Content-type": "multipart/form-data",
+      },
       categoryprops: {
         checkStrictly: true,
         lazy: true,
@@ -159,18 +167,34 @@ export default {
         value: "value",
       },
       rules: {
-        saleType: [{ required: true, message: "销售方式不能为空", trigger: "blur" }],
-        saleModel: [{ required: true, message: "销售方式不能为空", trigger: "blur" }],
-        categoryId: [{ required: true, message: "分类不能为空", trigger: "blur" }],
-        title: [{ required: true, message: "商品名称不能为空", trigger: "blur" }],
-        giftDesc: [{ required: true, message: "礼包描述不能为空", trigger: "blur" }],
+        saleType: [
+          { required: true, message: "销售方式不能为空", trigger: "blur" },
+        ],
+        saleModel: [
+          { required: true, message: "销售方式不能为空", trigger: "blur" },
+        ],
+        categoryId: [
+          { required: true, message: "分类不能为空", trigger: "blur" },
+        ],
+        title: [
+          { required: true, message: "商品名称不能为空", trigger: "blur" },
+        ],
+        giftDesc: [
+          { required: true, message: "礼包描述不能为空", trigger: "blur" },
+        ],
         bannerList: [
-          { required: true, message: "商品图最低上传两张图片", trigger: "blur" },
+          {
+            required: true,
+            message: "商品图最低上传两张图片",
+            trigger: "blur",
+          },
         ],
         carpoolSuccessTime: [
           { required: true, message: "拼车成功时间不能为空", trigger: "blur" },
         ],
-        datePicker: [{ required: true, message: "预售时间不能为空", trigger: "blur" }],
+        datePicker: [
+          { required: true, message: "预售时间不能为空", trigger: "blur" },
+        ],
       },
       index: 0,
       shopInfo: {},
@@ -184,40 +208,55 @@ export default {
   },
 
   methods: {
-    getFormInfo(record, type) {
-      if (type != "cg") {
-        this.actionType = "edit";
-      } else {
-        this.actionType = "";
-      }
+    getFormInfo(record = {}, type) {
+      // 设置操作类型
+      this.actionType = type === "cg" ? "" : "edit";
 
-      this.form.datePicker = [];
-      this.form.categoryId = record.categoryId;
-      this.form.categoryIds = record.categoryIds;
-      this.form.carpoolSuccessTime = record.carpoolSuccessTime;
-      this.form.scope = record.scope;
-      this.form.saleType = record.saleType;
-      this.form.saleModel = record.saleModel;
-      this.form.title = record.title;
-      this.form.giftDesc = record.giftDesc;
-      this.form.vid = record.vid;
-      this.form.bannerList = record.bannerList;
-      this.form.pic = record.pic;
-      this.form.categoryName = record.categoryName;
-      this.categoryName = record.categoryName;
-      this.bannerList = [];
-      if (this.form.bannerList?.length > 0) {
-        this.bannerList = this.form.bannerList;
-      }
-      if (this.form.pic) {
-        this.bannerList.unshift({
-          fileUrl: record.pic,
-          sort: 1,
-        });
-      }
-      this.$forceUpdate();
-    },
+      // 解构赋值并设置默认值
+      const {
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList = [],
+        pic,
+        categoryName,
+      } = record;
 
+      // 更新表单数据
+      this.form = {
+        ...this.form,
+        datePicker: [],
+        categoryId,
+        categoryIds,
+        carpoolSuccessTime,
+        scope,
+        saleType,
+        saleModel,
+        title,
+        giftDesc,
+        vid,
+        bannerList,
+        pic,
+        categoryName,
+      };
+
+      // 更新分类名称
+      this.categoryName = categoryName;
+
+      // 处理轮播图列表(pic优先显示在第一位)
+      this.bannerList = pic
+        ? [{ fileUrl: pic, sort: 1 }, ...bannerList]
+        : [...bannerList];
+
+      // 避免使用$forceUpdate,确保数据响应式更新
+      // this.$forceUpdate();
+    },
     beforeAvatarUpload(file) {
       const isJPG = file.type === "image/jpeg" || "image/png" || "image/jpg";
       const isLt2M = file.size / 1024 / 1024 < 2;
@@ -275,7 +314,8 @@ export default {
         console.log("bannerList", this.bannerList);
         for (let index = 0; index < this.bannerList.length; index++) {
           this.form.bannerList.push({
-            fileUrl: this.bannerList[index].url || this.bannerList[index].fileUrl,
+            fileUrl:
+              this.bannerList[index].url || this.bannerList[index].fileUrl,
             sort: this.bannerList[index].name,
           });
         }

+ 2 - 1
src/views/transmission/module/sales-info.vue

@@ -266,6 +266,7 @@
         <el-form-item prop="merchantClassifyIds">
           <span slot="label">店铺内所属分类</span>
           <el-cascader
+            :filterable="true"
             v-model="form.merchantClassifyIds"
             ref="formCascader"
             :placeholder="
@@ -392,7 +393,7 @@ export default {
       this.form.merchantClassifyIds = val;
       this.form.merchantClassifyId = JSON.stringify(val);
 
-      console.log('this.form.merchantClassifyId',this.form.merchantClassifyId);
+      console.log("this.form.merchantClassifyId", this.form.merchantClassifyId);
 
       // this.form.merchantClassifyId = `["${this.form.merchantClassifyId.join('", "')}"]`;
       this.passValue();

+ 43 - 12
src/views/transmission/updateProduct.vue

@@ -13,7 +13,10 @@
             :saleModels="form.saleModel"
           ></salesInfo>
           <el-descriptions title="商品详情" column="1"> </el-descriptions>
-          <productInfo ref="productRefs" @updateValue="updateValue"></productInfo>
+          <productInfo
+            ref="productRefs"
+            @updateValue="updateValue"
+          ></productInfo>
 
           <div class="dialog-footer" style="text-align: center">
             <el-button @click="submitCancel">取 消</el-button>
@@ -67,7 +70,9 @@
                     class="price"
                     :key="item"
                     v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
-                    >{{ item.skuPriceList ? item.skuPriceList[0].price : 0 }}元</span
+                    >{{
+                      item.skuPriceList ? item.skuPriceList[0].price : 0
+                    }}元</span
                   >
 
                   <span>/{{ form.unit }}</span>
@@ -80,7 +85,9 @@
               <div v-for="(item, index) in form.skuList" :key="index">
                 <div class="price_info">
                   <span
-                    >{{ item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : "" }}
+                    >{{
+                      item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : ""
+                    }}
                     {{
                       item.skuSpecsList[0].specsValue
                         ? item.skuSpecsList[0].specsValue
@@ -117,7 +124,8 @@
                     }}/{{ form.unit }}起购</span
                   >
                   <span style="font-size: 14px"
-                    >库存:{{ item.stock + item.predictStocks }}{{ form.unit }}</span
+                    >库存:{{ item.stock + item.predictStocks
+                    }}{{ form.unit }}</span
                   >
                 </div>
               </div>
@@ -135,7 +143,11 @@
                   <el-col :span="24">
                     <el-form-item label="发货地" prop="spuName">
                       <div style="width: 185px">
-                        {{ form.shippingAddrBean ? form.shippingAddrBean.addr : "" }}
+                        {{
+                          form.shippingAddrBean
+                            ? form.shippingAddrBean.addr
+                            : ""
+                        }}
                         {{
                           form.shippingAddrBean
                             ? form.shippingAddrBean.addrDetail
@@ -267,11 +279,15 @@ export default {
   mounted() {
     this.getInfo();
     if (
-      (this.$route.query.params != "[object Object]" && this.$route.query.params) ||
+      (this.$route.query.params != "[object Object]" &&
+        this.$route.query.params) ||
       JSON.parse(localStorage.getItem("productInfo"))
     ) {
       let info = {};
-      if (this.$route.query.params != "[object Object]" && this.$route.query.params) {
+      if (
+        this.$route.query.params != "[object Object]" &&
+        this.$route.query.params
+      ) {
         info = this.$route.query.params;
       } else {
         info = JSON.parse(localStorage.getItem("productInfo"));
@@ -406,12 +422,15 @@ export default {
     submitFormDraft() {
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
       if (this.form.saleModel == 2) {
         this.form.merchantClassifyId = "217524";
@@ -461,23 +480,35 @@ export default {
 
       if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
         if (this.form.datePicke) {
-          this.form.presaleStartTime = moment(this.form.datePicker[0]).valueOf();
+          this.form.presaleStartTime = moment(
+            this.form.datePicker[0]
+          ).valueOf();
           this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
         }
       }
 
       if (this.form.categoryId?.length > 0) {
-        this.form.categoryId = this.form.categoryId[this.form.categoryId.length - 1];
+        this.form.categoryId =
+          this.form.categoryId[this.form.categoryId.length - 1];
       }
 
       if (this.form.id) {
         if (this.skulist?.length > 0) {
-          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then((res) => {});
+          removeSkuBySkuId({ skuIds: this.skulist.toString() }).then(
+            (res) => {}
+          );
+        }
+        if (this.form.bannerList?.length > 0) {
+          this.form.bannerList.shift();
         }
         if (this.form.skuList.length < 1 || this.form.skuList === "") {
           this.$message.error(`规格不能为空`);
           return;
         }
+        // if (!this.form.shippingAddrBean.provinceCode) {
+        //   this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
+        //   return;
+        // }
         if (this.form.saleModel == 2) {
           this.form.merchantClassifyId = "217524";
           this.form.merchantClassifyName = "预售专区";