From d0aaaeda4b5e7aaed8067637baaea0e74e7993e6 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期四, 26 十月 2023 17:13:14 +0800
Subject: [PATCH] 环境配置

---
 src/views/productManage/product/AddProductDialog.vue |   52 +++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/src/views/productManage/product/AddProductDialog.vue b/src/views/productManage/product/AddProductDialog.vue
index a1d1117..e24ecd2 100644
--- a/src/views/productManage/product/AddProductDialog.vue
+++ b/src/views/productManage/product/AddProductDialog.vue
@@ -165,7 +165,7 @@
                       :disabled="!showFooter"
                     >
                       <el-option
-                        v-for="item in productCategoryListWithDefault"
+                        v-for="item in productCategoryOptions"
                         :key="item.id"
                         :label="item.name"
                         :value="item.id"
@@ -475,23 +475,20 @@
           visible: false,
           title: "鏂板缓",
           infomation: {},
-          autoEdit:false
+          autoEdit: false
         }
       }
     }
   },
   components: {},
   computed: {
-    productCategoryListWithDefault(){
-      return [{id:0,name:'璇烽�夋嫨'},...(this.productCategoryOptions ?? [])]
-    },
-    modalTitle(){
-      if (this.editConfig.title === '缂栬緫' && this.editConfig.autoEdit){
-        return '缂栬緫'
-      }else if (this.editConfig.title === '缂栬緫') {
-        return !this.showEdit ? '缂栬緫' : '鏌ョ湅'
-      }else {
-        return '鏂板缓'
+    modalTitle() {
+      if (this.editConfig.title === "缂栬緫" && this.editConfig.autoEdit) {
+        return "缂栬緫"
+      } else if (this.editConfig.title === "缂栬緫") {
+        return !this.showEdit ? "缂栬緫" : "鏌ョ湅"
+      } else {
+        return "鏂板缓"
       }
     }
   },
@@ -502,13 +499,12 @@
       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 }],
       productCategoryOptions: [], // 浜у搧绫诲埆
       productTypeOptions: [
-        { name: "璇烽�夋嫨", id: 0 },
         { name: "鑳芥秷鑰�", id: 1 },
         { name: "鏈嶅姟", id: 2 },
         { name: "鍙簱瀛樹骇鍝�", id: 3 }
@@ -553,11 +549,32 @@
     this.setTableForm()
     this.setBottonView()
     this.statisticsMap.inLibrary = this.editConfig?.infomation?.amount ?? 0
-    if (this.editConfig.autoEdit){
+    if (this.editConfig.autoEdit) {
       this.editClick()
     }
+    this.setOptionalFieldsToEmpty()
   },
   methods: {
+    /**
+     * 闈炲繀濉」鍚庣杩斿洖鐨勬槸鏁板瓧 0,琛ㄥ崟闇�瑕佺┖涓叉墠鑳借涓烘湭閫夋嫨鍥炴樉
+     */
+    setOptionalFieldsToEmpty(){
+      ['productType','categoryId']
+          .filter(filed => this.editConfig.infomation[filed] === 0)
+          .forEach(filed => {
+            this.editConfig.infomation[filed] = ''
+          })
+    },
+    /**
+     * 鍚庣鍙帴鍙楁暟瀛楀舰寮�, 淇濆瓨鏃惰繕寰楀啀杞洖鍘�
+     */
+    unsetFieldsToNumber(){
+      ['productType','categoryId']
+          .filter(filed => this.editConfig.infomation[filed] === '')
+          .forEach(filed => {
+            this.editConfig.infomation[filed] = 0
+          })
+    },
     // 鑾峰彇浜у搧绫诲埆
     async getProductCategoryList() {
       await getProductCategoryList({
@@ -618,6 +635,7 @@
       this.$refs[formName].validate((valid) => {
         if (valid) {
           let requestUrl = this.editConfig.title === "鏂板缓" ? addProduct : updateProduct
+          this.unsetFieldsToNumber()
           requestUrl({
             ...this.editConfig.infomation
           }).then((res) => {
@@ -627,7 +645,7 @@
               this.$message.success("娣诲姞鎴愬姛")
               this.$parent.getData()
             }
-          })
+          },console.error)
         }
       })
     },
@@ -749,7 +767,7 @@
       }
     },
     // 鍦ㄥ簱鐐瑰嚮
-    inLibraryClick(){
+    inLibraryClick() {
       if (this.editConfig.title !== "鏂板缓") {
         console.log(this.editConfig.infomation)
         this.$router.push({

--
Gitblit v1.8.0