From d3004dd80e5fa80c696eaf2aeff089c5fb01bfe2 Mon Sep 17 00:00:00 2001
From: zuozhengqing <a13193816592@163.com>
Date: 星期五, 10 十一月 2023 15:28:52 +0800
Subject: [PATCH] Merge branch 'dev' of http://192.168.5.5:10010/r/web/WMS into dev

---
 src/views/productManage/product/AddProductDialog.vue |  197 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 131 insertions(+), 66 deletions(-)

diff --git a/src/views/productManage/product/AddProductDialog.vue b/src/views/productManage/product/AddProductDialog.vue
index 27f441a..62f996c 100644
--- a/src/views/productManage/product/AddProductDialog.vue
+++ b/src/views/productManage/product/AddProductDialog.vue
@@ -1,14 +1,14 @@
 <template>
   <div class="add-common">
     <el-dialog
-      :title="editCommonConfig.title + '浜у搧'"
+      :title="modalTitle + '浜у搧'"
       :visible.sync="editConfig.visible"
       :width="dialogWidth"
       :before-close="handleClose"
     >
       <!-- 澶� -->
       <div slot="title" class="dialog-header">
-        <span>{{ editCommonConfig.title + "浜у搧" }}</span>
+        <span>{{ modalTitle + "浜у搧" }}</span>
         <div class="header_btns">
           <span class="btn">
             <i class="el-icon-printer"></i>
@@ -43,6 +43,8 @@
             :show-procure="showProcure"
             :countObject="statisticsMap"
             :show-sale="showSale"
+            @listingRulesClick="listingRulesClick"
+            @reorderRulesClick="reorderRulesClick"
           />
           <div class="bottom">
             <el-tabs v-model="activeName" type="card">
@@ -120,6 +122,14 @@
                       :disabled="!showFooter"
                     ></el-input>
                   </el-form-item>
+                  <el-form-item label="鍥剧墖涓婁紶锛�" prop="imageUrl">
+                    <IconCropper
+                      :isView="isView"
+                      :image-url="editConfig.infomation.imageSrc"
+                      @getImageData="getImageData"
+                      style="width: 85%"
+                    />
+                  </el-form-item>
                 </div>
                 <div class="right">
                   <el-form-item label="閿�鍞环鏍�" prop="salePrice">
@@ -130,7 +140,7 @@
                       :min="0"
                       :controls="false"
                       size="mini"
-                      style="width: 81%"
+                      style="width: 85%"
                       :disabled="!showFooter"
                     ></el-input-number>
                   </el-form-item>
@@ -152,7 +162,7 @@
                       :min="0"
                       :controls="false"
                       size="mini"
-                      style="width: 81%"
+                      style="width: 85%"
                       :disabled="!showFooter"
                     ></el-input-number>
                   </el-form-item>
@@ -460,11 +470,11 @@
 </template>
 
 <script>
-// import CommonFormTableView from "@/components/makepager/CommonFormTableView"
+import IconCropper from "./IconCropper"
 import { getProductCategoryList } from "@/api/product/productCategory"
 import { getProductList, addProduct, updateProduct } from "@/api/product/product"
+import { uploadFiles } from "@/api/common/other"
 
-let inputElement = null
 export default {
   name: "AddProductDialog",
   props: {
@@ -474,13 +484,24 @@
         return {
           visible: false,
           title: "鏂板缓",
-          infomation: {}
+          infomation: {},
+          autoEdit: false
         }
       }
     }
   },
-  components: {},
-  computed: {},
+  components: { IconCropper },
+  computed: {
+    modalTitle() {
+      if (this.editConfig.title === "缂栬緫" && this.editConfig.autoEdit) {
+        return "缂栬緫"
+      } else if (this.editConfig.title === "缂栬緫") {
+        return !this.showEdit ? "缂栬緫" : "鏌ョ湅"
+      } else {
+        return "鏂板缓"
+      }
+    }
+  },
   data() {
     return {
       dialogWidth: "50%",
@@ -488,7 +509,7 @@
       rules: {
         name: [{ required: true, message: "璇疯緭鍏ヤ骇鍝佸悕绉�", trigger: "blur" }],
         model: [{ required: true, message: "璇烽�夋嫨鐗╂枡绫诲瀷", trigger: "change" }],
-        salePrice: [{ required: true, message: "璇疯緭鍏ラ攢鍞环鏍�", trigger: "blur" }],
+        // salePrice: [{ required: true, message: "璇疯緭鍏ラ攢鍞环鏍�", trigger: "blur" }],
         unit: [{ required: true, message: "璇疯緭鍏ュ崟浣�", trigger: "blur" }]
       },
       memberOptions: [{ name: "绠$悊鍛�", id: 1 }],
@@ -529,17 +550,48 @@
       ],
       statisticsMap: {
         inLibrary: 0 // 鍦ㄥ簱
-      }
+      },
+      isView: false,
+      fileFormdata: null // 涓婁紶鍥剧墖鍏ュ弬
     }
   },
   created() {
+    if (this.editConfig.title === "缂栬緫" && !this.editConfig.autoEdit) {
+      this.isView = true
+    }
     this.getProductCategoryList()
     this.getProductList()
     this.setTableForm()
     this.setBottonView()
     this.statisticsMap.inLibrary = this.editConfig?.infomation?.amount ?? 0
+    if (this.editConfig.autoEdit) {
+      this.editClick()
+    }
+    this.setOptionalFieldsToEmpty()
   },
   methods: {
+    /**
+     * 闈炲繀濉」鍚庣杩斿洖鐨勬槸鏁板瓧 0,琛ㄥ崟闇�瑕佺┖涓叉墠鑳借涓烘湭閫夋嫨鍥炴樉
+     */
+    setOptionalFieldsToEmpty() {
+      let arr = ["productType", "categoryId"]
+      arr
+        .filter((filed) => this.editConfig.infomation[filed] === 0)
+        .forEach((filed) => {
+          this.editConfig.infomation[filed] = ""
+        })
+    },
+    /**
+     * 鍚庣鍙帴鍙楁暟瀛楀舰寮�, 淇濆瓨鏃惰繕寰楀啀杞洖鍘�
+     */
+    unsetFieldsToNumber() {
+      let arr = ["productType", "categoryId"]
+      arr
+        .filter((filed) => this.editConfig.infomation[filed] === "")
+        .forEach((filed) => {
+          this.editConfig.infomation[filed] = 0
+        })
+    },
     // 鑾峰彇浜у搧绫诲埆
     async getProductCategoryList() {
       await getProductCategoryList({
@@ -599,19 +651,45 @@
       console.log(this.editConfig.infomation)
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          let requestUrl = this.editConfig.title === "鏂板缓" ? addProduct : updateProduct
-          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 = []
             }
-          })
+            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() {},
@@ -672,50 +750,9 @@
       this.tableData.splice(scope.$index, 1)
     },
     // 涓婁紶鍥剧墖
