From dbab45ef6e56c32ca3b2d286ec5cb7ed0c86bfea Mon Sep 17 00:00:00 2001
From: charles <981744753@qq.com>
Date: 星期四, 18 七月 2024 21:57:21 +0800
Subject: [PATCH] feat:实现crm与aps共用token

---
 src/views/sales/salesOpportunity/AddSalesOpportunityDialog.vue |   83 +++++++++++++++++++++++++++++++----------
 1 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/src/views/sales/salesOpportunity/AddSalesOpportunityDialog.vue b/src/views/sales/salesOpportunity/AddSalesOpportunityDialog.vue
index cd7970b..31c73aa 100644
--- a/src/views/sales/salesOpportunity/AddSalesOpportunityDialog.vue
+++ b/src/views/sales/salesOpportunity/AddSalesOpportunityDialog.vue
@@ -327,9 +327,11 @@
           <div class="product-view">
             <CommonFormTableView
               :show-summary="showSummary"
+              :addTypeIdMultiple="true"
               :product-table-list="productTableList"
               @inputContent="inputContent"
               @addProductClick="addProductClick"
+              @getSelectArray="getSelectArray"
               @emptyProductClick="emptyProductClick"
               @recalculateProductClick="recalculateProductClick"
               @clearupProduct="clearupProduct"
@@ -649,7 +651,7 @@
         number: [{ required: true, validator: this.validateCheckCode, trigger: ["blur", "change"] }],
         name: [{ required: true, message: "璇疯緭鍏ユ満浼氬悕绉�", trigger: "blur" }],
 
-        member_id: [{ required: true, message: "璇烽�夋嫨閿�鍞礋璐d汉", trigger: "change" }],
+        member_id: [{ required: true, validator: this.validateMemberId, trigger: "change" }],
         sale_stage_id: [{ required: true, message: "璇烽�夋嫨閿�鍞樁娈�", trigger: "change" }],
         currency: [{ required: true, message: "璇烽�夋嫨甯佺", trigger: "change" }],
         expected_time: [{ required: true, message: "璇烽�夋嫨棰勮鎴愪氦鏃ユ湡", trigger: "change" }],
@@ -732,6 +734,14 @@
       getAllData()
         .then((res) => {
           this.memberOptions = res.data.member
+          if (this.editConfig.title === "鏂板缓") {
+            let username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1")
+            this.memberOptions.map((item) => {
+              if (item.username == username) {
+                this.$set(this.editConfig.infomation, "member_id", item.id)
+              }
+            })
+          }
           this.businessSourceOptions = res.data.sales_source
           this.businessTypeOptions = res.data.sale_type
           this.oldCustomerMarketOptions = res.data.regular_customers
@@ -757,11 +767,11 @@
     saveClick(formName) {
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          const hasProduct = this.tableData.every((ele) => !!ele.name)
-          if (!hasProduct) {
-            this.$message.error("浜у搧鍚嶇О涓嶈兘涓虹┖")
-            return
-          }
+          // const hasProduct = this.tableData.every((ele) => !!ele.name)
+          // if (!hasProduct) {
+          //   this.$message.error("浜у搧鍚嶇О涓嶈兘涓虹┖")
+          //   return
+          // }
 
           const params = this.saveParams()
           console.log(params)
@@ -800,6 +810,12 @@
     },
     saveParams() {
       let data = this.editConfig.infomation
+      let products = []
+      this.tableData.map((item) => {
+        if (item.number.length > 0) {
+          products.push(item)
+        }
+      })
       let params = {
         id: this.editConfig.title === "鏂板缓" ? 0 : data.id,
         advantages: data.advantages || "",
@@ -837,7 +853,7 @@
         detail_address: data.detail_address || "",
 
         codeStandID: data.ID,
-        products: this.tableData
+        products: products
       }
       return params
     },
@@ -971,8 +987,9 @@
       }
       this.productTableList = {
         tableData: this.tableData,
+        isReturn: true,
         tableColumn: [
-          { label: "#", prop: "productId", width: 40 },
+          // { label: "#", prop: "productId", width: 40 },
           { label: "浜у搧鍚嶇О", prop: "name", productName: true, isRequird: true },
           { label: "浜у搧缂栧彿", prop: "number" },
           { label: "鏁伴噺", prop: "amount", inputNumber: true, isRequird: true },
@@ -983,26 +1000,42 @@
     },
     // 浜у搧鍒楄〃杈撳叆
     inputContent(val, prop, row) {
-      this.productId = row.productId
+      // this.productId = row.productId
       this.tableData.map((item) => {
-        if (item.productId === row.productId) {
+        if (item.number === row.number) {
           item[prop] = val
         }
       })
     },
     // 浜у搧鏂板
     addProductClick() {
-      this.productId++
-      this.tableData.push({
-        productId: this.productId,
-        id: 0,
-        amount: 0,
-        desc: "",
-        name: "",
-        number: "",
-        price: 0,
-        total: 0
-      })
+      // this.productId++
+      // this.tableData.push({
+      //   productId: this.productId,
+      //   id: 0,
+      //   amount: 0,
+      //   desc: "",
+      //   name: "",
+      //   number: "",
+      //   price: 0,
+      //   total: 0
+      // })
+      // this.showSummary.show = true
+    },
+    // 鏂板鏂瑰紡淇敼
+    getSelectArray(val, index) {
+      if (this.tableData.length == 1 && this.tableData[0].number.length == 0) {
+        this.tableData = []
+      }
+      if (index < this.tableData.length) {
+        this.tableData.splice(index, 1)
+        val.map((item, ind) => {
+          this.tableData.splice(index + ind, 0, item)
+        })
+      } else {
+        this.tableData = this.tableData.concat(val)
+      }
+      this.productTableList.tableData = this.tableData
       this.showSummary.show = true
     },
     //  浜у搧娓呯┖
@@ -1027,6 +1060,14 @@
     clearupProduct(data) {
       this.tableData = data
       this.productTableList.tableData = this.tableData
+    },
+    // 閿�鍞礋璐d汉鑷畾涔夋牎楠岃鍒�
+    validateMemberId(rule, value, callback) {
+      if (this.editConfig.infomation?.member_id > 0) {
+        callback()
+      } else {
+        callback(new Error("璇烽�夋嫨閿�鍞礋璐d汉"))
+      }
     }
   }
 }

--
Gitblit v1.8.0