浏览代码

产品详情以及产品类别详情修改

zhuliu 1 年之前
父节点
当前提交
cf5b65293f

+ 12 - 7
src/views/pms/components/importDialog.vue

@@ -1,4 +1,4 @@
-<template> 
+<template>
   <el-dialog title="导入数据" :visible.sync="visible" :before-close="handleClose" width="40%">
     <div>
       <p>
@@ -8,7 +8,7 @@
     </div>
     <span slot="footer" class="dialog-footer">
       <el-button @click="handleClose">取 消</el-button>
-      <el-button type="primary" @click="submit">确 定</el-button>
+      <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
     </span>
   </el-dialog>
 </template>
@@ -22,8 +22,13 @@
     },
     data() {
       return {
+        btnLoading:false,
         visible:false,
-        files:[]
+        files:[],
+        api : {
+          '1':'importCategory',
+          '2':'ImportProductBatch'
+        }
       }
     },
     methods:{
@@ -84,16 +89,16 @@
         for (var i = 0; i < this.files.length; i++) {
           formData.append('file', this.files[i])//文件数据
         }
-        var api = {
-          '2':'ImportProductBatch'
-        }
-        this.$api[api[this.type]](formData).then(res=>{
+        this.btnLoading = true
+        this.$api[this.api[this.type]](formData).then(res=>{
           if(res.code == 200){
+            this.btnLoading = false
             this.$message.success("正在导入中")
             this.$emit('downLoad')
             this.handleClose()
           }
         }).catch(error=>{
+          this.btnLoading = false
           this.$message.error("导入失败")
         })
       },

+ 27 - 3
src/views/pms/product/components/ProductDetail.vue

@@ -1,10 +1,12 @@
-<template> 
+<template>
   <el-card class="form-container" shadow="never">
 
     <product-info-detail
       v-model="productParam"
       :is-edit="isEdit"
       @finishCommit="finishCommit"
+      @resetForm="resetForm"
+      :btnLoading="btnLoading"
     >
     </product-info-detail>
 
@@ -37,6 +39,7 @@
     },
     data() {
       return {
+        btnLoading:false,
         productParam: Object.assign({}, defaultProductParam),
       }
     },
@@ -63,6 +66,10 @@
 
         });
       },
+      //重置表单
+      resetForm(){
+        this.productParam = Object.assign({}, defaultProductParam);
+      },
       //提交信息
       finishCommit(isEdit) {
         this.$confirm('是否要提交该产品', '提示', {
@@ -70,25 +77,42 @@
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
+          this.btnLoading = true
           if(isEdit){
             this.productParam.id = this.productCateId
             this.$api.addOrUpdateHotProduct(this.productParam).then(response=>{
+              this.btnLoading = false
               this.$message({
                 type: 'success',
                 message: '提交成功',
                 duration:1000
               });
               this.$router.back();
-            });
+            }).catch(error=>{
+              this.btnLoading = false
+              this.$message({
+                type: 'success',
+                message: '提交失败',
+                duration:1000
+              });
+            })
           }else{
             this.$api.addOrUpdateHotProduct(this.productParam).then(response=>{
+              this.btnLoading = false
               this.$message({
                 type: 'success',
                 message: '提交成功',
                 duration:1000
               });
               location.reload();
-            });
+            }).catch(error=>{
+              this.btnLoading = false
+              this.$message({
+                type: 'success',
+                message: '提交失败',
+                duration:1000
+              });
+            })
           }
         })
       }

+ 22 - 1
src/views/pms/product/components/ProductInfoDetail.vue

@@ -48,7 +48,8 @@
         <el-input v-model="value.sort" placeholder="请输入排序"></el-input>
       </el-form-item> -->
       <el-form-item style="text-align: center">
-        <el-button type="primary" size="medium" @click="submit('productInfoForm')">确认</el-button>
+        <el-button type="primary" size="medium" @click="submit('productInfoForm')" :loading="btnLoading">确认</el-button>
+        <el-button v-if="!isEdit" @click="resetForm('productCateFrom')">重置</el-button>
       </el-form-item>
     </el-form>
   </div>
