Pārlūkot izejas kodu

商品列表优化

home chao 5 gadi atpakaļ
vecāks
revīzija
80671a00b9

+ 80 - 28
src/views/goods/components/price-edit.vue

@@ -15,10 +15,10 @@
         </el-select>
       </el-form-item>
       <div class="line">
-        <el-form-item label="市场价:" prop="normalPrice" :rules="{required:true, validator:checkPrice, type:'float', trigger:'blur'}">
+        <el-form-item label="市场价:" prop="normalPrice" :rules="{required:true, validator:checkMultiplePrice, type:'float', trigger:'blur'}">
           <el-input v-model="formData.normalPrice" size="small" />
         </el-form-item>
-        <el-form-item label="成本价:" prop="costPrice" :rules="{required:true, validator:checkPrice, type:'float', trigger:'blur'}">
+        <el-form-item label="成本价:" prop="costPrice" :rules="{required:true, validator:checkMultiplePrice, type:'float', trigger:'blur'}">
           <el-input v-model="formData.costPrice" size="small" />
         </el-form-item>
       </div>
@@ -41,10 +41,10 @@
       <div v-show="formData.ladderPriceFlag === 1" class="multiple">
         <div class="group">
           <div v-for="(item, index) in formData.ladderPriceList" :key="'ladderPrice'+index" class="line">
-            <el-form-item label="起订量" label-width="60px" style="width:130px" :prop="'ladderPriceList.' + index + '.buyNum'" :rules="{validator:checkNumber, type:'number', trigger:'blur'}">
+            <el-form-item label="起订量" label-width="60px" style="width:130px" :prop="'ladderPriceList.' + index + '.buyNum'" :rules="{validator:checkMultipleNumber, type:'number', trigger:'blur'}">
               <el-input v-model.number="item.buyNum" size="small" />
             </el-form-item>
-            <el-form-item label="及以上,单价为" label-width="120px" style="width:210px" :prop="'ladderPriceList.' + index + '.buyPrice'" :rules="{validator:checkPrice, type:'float', trigger:'blur'}">
+            <el-form-item label="及以上,单价为" label-width="120px" style="width:210px" :prop="'ladderPriceList.' + index + '.buyPrice'" :rules="{validator:checkMultiplePrice, type:'float', trigger:'blur'}">
               <el-input v-model="item.buyPrice" size="small" />
             </el-form-item>
           </div>
@@ -113,8 +113,8 @@ export default {
       rules: {
         classifyID: [{ required: true, message: '*必填', trigger: 'change' }],
         ladderPriceFlag: [{ required: true, message: '*必填', trigger: 'change' }],
-        retailPrice: [{ validator: this.checkPrice, type: 'float', trigger: 'blur' }],
-        minBuyNumber: [{ validator: this.checkNumber, type: 'number', trigger: 'blur' }]
+        retailPrice: [{ validator: this.checkSinglePrice, type: 'float', trigger: 'blur' }],
+        minBuyNumber: [{ validator: this.checkSingleNumber, type: 'number', trigger: 'blur' }]
       }
     }
   },
@@ -152,6 +152,9 @@ export default {
             this.formData.ladderPriceList.push(JSON.parse(JSON.stringify(item)))
           }
         })
+        for (let i = 0; i < this.formData.ladderPriceList.length; i++) {
+          this.formData.ladderPriceList[i].buyPrice = this.toFloatFilter(this.formData.ladderPriceList[i].buyPrice)
+        }
       }
       this.ladderSize = this.formData.ladderPriceList.length
     }
