浏览代码

产品的新增

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

+ 3 - 3
src/api/newApi/product.js

@@ -36,19 +36,19 @@ export default {
    * 修改产品类别
    */
   updateProduct(data) {
-    return axios.post("/xiaoshi/productCategory/updateProduct", data);
+    return axios.post("/xiaoshi/product/updateProduct", data);
   },
   /**
    * 查询产品类别
    */
   queryProduct(data) {
-    return axios.post("/xiaoshi/productCategory/queryProduct", data);
+    return axios.post("/xiaoshi/product/queryProduct", data);
   },
   /**
    * 删除产品类别
    */
   deleteProduct(data) {
-    return axios.post("/xiaoshi/productCategory/deleteProduct", data);
+    return axios.post("/xiaoshi/product/deleteProduct", data);
   },
  
   

+ 34 - 2
src/views/product/components/dialog/addEditProduct.vue

@@ -90,6 +90,7 @@
 
 <script>
 import choosePerson from '@/views/components/dialog/person.vue'
+import { mapGetters } from 'vuex';
 export default {
   components:{
     choosePerson
@@ -139,6 +140,9 @@ export default {
       chooseType:1
     };
   },
+  computed:{
+    ...mapGetters(['userinfo'])
+  },
   mounted() { 
     this.getProductCategory();
   },
@@ -167,6 +171,9 @@ export default {
         this.title = '编辑产品'
       } else {
         if (this.form.isTheCompany=='1') {
+          // 获取所属租户公司
+          this.form.companyName = this.userinfo.tenantName
+          this.form.tenantId = this.userinfo.tenantId
           this.title = '新增本公司产品'
         } else {
           this.title = '新增外公司产品'
@@ -175,10 +182,35 @@ export default {
       this.dialogVisible = true;
     },
     // 弹窗确定
-    submit() { 
+    // 弹窗确定
+    submit() {
       this.$refs.ruleForm.validate(valid => {
         if (valid) {
-          this.handleClose()
+          var formData = new FormData()
+          formData.append('product',JSON.stringify(this.form))
+          if(this.file.length>0){
+            this.file.forEach(item=>{
+              formData.append("files", item);
+            })
+          }
+          if(this.form.id){
+            this.$api.updateProduct(formData).then(response=>{
+              this.$message.success('更新成功')
+              this.$emit('getMessage','更新成功')
+              this.handleClose()
+            }).catch(error=>{
+
+            })
+          }else{
+            this.$api.addProduct(formData).then(response=>{
+              this.$message.success('添加成功')
+              this.$emit('getMessage','添加成功')
+              this.handleClose()
+            }).catch(error=>{
+
+            })
+          }
+          
         } else {
           
         }

+ 11 - 2
src/views/product/components/index.vue

@@ -34,7 +34,7 @@
       </el-header>
       <el-main>
         <div style="height: 100%;">
-          <component :is="componentType" :tableData="tableData" :queryParams="queryParams"  @options="handleOption" @on-sort="handleSort"></component>
+          <component :is="componentType" :tableData="tableData" :queryParams="queryParams" :searchOption="searchOption"  @options="handleOption" @on-sort="handleSort"></component>
         </div>
       </el-main>
       <el-footer class="pagination">
@@ -46,7 +46,7 @@
     </el-container>
 
     <addEditCategory ref="addEditCategory" @getMessage="getMessage"></addEditCategory>
-    <addEditProduct ref="addEditProduct"></addEditProduct>
+    <addEditProduct ref="addEditProduct" @getMessage="getMessage"></addEditProduct>
     <myImageViewer v-if="showImg" :on-close="closeViewer" :src="imgSrc"></myImageViewer>
   </div>
 </template>
@@ -118,6 +118,8 @@ export default {
       showImg:false,
       //图片地址
       imgSrc:'',
+      //接受子组件消息
+      handleMessage:'',
     }
   },
   mounted() {
@@ -241,6 +243,13 @@ export default {
     //获取子组件信息
     getMessage(val){
       this.getList()
+      this.clearMessage()
+    },
+    //清空信息
+    clearMessage(){
+      this.$nextTick(()=>{
+        this.handleMessage = ''
+      })
     },
     // 获取产品类别数据
     getList(){

+ 3 - 0
src/views/product/components/mixins/product.js

@@ -0,0 +1,3 @@
+export default {
+    
+}

+ 6 - 3
src/views/product/components/view/categoryTable.vue

@@ -6,7 +6,7 @@
         <!-- 产品 -->
         <template slot-scope="scope">
           <div style="padding: 10px;">
-            <component :is="componentType" :tableData="scope.row.productData" :row="scope.row" @optionsSon="handleOptionSon"></component>
+            <component :is="componentType" :tableData="scope.row.productData" :queryParams="scope.row.queryParams" :row="scope.row"  v-bind="$attrs" v-on="$listeners"></component>
           </div>
         </template>
       </el-table-column>
@@ -158,8 +158,11 @@ export default {
     },
     // 展开行打开或者关闭事件
     handleExpand(row, rowList) {
-      console.log(row, rowList);
-      // this.getList(row)
+      row.productData =row.productData || []
+      row.queryParams =row.queryParams || {
+        current:0,
+        size:10
+      }
     },
     // 编辑下拉菜单
     handleCommand(val, row) {

+ 40 - 166
src/views/product/components/view/productTable.vue

@@ -68,20 +68,30 @@ export default {
         }
       }
     },
-    row:''
+    row:'',
+    searchOption:{
+      default:{}
+    }
   },
   data() {
     return {
       disabled:false,
       isMore:false,
       isflag:false,
+      // 排序数组
+      sort: [],
+      //事件类型及所选
+      action:{
+        type:'',//1表示删除,2表示其他,3表示新增
+        id:''
+      }
     }
   },
   mounted() {
     if(!this.row){
       this.disabled = true
     }else{
-      this.getList()
+      this.disabled = false
     }
   },
   methods: {
@@ -90,174 +100,38 @@ export default {
       this.$emit('optionsSon',{val,row})
     },
     //获取数据
-    getList(){
-      if(this.disabled) return;
+    getList() {
+      if (!this.row) return;
+      if (this.queryParams.current * this.queryParams.size >= this.queryParams.total) {
+        this.isMore = true
+        this.disabled = true
+        setTimeout(() => {
+          this.isMore = false;
+          this.isFlag = false
+        }, 1000)
+      }
+      if (this.disabled) return;
       this.queryParams.current += 1
+      var str = this.$commonJS.objectToString(this.searchOption) 
+      let params = {
+        ...this.queryParams,
+        searchQuery:str?' AND ':'' + `category_id=${this.row.id}`,//检索条件
+        orderDTOList: this.sort,//排序
+      }
       this.isMore = false;
-      this.isflag = true;
-      this.tableData.push(
-        {
-          "id": 43,
-          "productName": "测试人员产品",
-          "marketTime": "2023-04-19 00:00:00",
-          "companyName": "测试",
-          "tenantId": 7,
-          "productExplain": "测试不同租户下的产品",
-          "productCategoryId": 27,
-          "licenseRate": 0.5,
-          "createPersonName": "测试",
-          "pictures": [],
-          "productPatentNum": 0,
-          "patentNum": 0,
-          "productCategory": {
-            "id": 27,
-            "productCategoryName": "测试人员类别",
-            "remark": "测试不同租户下类别",
-            "licenseRate": 0.5,
-            "createPersonName": "测试",
-            "pictures": [
-              {
-                  "id": 43,
-                  "productCategoryId": 27,
-                  "name": "1+",
-                  "suffix": "jpg",
-                  "url": "/20230509/112080e1e7ee4899b9a765248cf92254.jpg"
-              }
-            ]
-          }
-        },
-        {
-          "id": 43,
-          "productName": "测试人员产品",
-          "marketTime": "2023-04-19 00:00:00",
-          "companyName": "测试",
-          "tenantId": 7,
-          "productExplain": "测试不同租户下的产品",
-          "productCategoryId": 27,
-          "licenseRate": 0.5,
-          "createPersonName": "测试",
-          "pictures": [],
-          "productPatentNum": 0,
-          "patentNum": 0,
-          "productCategory": {
-            "id": 27,
-            "productCategoryName": "测试人员类别",
-            "remark": "测试不同租户下类别",
-            "licenseRate": 0.5,
-            "createPersonName": "测试",
-            "pictures": [
-              {
-                  "id": 43,
-                  "productCategoryId": 27,
-                  "name": "1+",
-                  "suffix": "jpg",
-                  "url": "/20230509/112080e1e7ee4899b9a765248cf92254.jpg"
-              }
-            ]
-          }
-        },
-        {
-          "id": 43,
-          "productName": "测试人员产品",
-          "marketTime": "2023-04-19 00:00:00",
-          "companyName": "测试",
-          "tenantId": 7,
-          "productExplain": "测试不同租户下的产品",
-          "productCategoryId": 27,
-          "licenseRate": 0.5,
-          "createPersonName": "测试",
-          "pictures": [],
-          "productPatentNum": 0,
-          "patentNum": 0,
-          "productCategory": {
-            "id": 27,
-            "productCategoryName": "测试人员类别",
-            "remark": "测试不同租户下类别",
-            "licenseRate": 0.5,
-            "createPersonName": "测试",
-            "pictures": [
-              {
-                  "id": 43,
-                  "productCategoryId": 27,
-                  "name": "1+",
-                  "suffix": "jpg",
-                  "url": "/20230509/112080e1e7ee4899b9a765248cf92254.jpg"
-              }
-            ]
-          }
-        },
-        {
-          "id": 43,
-          "productName": "测试人员产品",
-          "marketTime": "2023-04-19 00:00:00",
-          "companyName": "测试",
-          "tenantId": 7,
-          "productExplain": "测试不同租户下的产品",
-          "productCategoryId": 27,
-          "licenseRate": 0.5,
-          "createPersonName": "测试",
-          "pictures": [],
-          "productPatentNum": 0,
-          "patentNum": 0,
-          "productCategory": {
-            "id": 27,
-            "productCategoryName": "测试人员类别",
-            "remark": "测试不同租户下类别",
-            "licenseRate": 0.5,
-            "createPersonName": "测试",
-            "pictures": [
-              {
-                  "id": 43,
-                  "productCategoryId": 27,
-                  "name": "1+",
-                  "suffix": "jpg",
-                  "url": "/20230509/112080e1e7ee4899b9a765248cf92254.jpg"
-              }
-            ]
-          }
-        },
-        {
-          "id": 43,
-          "productName": "测试人员产品",
-          "marketTime": "2023-04-19 00:00:00",
-          "companyName": "测试",
-          "tenantId": 7,
-          "productExplain": "测试不同租户下的产品",
-          "productCategoryId": 27,
-          "licenseRate": 0.5,
-          "createPersonName": "测试",
-          "pictures": [],
-          "productPatentNum": 0,
-          "patentNum": 0,
-          "productCategory": {
-            "id": 27,
-            "productCategoryName": "测试人员类别",
-            "remark": "测试不同租户下类别",
-            "licenseRate": 0.5,
-            "createPersonName": "测试",
-            "pictures": [
-              {
-                  "id": 43,
-                  "productCategoryId": 27,
-                  "name": "1+",
-                  "suffix": "jpg",
-                  "url": "/20230509/112080e1e7ee4899b9a765248cf92254.jpg"
-              }
-            ]
-          }
+      this.isFlag = true;
+      this.$api.queryProduct(params).then(res => {
+        if (res.code == 200) {
+          this.tableData.push(...res.data.data)
+          this.queryParams.total = res.data.total
         }
-      )
-      this.queryParams.total = 15
-      console.log(this.queryParams)
-      if(this.queryParams.current * this.queryParams.size >= this.queryParams.total){
-        this.isMore = true 
-        this.disabled = true
-      }
-      this.$nextTick(()=>{
-        this.isMore = false;
-        this.isflag = false 
+      }).catch(err => {
       })
-    }
+      setTimeout(() => {
+        this.isMore = false;
+        this.isFlag = false
+      }, 1000)
+    },
   },
 }
 </script>