From c4d5a6dc8561f95b1736e4a052e512a2c5322fca Mon Sep 17 00:00:00 2001
From: wwl <xchao828@163.com>
Date: 星期三, 22 一月 2025 17:08:23 +0800
Subject: [PATCH] 1

---
 src/views/system/tijian/index.vue |  185 ++++++++++++++++++++++++++++++++--------------
 1 files changed, 129 insertions(+), 56 deletions(-)

diff --git a/src/views/system/tijian/index.vue b/src/views/system/tijian/index.vue
index 9966fbe..34913f1 100644
--- a/src/views/system/tijian/index.vue
+++ b/src/views/system/tijian/index.vue
@@ -351,6 +351,8 @@
                   </el-table-column>
                   <el-table-column prop="proName" label="鏄庣粏椤圭洰" width="260px">
                   </el-table-column>
+                  <el-table-column prop="sl" label="鏁伴噺" width="56px">
+                  </el-table-column>
 
                   <el-table-column prop="proPrice" label="鍘熶环" width="56px">
                   </el-table-column>
@@ -372,12 +374,10 @@
         </el-tab-pane>
         <el-tab-pane label="鍗曢」" name="second">
           <div class="tab8">
-            <el-row :gutter="20">
-              <el-col :span="6">
+            <el-row :gutter="24">
+              <el-col :span="8">
                 <div style="
                     text-align: center;
-                    margin-bottom: 10px;
-                    margin-top: 10px;
                   ">
                   椤圭洰鍒楄〃
                 </div>
@@ -391,7 +391,7 @@
                   </el-tree>
                 </div>
               </el-col>
-              <el-col :span="6">
+              <el-col :span="8">
                 <div style="
                     text-align: center;
                     margin-bottom: 10px;
@@ -407,7 +407,7 @@
                   </el-tree>
                 </div>
               </el-col>
-              <el-col :span="11">
+              <el-col :span="8">
                 <div class="grid-content bg-purple">
                   <div style="
                       text-align: center;
@@ -1075,6 +1075,9 @@
   },
   watch: {
 
+    filterText(val) {
+      this.$refs.tree.filter(val);
+    },
     filterage(val) {
       this.$refs.treas.filter(val);
     },
@@ -1088,8 +1091,11 @@
 
     // this.getData();
   },
