From d35533b1b42df7e1808a19a8ea72613e605cd6ef Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期四, 09 十一月 2023 16:49:35 +0800
Subject: [PATCH] 添加、编辑上传图片接口联调及编辑和查看和列表图片回显

---
 src/views/productManage/product/AddProductDialog.vue |   65 ++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/views/productManage/product/AddProductDialog.vue b/src/views/productManage/product/AddProductDialog.vue
index 28db941..62f996c 100644
--- a/src/views/productManage/product/AddProductDialog.vue
+++ b/src/views/productManage/product/AddProductDialog.vue
@@ -140,7 +140,7 @@
                       :min="0"
                       :controls="false"
                       size="mini"
-                      style="width: 81%"
+                      style="width: 85%"
                       :disabled="!showFooter"
                     ></el-input-number>
                   </el-form-item>
@@ -162,7 +162,7 @@
                       :min="0"
                       :controls="false"
                       size="mini"
-                      style="width: 81%"
+                      style="width: 85%"
                       :disabled="!showFooter"
                     ></el-input-number>
                   </el-form-item>
@@ -473,6 +473,7 @@
 import IconCropper from "./IconCropper"
 import { getProductCategoryList } from "@/api/product/productCategory"
 import { getProductList, addProduct, updateProduct } from "@/api/product/product"
+import { uploadFiles } from "@/api/common/other"
 
 export default {
   name: "AddProductDialog",
@@ -550,18 +551,14 @@
       statisticsMap: {
         inLibrary: 0 // 鍦ㄥ簱
       },
-      isView: false
+      isView: false,
+      fileFormdata: null // 涓婁紶鍥剧墖鍏ュ弬
     }
   },
   created() {
     if (this.editConfig.title === "缂栬緫" && !this.editConfig.autoEdit) {
       this.isView = true
     }
-    // if (this.editConfig.title === "鏂板缓") {
-    //   this.editConfig.infomation.imageSrc = ""
-    // } else {
-    //   this.editConfig.infomation.imageSrc = "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
-    // }
     this.getProductCategoryList()
     this.getProductList()
     this.setTableForm()
@@ -654,20 +651,45 @@
       console.log(this.editConfig.infomation)
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          let requestUrl = this.editConfig.title === "鏂板缓" ? addProduct : updateProduct
-          this.unsetFieldsToNumber()
-          requestUrl({
-            ...this.editConfig.infomation
-          }).then((res) => {
-            console.log(res)
-            this.editConfig.visible = false
-            if (res.code === 200) {
-              this.$message.success("娣诲姞鎴愬姛")
-              this.$parent.getData()
+          console.log(this.fileFormdata == null)
+          let attachmentIDs = []
+          if (this.fileFormdata == null) {
+            if (this.editConfig.infomation.attachmentList?.length > 0) {
+              this.editConfig.infomation.attachmentList.forEach((ele) => {
+                attachmentIDs.push(ele.id)
+              })
+            } else {
+              attachmentIDs = []
             }
-          }, console.error)
+            this.saveEditRequest(attachmentIDs)
+          } else {
+            uploadFiles(this.fileFormdata).then((res) => {
+              if (res.code == 200) {
+                res.data.forEach((ele) => {
+                  attachmentIDs.push(ele.id)
+                })
+              }
+              this.saveEditRequest(attachmentIDs)
+            })
+          }
         }
       })
+    },
+    // 淇濆瓨/缂栬緫鎺ュ彛璇锋眰
+    saveEditRequest(attachmentIDs) {
+      let requestUrl = this.editConfig.title === "鏂板缓" ? addProduct : updateProduct
+      this.unsetFieldsToNumber()
+      requestUrl({
+        ...this.editConfig.infomation,
+        attachmentIDs
+      }).then((res) => {
+        console.log(res)
+        this.editConfig.visible = false
+        if (res.code === 200) {
+          this.$message.success("娣诲姞鎴愬姛")
+          this.$parent.getData()
+        }
+      }, console.error)
     },
     // 鍒犻櫎
     delClick() {},
@@ -728,8 +750,9 @@
       this.tableData.splice(scope.$index, 1)
     },
     // 涓婁紶鍥剧墖
-    getImageData(data) {
-      console.log(data, "鍥剧墖鏁版嵁")
+    getImageData(formdata) {
+      this.fileFormdata = formdata
+      // console.log(formdata, "鍥剧墖鏁版嵁")
     },
     // 杩涘嚭鐐瑰嚮
     inOutBoundClick() {

--
Gitblit v1.8.0