ソースを参照

优化商品管理页面限购量显示逻辑

- 修复主页面表格限购量字段显示问题,当值为0时显示'不限购'
- 为多规格商品表格添加限购量列,位置在库存列之后
- 优化限购量字段的数据类型兼容性,支持数字0和字符串'0'的判断
- 提升用户体验,使限购量为0时的特殊含义更加清晰
xw 2 ヶ月 前
コミット
2e0a8af322
1 ファイル変更73 行追加7 行削除
  1. 73 7
      src/views/hisStore/storeProduct/index.vue

+ 73 - 7
src/views/hisStore/storeProduct/index.vue

@@ -151,6 +151,12 @@
       </el-table-column>
       <el-table-column label="销量" align="center" prop="sales" />
       <el-table-column label="库存" align="center" prop="stock" />
+      <el-table-column label="限购量" align="center" prop="purchaseLimit" >
+        <template slot-scope="scope">
+          <span v-if="scope.row.purchaseLimit == 0 || scope.row.purchaseLimit === null || scope.row.purchaseLimit === undefined || scope.row.purchaseLimit === ''">不限购</span>
+          <span v-else>{{ scope.row.purchaseLimit }}</span>
+        </template>
+      </el-table-column>
       <el-table-column label="类型" align="center" prop="productType" >
         <template slot-scope="scope">
           <el-tag prop="productType" v-for="(item, index) in productTypeOptions"    v-if="scope.row.productType==item.dictValue">{{item.dictLabel}}</el-tag>
@@ -393,6 +399,9 @@
                         <div v-else-if="scope.column.property === 'onBehalfPaymentAmount'">
                           <el-input type="text" v-model="scope.row[scope.column.property]" :disabled="scope.row.hasDepositFeatureType === 0"/>
                         </div>
+                        <div v-else-if="scope.column.property === 'purchaseLimit'">
+                          <el-input type="number" v-model.number="scope.row[scope.column.property]" placeholder="0表示不限购" :min="0"/>
+                        </div>
                         <div v-else-if="scope.column.property.indexOf('value') !== -1" align="center">
                           {{ scope.row[scope.column.property] }}
                         </div>
@@ -465,6 +474,11 @@
                     <el-input type="text" v-model="scope.row.stock" maxlength="7"/>
                   </template>
                 </el-table-column>
+                <el-table-column prop="purchaseLimit" label="限购量" align="center">
+                  <template slot-scope="scope">
+                    <el-input type="number" v-model.number="scope.row.purchaseLimit" placeholder="0表示不限购" :min="0"/>
+                  </template>
+                </el-table-column>
                 <el-table-column prop="barCode" label="商品编号" width="130px" align="center">
                   <template slot-scope="scope">
                     <el-input type="text" v-model="scope.row.barCode"/>
@@ -781,6 +795,7 @@ export default {
           agentPrice: 0,
           otPrice: 0,
           stock: 0,
+          purchaseLimit: 0,
           barCode: '',
           weight: 0,
           volume: 0,
@@ -1001,6 +1016,10 @@ export default {
             if(this.imageArr.length>0){
               item.image = this.imageArr[0]
             }
+            // 确保purchaseLimit字段存在
+            if (item.purchaseLimit === undefined || item.purchaseLimit === null) {
+              this.$set(item, 'purchaseLimit', 0);
+            }
           });
         }else if(this.form.specType === 1) {
           this.manyFormValidate = res.value;
@@ -1011,14 +1030,50 @@ export default {
             width: 220
           };
           res.header.push(headerdel);
+          // 检查是否已存在限购量列,如果不存在则添加
+          const hasPurchaseLimitColumn = res.header.some(col => col.slot === 'purchaseLimit');
+          if (!hasPurchaseLimitColumn) {
+            // 找到库存列的索引位置
+            const stockColumnIndex = res.header.findIndex(col => col.slot === 'stock');
+            if (stockColumnIndex !== -1) {
+              // 在库存列之后插入限购量列
+              const purchaseLimitColumn = {
+                title: '限购量',
+                minWidth: 120,
+                align: 'center',
+                key: 'value1',
+                slot: 'purchaseLimit'
+              };
+              res.header.splice(stockColumnIndex + 1, 0, purchaseLimitColumn);
+            } else {
+              // 如果找不到库存列,则在操作列之前插入
+              const purchaseLimitColumn = {
+                title: '限购量',
+                minWidth: 120,
+                align: 'center',
+                key: 'value1',
+                slot: 'purchaseLimit'
+              };
+              res.header.splice(res.header.length - 1, 0, purchaseLimitColumn);
+            }
+          }
           this.form.header = res.header;
           let header = res.header;
           header.pop();
-          // this.manyFormValidate.map((item) => {
-          //   if(this.imageArr.length>0){
-          //     item.image = this.imageArr[0]
-          //   }
+          // this.manyFormValidate.map((item) => 1/1O
+          // if(this.imageArr.length>0){
+          // item.image = this.imageArr[0]
+          // }
           // });
+          // 确保所有多规格项都有purchaseLimit字段
+          this.manyFormValidate.map((item) => {
+            if(this.imageArr.length>0){
+              item.image = this.imageArr[0]
+            }
+            if (item.purchaseLimit === undefined || item.purchaseLimit === null) {
+              this.$set(item, 'purchaseLimit', 0);
+            }
+          });
         }
 
       }).catch(res => {
@@ -1215,7 +1270,8 @@ export default {
         prescribeFactory: null,
         prescribeName: null,
         isDisplay:"1",
-        companyIds:[]
+        companyIds:[],
+        purchaseLimit: 0
       };
       this.resetForm("form");
       this.oneFormValidate = [
@@ -1230,12 +1286,14 @@ export default {
           cost: 0,
           otPrice: 0,
           stock: 0,
+          purchaseLimit: 0,
           barCode: '',
           weight: 0,
           volume: 0,
           integral: 0,
           brokerage:0,
-          brokerageTwo:0
+          brokerageTwo:0,
+          brokerageThree:0
         }
       ]
       this.attrs=[];
@@ -1307,6 +1365,12 @@ export default {
         if (response.data.companyIds != null && response.data.companyIds != undefined && response.data.companyIds.length > 0) {
           this.form.companyIds = response.data.companyIds.split(',').map(Number);
         }
+        
+        // 确保purchaseLimit字段存在并设置默认值
+        if (this.form.purchaseLimit === undefined || this.form.purchaseLimit === null) {
+          this.$set(this.form, 'purchaseLimit', 0);
+        }
+        
         setTimeout(() => {
           that.generate();
         }, 200);
@@ -1326,12 +1390,14 @@ export default {
               cost: 0,
               otPrice: 0,
               stock: 0,
+              purchaseLimit: 0,
               barCode: '',
               weight: 0,
               volume: 0,
               integral: 0,
               brokerage:0,
-              brokerageTwo:0
+              brokerageTwo:0,
+              brokerageThree:0
             }
           ]
         }