-  mounted() { },
-
+  mounted() {
+  this.TreedataList = [];
+  this.DataList = [];
+  this.marryall = 0;
+},
   methods: {
     debounceNumberChange(currentValue, oldValue) {
       clearTimeout(this.debounceTimer);
@@ -2227,12 +2233,15 @@
 
     // 鍙栨秷鎸夐挳
     cancel() {
-      this.Seachopen = false;
-      this.taocan = false;
-      this.malldisble = false;
-      this.defaultKeys = [];
-      this.DataLists = [];
-    },
+  this.TreedataList = [];
+  this.DataList = [];
+  this.marryall = 0; // 閲嶇疆鍚堣
+  this.Seachopen = false;
+  this.taocan = false;
+  this.malldisble = false;
+  this.defaultKeys = [];
+  this.DataLists = [];
+},
 
     cancell() {
       if (this.addAddress.address) {
@@ -2486,21 +2495,25 @@
       }
     },
     handleClick(tab, event) {
-      if (this.activeNames == "second") {
-        this.DataList = [];
-        this.checkedkey = [];
-        this.getDataList();
-      } else if (this.activeNames == "third") {
-        this.DataLists = [];
-        this.checkedkeys = [];
-        getZhList().then((response) => {
-          if (response.data) {
-            this.packageList = response.data;
-          }
-          this.loading = false;
-        });
+  if (this.activeNames == "second") {
+    this.DataList = [];
+    this.checkedkey = [];
+    this.TreedataList = []; 
+    this.marryall = 0; // 閲嶇疆鍚堣
+    this.getDataList();
+  } else if (this.activeNames == "third") {
+    this.DataLists = [];
+    this.checkedkeys = [];
+    this.TreedataList = []; 
+    this.marryall = 0; // 閲嶇疆鍚堣
+    getZhList().then((response) => {
+      if (response.data) {
+        this.packageList = response.data;
       }
-    },
+      this.loading = false;
+    });
+  }
+},
     // gaibian(val){
     //   let pname = val;
     //   getProParentIdDxList(pname).then(response=>{
@@ -2512,6 +2525,16 @@
       getProParentIdDxList().then((response) => {
         this.Treedata = response.data.list;
 
+        // 鍥炴樉 TreedataList 鍒� DataList
+        if (this.TreedataList && this.TreedataList.length > 0) {
+          this.DataList = this.TreedataList;
+          this.marryall = this.DataList.reduce((sum, item) => sum + (item.proPrice || 0) * (item.sl || 1), 0);
+          this.checkedListkey = this.DataList.map(item => item.proId);
+          this.$nextTick(() => {
+            this.$refs.tree.setCheckedKeys(this.checkedListkey);
+          });
+        }
+
         if (this.tableData[0]) {
           this.tableData[0].tjProjectList.forEach((selectionitem) => {
             this.Treedata.forEach((item) => {
@@ -2521,8 +2544,63 @@
             });
           });
         }
+
+        // 鍥炴樉 packageList 鐨勯�変腑鎬�
+        this.handlePackageSelection();
+
         this.loading = false;
       });
+    },
+
+    handlePackageSelection() {
+      // 鍋囪浣犳湁涔嬪墠淇濆瓨鐨勯�変腑鐘舵�佹垨浠庢煇涓湴鏂硅幏鍙栬繖浜涙暟鎹�
+      let selectedPackageIds = this.getPreviouslySelectedPackages(); // 杩欐槸涓�涓亣璁剧殑鍑芥暟锛屽疄闄呬娇鐢ㄦ椂鏇挎崲涓哄疄闄呯殑閫昏緫
+
+      // 璁剧疆 packageList 鐨勯�変腑鐘舵��
+      this.$nextTick(() => {
+        if (this.$refs.treas) { // 纭繚 treas 寮曠敤宸茬粡瀛樺湪
+          this.$refs.treas.setCheckedKeys(selectedPackageIds, true);
+        }
+        // 鏇存柊 checkedkeys 浠ュ弽鏄犲綋鍓嶉�変腑鐨勫寘
+        this.checkedkeys = selectedPackageIds;
+      });
+
+      // 鏍规嵁閫変腑鐘舵�佹洿鏂� DataLists 鎴栧叾浠栭渶瑕佹洿鏂扮殑鍐呭
+      this.updateDataListsBasedOnSelection(selectedPackageIds);
+    },
+
+    getPreviouslySelectedPackages() {
+      // 杩斿洖涔嬪墠淇濆瓨鐨勯�変腑鍖匢D鏁扮粍
+      // 渚嬪锛屼粠 localStorage 鎴栬�� Vuex store 鑾峰彇
+      return []; // 杩欓噷鏄ず渚嬶紝鏇挎崲涓哄疄闄呰幏鍙栨暟鎹殑閫昏緫
+    },
+
+    updateDataListsBasedOnSelection(selectedPackageIds) {
+      // 鏍规嵁閫変腑鐨勫寘ID鏇存柊 DataLists
+      this.DataLists = [];
+      selectedPackageIds.forEach(id => {
+        let packageItem = this.packageList.find(item => item.id === id);
+        if (packageItem) {
+          // 杩欓噷鍋囪姣忎釜鍖呴」鐩兘鏈変竴涓� proId 鏁扮粍鎴栬�呯被浼肩殑缁撴瀯锛岀敤鏉ヨ幏鍙栧寘涓殑椤圭洰
+          if (packageItem.proIds) { // 鍋囪 packageItem 鍖呭惈涓�涓� proId 鏁扮粍
+            packageItem.proIds.forEach(proId => {
+              let project = this.findProjectById(proId); // 鍋囪鏈変竴涓嚱鏁版潵鎵惧埌椤圭洰
+              if (project) {
+                this.DataLists.push(project);
+              }
+            });
+          }
+        }
+      });
+
+      // 璁$畻鍚堣
+      this.marryalls = this.DataLists.reduce((sum, item) => sum + item.proPrice, 0);
+    },
+
+    findProjectById(proId) {
+      // 姝ゅ嚱鏁板亣璁句綘鏈変竴涓叏灞�鐨勯」鐩垪琛ㄦ垨鑰呭彲浠ヤ粠鏌愪釜API鑾峰彇
+      // 杩欓噷鍙槸涓�涓ず渚嬶紝瀹為檯搴旂敤涓簲璇ユ牴鎹綘鐨勬暟鎹粨鏋勬潵瀹炵幇
+      return this.allpackageList.find(item => item.proId === proId) || null;
     },
 
     handlepackage(data, checked, checkedNodes) {
@@ -2552,7 +2630,7 @@
                 if (this.DataLists.length >= 1) {
                   this.marryalls = 0;
                   this.DataLists.forEach((item1) => {
-                    this.marryalls += item1.proPrice;
+                    this.marryalls += item1.proPrice * item1.sl;
 
                     this.packagedataList.forEach((item3) => {
                       if (item1.proParentId == item3.proId) {
@@ -2626,30 +2704,36 @@
         });
       }
     },
-    // 鐐瑰嚮鑾峰彇姣忎釜鏍戣妭鐐�
     handleCurrentChecked(data, checked, checkedNodes) {
       this.dataObj = data;
-      if (checked.checkedNodes.length != 0) {
-        let proId = data.proId;
-        getProSonDxList(proId).then((res) => {
-          this.TreedataList = res.data.list;
+      if (checked.checkedNodes.length > 0) {
+        const promises = checked.checkedNodes.map(node => getProSonDxList(node.proId));
+        Promise.all(promises).then(results => {
+          this.TreedataList = results.flatMap(res => res.data.list);
+          this.checkedListkey = [];
+          this.DataList = [];
+
           this.TreedataList.forEach((item) => {
             this.checkedListkey.push(item.proId);
-
             this.DataList.push(item);
-            this.spliceData();
-            this.DataList.forEach((item1) => {
-              if (item1.proParentId == data.proId) {
-                item1.propinName = data.proName;
-              }
-            });
           });
+
+          this.spliceData(); // 鍋囪杩欎釜鏂规硶鏄綘瀹氫箟鐨勫叾浠栧湴鏂瑰鐞嗘暟鎹殑
+
+          // 鏇存柊鍚嶇О鍜岃绠楁�讳环
+          this.DataList.forEach((item1) => {
+            const parent = checked.checkedNodes.find(node => node.proId === item1.proParentId);
+            if (parent) {
+              item1.propinName = parent.proName;
+            }
+          });
+
           this.TotalPrice1 = 0;
           this.marryall = 0;
           if (this.DataList.length != 0) {
             this.list1 = false;
             this.DataList.forEach((item) => {
-              this.marryall = item.proPrice * item.sl;
+              this.marryall += Number(item.proPrice) * Number(item.sl);
             });
           }
         });
@@ -2830,13 +2914,11 @@
       this.DataLists = [];
     },
 
+    // 澶勭悊璁㈠崟椤圭洰
     processOrderItems(cusId) {
       getTransitionList1(cusId).then((response) => {
         this.tableData1 = response.data;
         if (this.tableData1) {
-          let totalOrdPrice = new Big(0);
-          let totalNowPrice = new Big(0);
-
           this.tableData1.forEach((item) => {
             if (item.tjCategory != null) {
               this.tjCategory = item.tjCategory;
@@ -2846,18 +2928,9 @@
                 this.treeList.push(item9.proId);
               });
             }
-            // 浣跨敤Big.js杩涜鍔犳硶浠ラ伩鍏嶇簿搴︿涪澶�
-            totalOrdPrice = totalOrdPrice.plus(new Big(item.ordPrice || 0));
-            totalNowPrice = totalNowPrice.plus(new Big(item.nowPrice || 0));
+            this.TotalPrice1 += item.ordPrice || 0; // 绱姞搴旀敹閲戦
+            this.TotalPrice += item.nowPrice || 0; // 绱姞瀹炴敹閲戦
           });
-
-          // 灏咮ig鏁拌浆鎹㈠洖鏁板�煎苟淇濈暀涓や綅灏忔暟
-          this.TotalPrice1 = totalOrdPrice.toNumber().toFixed(2);
-          this.TotalPrice = totalNowPrice.toNumber().toFixed(2);
-
-          // 纭繚TotalPrice鏄竴涓瓧绗︿覆锛岄槻姝㈠悗缁搷浣滃鑷寸簿搴︿涪澶�
-          this.TotalPrice = this.TotalPrice.toString();
-
           // 璁$畻鎶樻墸
           this.discount = this.TotalPrice1 > 0 ?
             (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) / 100) * 10 : 0;

--
Gitblit v1.8.0