@@ -63,6 +64,10 @@
       isEdit: {
         type: Boolean,
         default: false
+      },
+      btnLoading:{
+        type: Boolean,
+        default: false
       }
     },
     data() {
@@ -84,6 +89,13 @@
     created() {
     },
     computed:{
+      //重置表单
+      resetForm(formName) {
+        this.$refs[formName].resetFields();
+        this.selectProductCateValue=null,
+        this.files=[]
+        this.$emit('resetForm')
+      },
       //产品的编号
       productId(){
         return this.value.id;
@@ -142,7 +154,16 @@
       handleEditCreated(){
         if(this.value.productCategoryId!=null){
           // this.selectProductCateValue.push(this.value.cateParentId);
+          if(this.value.path){
+            var arr = this.value.path.split('/')
+            if(arr[arr.length-1] == ''){
+              arr.pop()
+            }
+            var arr = arr.map(item=>parseInt(item))
+            this.selectProductCateValue.push(...arr);
+          }
           this.selectProductCateValue.push(this.value.productCategoryId);
+          console.log(this.selectProductCateValue)
         }
         this.hasEditCreated=true;
       },

+ 16 - 3
src/views/pms/product/index.vue

@@ -27,7 +27,7 @@
             <el-cascader
               clearable
               :props="categoryProp()"
-              v-model="listQuery.productCategoryIds "
+              v-model="listQuery.productCategoryIds1 "
               :options="productCateOptions">
             </el-cascader>
           </el-form-item>
@@ -90,6 +90,12 @@
             <!-- <p>货号:{{scope.row.productSn}}</p> -->
           </template>
         </el-table-column>
+        <el-table-column label="所属类别" width="120" align="center">
+          <template slot-scope="scope">
+            <p v-if="scope.row.categoryName">所属类别:{{scope.row.categoryName}}</p>
+            <!-- <p>货号:{{scope.row.productSn}}</p> -->
+          </template>
+        </el-table-column>
         <el-table-column label="标签" width="140" align="center">
           <template slot-scope="scope">
             <p>上架:
@@ -97,7 +103,7 @@
                 @change="handlePublishStatusChange(scope.$index, scope.row)"
                 :active-value="true"
                 :inactive-value="false"
-                v-model="scope.row.publishStatus">
+                v-model="scope.row.ifShow">
               </el-switch>
             </p>
           </template>
@@ -178,6 +184,7 @@
     ifShow: null,
     sourceFrom: null,
     productCategoryIds : null,
+    productCategoryIds1 : null,
     bestSellingBrand : null
   };
 
@@ -288,6 +295,12 @@
       //检索
       handleSearchList() {
         this.listQuery.current = 1;
+        this.listQuery.productCategoryIds = []
+        if(this.listQuery.productCategoryIds1 && this.listQuery.productCategoryIds1.length>0){
+          this.listQuery.productCategoryIds1.forEach(item => {
+            this.listQuery.productCategoryIds.push(item[item.length-1])
+          });
+        }
         this.getList();
       },
       //添加产品
@@ -364,7 +377,7 @@
       handlePublishStatusChange(index, row) {
         let ids = [];
         ids.push(row.id);
-        this.updatePublishStatus(row.publishStatus, ids);
+        this.updatePublishStatus(!row.ifShow, ids);
       },
       //修改产品状态
       updatePublishStatus(publishStatus, ids) {

+ 21 - 4
src/views/pms/productCate/components/ProductCateDetail.vue

@@ -40,7 +40,7 @@
         <el-input type="textarea" :autosize="true" v-model="productCate.description" placeholder="请输入类别的描述"></el-input>
       </el-form-item>
       <el-form-item>
-        <el-button type="primary" @click="onSubmit('productCateFrom')">提交</el-button>
+        <el-button type="primary" @click="onSubmit('productCateFrom')" :loading="btnLoading">提交</el-button>
         <el-button v-if="!isEdit" @click="resetForm('productCateFrom')">重置</el-button>
       </el-form-item>
     </el-form>
@@ -78,6 +78,7 @@
           ],
 
         },
+        btnLoading:false
 
       }
     },
@@ -196,29 +197,45 @@
               cancelButtonText: '取消',
               type: 'warning'
             }).then(() => {
-
+              this.btnLoading = true
               if (this.isEdit) {
                 //更新产品类别
                 this.productCate.id = this.productCateId
                 this.$api.editCategory(this.productCate).then(response => {
+                  this.btnLoading = false
                   this.$message({
                     message: '修改成功',
                     type: 'success',
                     duration: 1000
                   });
                   this.$router.back();
-                });
+                }).catch(error=>{
+                  this.btnLoading = false
+                  this.$message({
+                    message: '修改失败',
+                    type: 'success',
+                    duration: 1000
+                  });
+                })
               } else {
                 //添加产品类别
                 this.$api.addCategory(this.productCate).then(response => {
                   this.$refs[formName].resetFields();
                   this.resetForm(formName);
+                  this.btnLoading = false
                   this.$message({
                     message: '提交成功',
                     type: 'success',
                     duration: 1000
                   });
-                });
+                }).catch(error=>{
+                  this.btnLoading = false
+                  this.$message({
+                    message: '提交失败',
+                    type: 'success',
+                    duration: 1000
+                  });
+                })
               }
             });