-    toGetImg() {
-      if (this.showFooter) {
-        if (inputElement === null) {
-          // 鐢熸垚鏂囦欢涓婁紶鐨勬帶浠�
-          inputElement = document.createElement("input")
-          inputElement.setAttribute("type", "file")
-          inputElement.style.display = "none"
-          if (window.addEventListener) {
-            inputElement.addEventListener("change", this.uploadFile, false)
-          } else {
-            inputElement.attachEvent("onchange", this.uploadFile)
-          }
-          document.body.appendChild(inputElement)
-        }
-        inputElement.click()
-      }
-    },
-    uploadFile(el) {
-      if (el && el.target && el.target.files && el.target.files.length > 0) {
-        console.log(el)
-        const files = el.target.files[0]
-        const isLt2M = files.size / 1024 / 1024 < 2
-        const size = files.size / 1024 / 1024
-        console.log(size)
-        // 鍒ゆ柇涓婁紶鏂囦欢鐨勫ぇ灏�
-        if (!isLt2M) {
-          this.$message.error("涓婁紶澶村儚鍥剧墖澶у皬涓嶈兘瓒呰繃 2MB!")
-        } else if (files.type.indexOf("image") === -1) {
-          //濡傛灉涓嶆槸鍥剧墖鏍煎紡
-          this.$message.error("璇烽�夋嫨鍥剧墖鏂囦欢")
-        } else {
-          const that = this
-          const reader = new FileReader() // 鍒涘缓璇诲彇鏂囦欢瀵硅薄
-          reader.readAsDataURL(el.target.files[0]) // 鍙戣捣寮傛璇锋眰锛岃鍙栨枃浠�
-          reader.onload = function () {
-            // 璇诲彇瀹屾垚鍚庯紝灏嗙粨鏋滆祴鍊肩粰img鐨剆rc
-            that.imageSrc = this.result
-            console.log(this.result)
-            // 鏁版嵁浼犲埌鍚庡彴
-            //const formData = new FormData()
-            //formData.append('file', files); // 鍙互浼犲埌鍚庡彴鐨勬暟鎹�
-          }
-        }
-      }
+    getImageData(formdata) {
+      this.fileFormdata = formdata
+      // console.log(formdata, "鍥剧墖鏁版嵁")
     },
     // 杩涘嚭鐐瑰嚮
     inOutBoundClick() {
@@ -731,7 +768,7 @@
       }
     },
     // 鍦ㄥ簱鐐瑰嚮
-    inLibraryClick(){
+    inLibraryClick() {
       if (this.editConfig.title !== "鏂板缓") {
         console.log(this.editConfig.infomation)
         this.$router.push({
@@ -743,6 +780,34 @@
         })
       }
     },
+    // 涓婃灦瑙勫垯
+    listingRulesClick() {
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          this.$router.push({
+            path: "/warehouseManage/listingRules",
+            query: {
+              productName: this.editConfig.infomation.name,
+              productId: this.editConfig.title === "鏂板缓" ? "" : this.editConfig.infomation.id
+            }
+          })
+        }
+      })
+    },
+    // 閲嶈璐鍒�
+    reorderRulesClick() {
+      this.$refs.form.validate((valid) => {
+        if (valid) {
+          this.$router.push({
+            path: "/productManage/reorderRules",
+            query: {
+              productName: this.editConfig.infomation.name,
+              productId: this.editConfig.title === "鏂板缓" ? "" : this.editConfig.infomation.id
+            }
+          })
+        }
+      })
+    },
     // 鍙攢鍞�/鍙噰璐�
     checkboxChange(val, param) {
       if (val === "閲囪喘") {

--
Gitblit v1.8.0