Jelajahi Sumber

创建套餐如果仓库代码不一致就卡住

xdd 2 bulan lalu
induk
melakukan
6fe8b45002

+ 3 - 2
src/views/store/components/productAttrValueSelect.vue

@@ -31,6 +31,7 @@
       </el-table-column>
       <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="productName" />
       <el-table-column label="商品规格" align="center" prop="sku" />
+      <el-table-column label="仓库代码" align="center" prop="prodWareHouseCode" />
       <el-table-column label="库存" align="center" prop="stock" />
       <el-table-column label="单价" align="center" prop="price" />
       <el-table-column label="操作" align="center" width="100px" >
@@ -42,7 +43,7 @@
           >选择</el-button>
         </template>
       </el-table-column>
-    </el-table> 
+    </el-table>
     <pagination
       style="padding-bottom:10px;"
       v-show="total>0"
@@ -100,7 +101,7 @@ export default {
 };
 </script>
 <style scoped>
- 
+
 .product-select{
   padding-bottom: 15px;
 }

+ 28 - 0
src/views/store/storeProductPackage/index.vue

@@ -222,6 +222,7 @@
                 </el-table-column>
                 <el-table-column label="商品名称" show-overflow-tooltip align="center" prop="productName" />
                 <el-table-column label="商品规格" align="center" prop="sku" />
+                <el-table-column label="仓库代码" align="center" prop="prodWareHouseCode" />
                 <!-- <el-table-column label="库存" align="center" prop="stock" /> -->
                 <el-table-column label="售价" align="center"  prop="price"  >
                    <template slot-scope="scope">
@@ -496,8 +497,29 @@ export default {
       }
       row.count=1;
       row.money=row.count*row.price;
+      let testProduct = [...this.products,row]
+      if (!this.checkProductsWarehouseCode(testProduct)) {
+        this.$message.error("商品仓库代码不一致,且不能为空");
+        return;
+      }
       this.products.push(row);
       this.compute();
+
+      this.$message.success('添加成功!')
+    },
+    checkProductsWarehouseCode(products) {
+      const warehouseCodeSet = new Set(products.map(row => row.prodWareHouseCode));
+      // 2. 检查 Set 大小是否为 1
+      if (warehouseCodeSet.size !== 1) {
+        return false;
+      }
+      // 3. 获取 Set 中的唯一元素(因为 Set 大小为 1,所以可以直接获取)
+      const [singleWarehouseCode] = warehouseCodeSet;
+      // 4. 检查唯一元素是否为空
+      if (singleWarehouseCode === null || singleWarehouseCode === undefined || singleWarehouseCode === '') {
+        return false; // 元素为空
+      }
+      return true; // 所有条件都满足
     },
     handleAddProduct(){
       this.product.open=true;
@@ -639,6 +661,12 @@ export default {
       // return;
       this.$refs["form"].validate(valid => {
         if (valid) {
+
+          if (!this.checkProductsWarehouseCode(this.products)) {
+            this.$message.error("商品仓库代码不一致,且不能为空");
+            return;
+          }
+
           if (this.form.packageId != null) {
             updateStoreProductPackage(this.form).then(response => {
               if (response.code === 200) {