@@ -175,6 +178,11 @@ export default {
     updateGoods() {
       this.$refs['dataForm'].validate((valid) => {
         if (valid) {
+          if (this.postData.ladderPriceList && this.postData.ladderPriceList.length > 0) {
+            for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
+              this.postData.ladderPriceList[i].delFlag = 1
+            }
+          } else { this.postData.ladderPriceList = [] }
           this.postData.classifyID = this.formData.classifyID
           this.postData.normalPrice = this.formData.normalPrice
           this.postData.costPrice = this.formData.costPrice
@@ -182,24 +190,15 @@ export default {
           if (this.formData.ladderPriceFlag === 0) {
             this.postData.retailPrice = this.formData.retailPrice
             this.postData.minBuyNumber = this.formData.minBuyNumber
-            for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
-              this.postData.ladderPriceList[i].delFlag = 1
-            }
           } else {
             for (let i = 0; i < this.formData.ladderPriceList.length; i++) {
-              this.formData.ladderPriceList[i].delFlag = 0
-            }
-            if (!this.postData.ladderPriceList || this.postData.ladderPriceList.length === 0) {
-              this.postData.ladderPriceList = this.formData.ladderPriceList
-            } else {
-              for (let i = 0; i < this.postData.ladderPriceList.length; i++) {
-                if (this.formData.ladderPriceList[i]) {
-                  this.postData.ladderPriceList[i].buyNum = this.formData.ladderPriceList[i].buyNum
-                  this.postData.ladderPriceList[i].buyPrice = this.formData.ladderPriceList[i].buyPrice
-                  this.postData.ladderPriceList[i].delFlag = 0
-                } else {
-                  this.postData.ladderPriceList[i].delFlag = 1
-                }
+              if (this.postData.ladderPriceList[i]) {
+                this.postData.ladderPriceList[i].delFlag = 0
+                this.postData.ladderPriceList[i].ladderNum = this.formData.ladderPriceList[i].ladderNum
+                this.postData.ladderPriceList[i].buyNum = this.formData.ladderPriceList[i].buyNum
+                this.postData.ladderPriceList[i].buyPrice = this.formData.ladderPriceList[i].buyPrice
+              } else {
+                this.postData.ladderPriceList.push(JSON.parse(JSON.stringify(this.formData.ladderPriceList[i])))
               }
             }
           }
@@ -212,38 +211,91 @@ export default {
       })
     },
     /** 自定义校验规则 */
-    checkPrice(rule, value, callback) {
+    checkSinglePrice(rule, value, callback) {
+      if (this.formData.ladderPriceFlag === 1) {
+        return callback()
+      }
       if (!value) {
         return callback(new Error('*必填'))
       }
       this.$nextTick(() => {
         if (!Number.parseFloat(value * 1)) {
-          callback(new Error('*请输入正确的金额'))
+          return callback(new Error('*请输入正确的金额'))
         } else {
           if (('' + value).split('.').length > 1 && ('' + value).split('.')[1].length > 2) {
             return callback(new Error('*最多保留两位小数'))
           } else {
-            callback()
+            return callback()
           }
         }
       })
     },
-    checkNumber(rule, value, callback) {
+    checkSingleNumber(rule, value, callback) {
+      if (this.formData.ladderPriceFlag === 1) {
+        return callback()
+      }
       if (!value) {
         return callback(new Error('*必填'))
       }
       this.$nextTick(() => {
         if (!Number.isInteger(value)) {
-          callback(new Error('*起订量数值填写错误'))
+          return callback(new Error('*起订量数值填写错误'))
+        } else {
+          return callback()
+        }
+      })
+    },
+    checkMultiplePrice(rule, value, callback) {
+      if (this.formData.ladderPriceFlag === 0) {
+        return callback()
+      }
+      if (!value) {
+        return callback(new Error('*必填'))
+      }
+      this.$nextTick(() => {
+        if (!Number.parseFloat(value * 1)) {
+          return callback(new Error('*请输入正确的金额'))
+        } else {
+          if (('' + value).split('.').length > 1 && ('' + value).split('.')[1].length > 2) {
+            return callback(new Error('*最多保留两位小数'))
+          } else {
+            return callback()
+          }
+        }
+      })
+    },
+    checkMultipleNumber(rule, value, callback) {
+      if (this.formData.ladderPriceFlag === 0) {
+        return callback()
+      }
+      if (!value) {
+        return callback(new Error('*必填'))
+      }
+      this.$nextTick(() => {
+        if (!Number.isInteger(value)) {
+          return callback(new Error('*起订量数值填写错误'))
         } else {
           if ((rule.fullField.indexOf('2') > 0 && this.formData.ladderPriceList[2].buyNum <= this.formData.ladderPriceList[1].buyNum) ||
             (rule.fullField.indexOf('1') > 0 && this.formData.ladderPriceList[1].buyNum <= this.formData.ladderPriceList[0].buyNum)) {
             return callback(new Error('*起订量必须大于上一个阶梯'))
           } else {
-            callback()
+            return callback()
           }
         }
       })
+    },
+    /** 两位小数转换 */
+    toFloatFilter(num) {
+      let result = '' + num
+      const temp = result.split('.')
+      if (temp.length === 1) {
+        result += '.00'
+      } else if (temp.length > 1) {
+        if (temp[1].length < 2) {
+          result += '0'
+        }
+      }
+      return result
     }
   }
 }

+ 6 - 6
src/views/goods/list-commonly.vue

@@ -94,11 +94,6 @@
         </template>
       </el-table-column>
       <el-table-column label="商品分类" align="center" prop="productClassifyName" />
-      <el-table-column align="center" label="添加时间" prop="addTime">
-        <template v-if="row.addTime" slot-scope="{row}">
-          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
-        </template>
-      </el-table-column>
       <el-table-column label="排序值" align="center" prop="commonlyProductSort">
         <template slot-scope="{row}">
           <el-input-number v-model="row.commonlyProductSort" controls-position="right" :min="1" :max="999" :maxlength="3" size="mini" style="width:65px;" />
@@ -109,6 +104,11 @@
           <el-button type="primary" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="cancelGoods(row)">取消</el-button>
         </template>
       </el-table-column>
+      <el-table-column align="center" label="添加时间" prop="addTime">
+        <template v-if="row.addTime" slot-scope="{row}">
+          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
+        </template>
+      </el-table-column>
     </el-table>
 
     <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
@@ -136,7 +136,7 @@ export default {
       total: 0,
       listQuery: {
         index: 1,
-        pageSize: 20,
+        pageSize: 10,
         organizeID: this.$store.getters.organizeID,
         commonlyProduct: '1', // 常用商品
         id: '',

+ 6 - 6
src/views/goods/list-preferential.vue

@@ -94,11 +94,6 @@
         </template>
       </el-table-column>
       <el-table-column label="商品分类" align="center" prop="productClassifyName" />
-      <el-table-column align="center" label="添加时间" prop="addTime">
-        <template v-if="row.addTime" slot-scope="{row}">
-          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
-        </template>
-      </el-table-column>
       <el-table-column label="排序值" align="center" prop="preferentialProductSort">
         <template slot-scope="{row}">
           <el-input-number v-model="row.preferentialProductSort" controls-position="right" :min="1" :max="999" :maxlength="3" size="mini" style="width:65px;" />
@@ -109,6 +104,11 @@
           <el-button type="primary" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="cancelGoods(row)">取消</el-button>
         </template>
       </el-table-column>
+      <el-table-column align="center" label="添加时间" prop="addTime">
+        <template v-if="row.addTime" slot-scope="{row}">
+          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
+        </template>
+      </el-table-column>
     </el-table>
 
     <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
@@ -136,7 +136,7 @@ export default {
       total: 0,
       listQuery: {
         index: 1,
-        pageSize: 20,
+        pageSize: 10,
         organizeID: this.$store.getters.organizeID,
         preferentialProduct: '1', // 星范精品
         id: '',

+ 6 - 6
src/views/goods/list-preferred.vue

@@ -94,11 +94,6 @@
         </template>
       </el-table-column>
       <el-table-column label="商品分类" align="center" prop="productClassifyName" />
-      <el-table-column align="center" label="添加时间" prop="addTime">
-        <template v-if="row.addTime" slot-scope="{row}">
-          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
-        </template>
-      </el-table-column>
       <el-table-column label="排序值" align="center" prop="preferredProductSort">
         <template slot-scope="{row}">
           <el-input-number v-model="row.preferredProductSort" controls-position="right" :min="1" :max="999" :maxlength="3" size="mini" style="width:65px;" />
@@ -109,6 +104,11 @@
           <el-button type="primary" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="cancelGoods(row)">取消</el-button>
         </template>
       </el-table-column>
+      <el-table-column align="center" label="添加时间" prop="addTime">
+        <template v-if="row.addTime" slot-scope="{row}">
+          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
+        </template>
+      </el-table-column>
     </el-table>
 
     <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
@@ -136,7 +136,7 @@ export default {
       total: 0,
       listQuery: {
         index: 1,
-        pageSize: 20,
+        pageSize: 10,
         organizeID: this.$store.getters.organizeID,
         preferredProduct: '1', // 星范优选
         id: '',

+ 1 - 1
src/views/goods/list-select.vue

@@ -121,7 +121,7 @@ export default {
       total: 0,
       listQuery: {
         index: 1,
-        pageSize: 20,
+        pageSize: 10,
         organizeID: this.$store.getters.organizeID,
         id: '',
         productName: '',

+ 6 - 6
src/views/goods/list.vue

@@ -136,17 +136,17 @@
         </template>
       </el-table-column>
       <el-table-column label="商品分类" align="center" prop="productClassifyName" width="100" />
-      <el-table-column align="center" label="添加时间" prop="addTime">
-        <template v-if="row.addTime" slot-scope="{row}">
-          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
-        </template>
-      </el-table-column>
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="{row}">
           <el-button type="primary" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="handleEdit(row)">编辑</el-button>
           <el-button :type="row.validFlag*1 === 1 ? 'danger' : 'success'" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="handleSwitch(row)">{{ row.validFlag*1 === 1 ? '下架' : '上架' }}</el-button>
         </template>
       </el-table-column>
+      <el-table-column align="center" label="添加时间" prop="addTime">
+        <template v-if="row.addTime" slot-scope="{row}">
+          <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
+        </template>
+      </el-table-column>
     </el-table>
 
     <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
@@ -187,7 +187,7 @@ export default {
       total: 0,
       listQuery: {
         index: 1,
-        pageSize: 20,
+        pageSize: 10,
         organizeID: this.$store.getters.organizeID,
         id: '',
         productName: '',