From c36ada6253862acaa44a1dc0eb5b9cbb28e68fd8 Mon Sep 17 00:00:00 2001
From: wwl <xchao828@163.com>
Date: 星期二, 21 一月 2025 11:08:41 +0800
Subject: [PATCH] 1

---
 src/views/system/tijian/index.vue |  379 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 243 insertions(+), 136 deletions(-)

diff --git a/src/views/system/tijian/index.vue b/src/views/system/tijian/index.vue
index 7ab21ed..bbea675 100644
--- a/src/views/system/tijian/index.vue
+++ b/src/views/system/tijian/index.vue
@@ -206,10 +206,6 @@
                   :value="dict.value"></el-option>
               </el-select>
             </el-form-item>
-
-            <!-- <el-form-item prop="ageUnit">
-              
-              </el-form-item> -->
           </el-form>
           <el-form :inline="true" ref="form" :model="form" :rules="rules" :label-position="labelPosition"
             label-width="106px" v-show="top">
@@ -355,6 +351,7 @@
                   </el-table-column>
                   <el-table-column prop="proName" label="鏄庣粏椤圭洰" width="260px">
                   </el-table-column>
+
                   <el-table-column prop="proPrice" label="鍘熶环" width="56px">
                   </el-table-column>
 
@@ -421,6 +418,8 @@
                   </div>
                   <el-table :data="DataList" border style="width: 100%" height="400" :span-method="objectSpanMethod">
                     <el-table-column prop="propinName" label="妫�鏌ラ」鐩�">
+                    </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>
                     <el-table-column prop="proName" label="鏄庣粏椤圭洰" width="260px">
@@ -492,13 +491,14 @@
               <el-form-item label="搴旀敹閲戦">
                 <el-input placeholder="搴旀敹閲戦" v-model="TotalPrice1" disabled style="width: 150px"></el-input>
               </el-form-item>
-              <el-form-item label="浼樻儬">
+              <el-form-item label="鎶樻墸">
                 <!-- {{ discount }} -->
                 <el-input-number ref="inputNumber" style="width: 150px" v-model="discount" :precision="1" :step="0.1"
-                  :max="10" :min="0" @change="numberChange" :disabled="isfalse"></el-input-number>
+                  :max="10" :min="0" @change="debounceNumberChange" :disabled="isfalse"></el-input-number>
               </el-form-item>
               <el-form-item label="瀹炴敹閲戦">
-                <el-input placeholder="瀹炴敹閲戦" v-model="TotalPrice" style="width: 206px"></el-input>
+                <el-input placeholder="瀹炴敹閲戦" v-model="TotalPrice" style="width: 206px" @input="changeXianjia"
+                  @blur="numberChangeXianPrice(discount, discount)" />
               </el-form-item>
               <br />
 
@@ -581,7 +581,8 @@
                 <template slot-scope="scope">
                   <!-- 鍙緭鍏ョ函鏁板瓧鎶樻墸 -->
                   <el-input-number v-model.number="scope.row.discount" @input="validateDiscount(scope.row)"
-                    placeholder="杈撳叆鎶樻墸" size="small" type="number" :precision="1" :step="0.1" :max="10" :min="0">
+                    @change="handleManualChange(scope.row)" placeholder="杈撳叆鎶樻墸" size="small" type="number" :precision="1"
+                    :step="0.1" :max="10" :min="0">
                   </el-input-number>
                 </template>
               </el-table-column>
@@ -654,7 +655,7 @@
               </el-form-item>
               <el-form-item label="浼樻儬">
                 <el-input-number style="width: 140px" v-model="discount" :precision="1" :step="0.1" :max="10" :min="0"
-                  @change="numberChange" :disabled="isfalse"></el-input-number>
+                  @change="debounceNumberChange" :disabled="isfalse"></el-input-number>
               </el-form-item>
               <el-form-item label="瀹炴敹閲戦">
                 <el-input v-model="formInline.paidIn" placeholder="瀹炰粯" style="width: 94px">
@@ -804,6 +805,7 @@
   },
   data() {
     return {
+      isSubmitting: false,
       open1: false,
       filterage: "",
       checkedkeys: [],
@@ -865,7 +867,6 @@
       taocan: false,
       top: true,
       value: "2",
-      getInfodis: "",
       srcUrl: "",
       hides: false,
       hide: true,
@@ -1005,7 +1006,7 @@
         cusIsvip: null,
       },
       // 娣诲姞
-
+      lastXianPrice: 0,
       // 琛ㄥ崟鍙傛暟
       // 琛ㄥ崟鍙傛暟
       obj: {},
@@ -1021,7 +1022,27 @@
         firmId: "",
         firmDeptName: "",
       },
-      form1: {},
+      form1: {
+        cnName: "",
+        contactPerson: "",
+        contactPhone: "",
+        taxNumber: "",
+        legalPerson: "",
+        registerAddress: "",
+        mailingAddress: "",
+        bankAccount: "",
+        mailingAddress: "",
+        countNum: "",
+        bankAccount: "",
+        email: "",
+        principal: "",
+        url: "",
+        faxNumber: "",
+        areaName: "",
+        orderNum: "",
+        remark: "",
+        validTime: "",
+      },
       title: "",
       // 琛ㄥ崟鏍¢獙
       rules: {
@@ -1072,7 +1093,19 @@
   mounted() { },
 
   methods: {
-
+    debounceNumberChange(currentValue, oldValue) {
+      clearTimeout(this.debounceTimer);
+      this.debounceTimer = setTimeout(() => {
+        this.numberChange(currentValue, oldValue);
+      }, 300);
+    },
+    changeXianjia() {
+      // 鍘熷鎶樻墸鐜囪绠�
+      if (this.TotalPrice1 !== 0) {
+        this.discount =
+          (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) / 100) * 10;
+      }
+    },
     clear() {
       this.form.firmId = "";
     },
@@ -1108,14 +1141,17 @@
         })
         .catch(() => { });
     },
-    validateDiscount(row) {
-      if (row.discount > 10) {
-        row.discount = 10; // 寮哄埗灏嗗�艰缃负鏈�澶у��
-      } else if (row.discount < 0) {
-        row.discount = 0; // 寮哄埗灏嗗�艰缃负鏈�灏忓��
-      }
-      this.updateProPrice(row); // 鏇存柊浠锋牸鎴栧叾浠栭�昏緫
+    handleManualChange(row) {
+      console.log("杩欐槸涓诲姩鍑哄彂鐨�");
+      this.updateProPrice(row);
     },
+    validateDiscount(row) {
+      if (this.TotalPrice !== undefined && !isNaN(this.TotalPrice) && this.TotalPrice !== this.lastXianPrice) {
+        this.updateProPrice1(row);
+        this.lastXianPrice = this.TotalPrice;
+      }
+    },
+
     isAll(value) {
       return value === "" || value === null;
     },
@@ -1132,7 +1168,33 @@
       this.discount =
         (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) / 100) * 10;
     },
+    updateProPrice1(row) {
+      console.log("杩涘叆浜�1")
+      const ordPrice = new Big(row.ordPrice);
+      const discount = new Big(row.discount);
+      const result = ordPrice.times(discount.div(10));
+      row.nowPrice = result.toNumber();
+      const totalYsPrice = this.tableData1.reduce((sum, item) => {
+        return sum.plus(new Big(item.nowPrice || '0'));
+      }, new Big(0));
+      const totalYsPriceNum = totalYsPrice.toNumber();
+      if (this.TotalPrice !== undefined && !isNaN(this.TotalPrice)) {
+        const xianPrice = new Big(this.TotalPrice);
+        const diff = xianPrice.minus(totalYsPriceNum);
+        if (!diff.eq(0) && this.tableData1.length > 0) {
+          const lastItem = this.tableData1[this.tableData1.length - 1];
+          const newYsPrice = new Big(lastItem.nowPrice).plus(diff).toNumber();
+          this.$set(this.tableData1[this.tableData1.length - 1], 'nowPrice', newYsPrice);
+        }
+      }
 
+      // Update youhui calculation
+      if (this.TotalPrice1 !== 0 && this.TotalPrice !== 0) {
+        this.discount = (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) / 100) * 10;
+      } else {
+        this.discount = 0;
+      }
+    },
     openname() {
       this.$refs.bbb.open = true;
       this.$refs.bbb.title = "鎼滅储濮撳悕";
@@ -1256,11 +1318,9 @@
     },
     getList1() {
       getInfo().then((response) => {
-        this.getInfodis = response.user.discount;
+
         this.hospName = response.hospName;
-        if (this.getInfodis === null) {
-          this.isfalse = true;
-        }
+
       });
       getIsRequired().then((response) => {
         this.showHidden = response.data;
@@ -1474,7 +1534,6 @@
       });
     },
 
-
     handleClose(done) {
       this.$confirm("纭鍏抽棴锛�")
         .then((_) => {
@@ -1486,10 +1545,8 @@
     /** 鏌ヨ淇℃伅鍒楄〃 */
     getList() {
       getInfo().then((response) => {
-        this.getInfodis = response.user.discount;
-        if (this.getInfodis === null) {
-          this.isfalse = true;
-        }
+
+
       });
       let cusSex = this.form.cusSex;
       //鍏ㄩ儴濂楅
@@ -1573,15 +1630,12 @@
       })
         .then(() => {
           this.discount = currentValue;
-          if (this.discount < this.getInfodis) {
-            this.discount = this.getInfodis;
-            // this.$modal.msgError(`璇ヤ汉鍛樻渶楂樹紭鎯犳潈闄愪负${this.getInfodis}鎶榒);
-          }
+
           this.tableData1.forEach((item) => {
             item.discount = this.discount;
             const ordPrice = new Big(item.ordPrice);
             const discount = new Big(item.discount);
-            const result = ordPrice.times(discount.div(10))
+            const result = ordPrice.times(discount.div(10));
             item.nowPrice = result.toNumber();
             this.TotalPrice = this.tableData1.reduce((sum, item) => {
               return sum.plus(new Big(item.nowPrice || "0"));
@@ -1592,7 +1646,50 @@
           this.discount = oldValue;
         });
     },
-
+    numberChangeXianPrice(currentValue, oldValue) {
+      this.$confirm("纭畾淇敼鎵�鏈夊瓙椤圭殑鎶樻墸鍚楋紵", "鎻愮ず", {
+        confirmButtonText: "纭畾",
+        cancelButtonText: "鍙栨秷",
+        type: "warning",
+      })
+        .then(() => {
+          this.discount = currentValue;
+          if (this.discount < this.getInfodis) {
+            this.discount = this.getInfodis;
+          }
+          let totalYsprice = new Big(0);
+          this.tableData1.forEach((item) => {
+            item.discount = this.discount;
+            const ordPrice = new Big(item.ordPrice);
+            const discount = new Big(item.discount);
+            const result = ordPrice.times(discount.div(10));
+            item.nowPrice = result.toNumber();
+            totalYsprice = totalYsprice.plus(new Big(item.nowPrice));
+          });
+          if (!totalYsprice.eq(this.TotalPrice)) {
+            const diff = new Big(this.TotalPrice).minus(totalYsprice);
+            if (this.tableData1.length > 0) {
+              const lastItem = this.tableData1[this.tableData1.length - 1];
+              const newYsPrice = new Big(lastItem.nowPrice)
+                .plus(diff)
+                .toNumber();
+              console.log(
+                "hhh",
+                this.tableData1[this.tableData1.length - 1].nowPrice,
+                newYsPrice
+              );
+              this.$set(
+                this.tableData1[this.tableData1.length - 1],
+                "nowPrice",
+                newYsPrice
+              );
+            }
+          }
+        })
+        .catch(() => {
+          this.discount = oldValue;
+        });
+    },
     /** 鐧昏鎻愪氦鎸夐挳 */
     submitForm() {
       let _this = this;
@@ -1641,6 +1738,7 @@
       let cusIdcard = this.form.cusIdcard;
       if (cusIdcard) {
         getCusIdcard(cusIdcard).then((response) => {
+          _this.top = false;
           if (response.data) {
             this.form = response.data;
             if (this.form.discount === null) {
@@ -1681,11 +1779,11 @@
                     this.list1 = false;
                     this.list2 = true;
                     this.list3 = false;
-                    this.top = false;
+                    _this.top = false;
                   } else {
                     this.list1 = true;
                     this.TotalPrice = 0;
-                    this.top = false;
+                    _this.top = false;
                   }
                 });
               } else {
@@ -1733,7 +1831,7 @@
         });
       } else {
         let configKey = "getInfoFromSqlData";
-        getconfigKey(configKey).then((res) => {
+        getconfigKey(configKey).then((res) => {  
           if (res.code == 200) {
             if (res.msg == "N") {
               var websocket = null;
@@ -1781,9 +1879,10 @@
                 alert("璇诲崱鍣ㄨ繛鎺ュ叧闂�");
               };
             } else if (res.msg == "Y") {
-              this.$refs.aaa.open = true;
+              /* this.$refs.aaa.open = true;
               this.$refs.aaa.getAllList();
-              this.$refs.aaa.title = "璇佷欢瀛楀吀";
+              this.$refs.aaa.title = "璇佷欢瀛楀吀"; */
+              
             } else if (res.msg == "S") {
               this.cardreader = true;
               _this.cardreaderradio = 3;
@@ -2168,7 +2267,6 @@
       }
     },
 
-
     resetpackage() {
       this.discount = 10;
       if (this.form.cusIdcard) {
@@ -2180,6 +2278,13 @@
       _this.pacId = "";
       this.proIds = [];
       this.tjCategory = "12";
+
+      this.DataList = []; // 娓呯┖宸查�夐」鐩垪琛�
+      this.checkedkey = []; // 娓呯┖鏍戠殑閫変腑鐘舵��
+      this.checkedListkey = [];
+      this.TreedataList = [];
+      this.$refs.tree.setCheckedKeys([]); // 閲嶇疆鏍戦�変腑鐘舵��
+
       let data = {
         cusId,
         pacId: _this.pacId,
@@ -2216,12 +2321,37 @@
         dwId: this.form.firmId || "",
       };
       if (this.form.tjType == 1) {
-        if (!this.form.firmId) {
+        if (!this.form.firmId && !this.form.firmName) {
           this.$message({
             type: "warning",
             message: "璇峰厛缁存姢鍗曚綅锛�",
           });
-        } else {
+        } else if (!this.form.firmId && this.form.firmName) {
+          this.taocan = true;
+          this.loading = true;
+          deptTreeSelect(cusSex).then((response) => {
+            this.newpacName = response.rows;
+            try {
+              if (this.tableData1.length >= 1) {
+                this.newpacName.forEach((item3) => {
+                  this.tableData1.forEach((item4) => {
+                    item4.list.forEach((item6) => {
+                      if (item6.pacName === item3.pacName) {
+                        this.$nextTick(() => {
+                          this.$refs.tb.toggleRowSelection(item3, true);
+                        });
+                        throw Error();
+                      }
+                    });
+                  });
+                });
+              }
+            } catch (error) { }
+            this.loading = false;
+          });
+        }
+
+        else {
           this.taocan = true;
           this.loading = true;
           tuantiSelect(param).then((res) => {
@@ -2519,7 +2649,7 @@
           if (this.DataList.length != 0) {
             this.list1 = false;
             this.DataList.forEach((item) => {
-              this.marryall += item.proPrice;
+              this.marryall = item.proPrice * item.sl;
             });
           }
         });
@@ -2637,123 +2767,104 @@
         var cusId = this.form.cusIdcard;
       } else {
         this.$message.warning("璇峰厛濉啓淇℃伅锛屽啀閫変綋妫�鍐呭");
+        return; // 濡傛灉娌℃湁韬唤璇佸彿鐮侊紝鍋滄鎵ц
       }
+
       let _this = this;
+
+      // 鍒濆鍖栧彉閲�
+      this.isSubmitting = true; // 寮�濮嬫彁浜ゆ椂璁剧疆鏍囧織
+      this.TotalPrice1 = 0; // 鍒濆鍖栧簲鏀堕噾棰�
+      this.TotalPrice = 0; // 鍒濆鍖栧疄鏀堕噾棰�
+      this.discount = 10; // 鍒濆鍖栨姌鎵d负10锛�100%锛�
+
+      // 鍒ゆ柇鏄惁鏈夐�変腑鐨勫椁�
       if (this.tableData.length != 0) {
-        this.tableData.forEach((item) => {
-          _this.pacId = item.pacId;
-        });
+        _this.pacId = this.tableData[0].pacId;
       } else {
         _this.pacId = "";
       }
+
       this.proIds = [];
-      if (this.DataList.length != 0) {
-        this.DataList.forEach((item) => {
+
+      // 澶勭悊閫変腑鐨勯」鐩�
+      const newItemsToAdd = [];
+      const allItems = [...this.DataList, ...this.DataLists]; // 鍚堝苟鎵�鏈夐」鐩�
+
+      allItems.forEach((item) => {
+        if (!this.proIds.includes(item.proId)) {
+          newItemsToAdd.push(item);
           this.proIds.push(item.proId);
-        });
-      }
-      if (this.DataLists.length != 0) {
-        this.DataLists.forEach((item) => {
-          this.proIds.push(item.proId);
-        });
-      }
+        }
+      });
+
+      // 鍑嗗鏁版嵁
       let data = {
         cusId,
         pacId: _this.pacId,
         proIds: this.proIds,
       };
+
+      // 鏍规嵁浣撴绫诲瀷閫夋嫨涓嶅悓鐨勫鐞嗘柟娉�
       if (this.form.tjType == 1) {
         tuantiqueren(data).then((response) => {
           if (response.code == 200) {
-            let cusId = this.form.cusIdcard;
-            this.proIds = [];
-            getTransitionList1(cusId).then((response) => {
-              this.tableData1 = response.data;
-              this.TotalPrice1 = 0;
-              if (this.tableData1) {
-                this.tableData1.forEach((item) => {
-                  if (item.tjCategory != null) {
-                    this.tjCategory = item.tjCategory;
-                  }
-                  if (item.pacName == "鍗曢」") {
-                    item.list.forEach((item9) => {
-                      this.treeList.push(item9.proId);
-                    });
-                  }
-                  this.TotalPrice = 0;
-                  this.TotalPrice1 += item.ordPrice;
-                  this.TotalPrice += item.nowPrice;
-
-                  this.pacName = item.pacName;
-                });
-
-                this.TotalPrice = this.tableData1.reduce((sum, item) => {
-                  return sum.plus(new Big(item.nowPrice || "0"));
-                }, new Big(0));
-                this.discount =
-                  (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) /
-                    100) *
-                  10;
-                this.list1 = false;
-                this.list3 = true;
-                this.list2 = false;
-              } else {
-                this.list1 = true;
-                this.TotalPrice = 0;
-              }
-            });
-          } else {
+            this.processOrderItems(cusId);
           }
+          this.isSubmitting = false; // 鎻愪氦瀹屾垚鍚庨噸缃爣蹇�
+        }).catch(() => {
+          this.isSubmitting = false; // 纭繚鍦ㄩ敊璇儏鍐典笅涔熼噸缃爣蹇�
         });
       } else {
         getaddtTransition(data).then((response) => {
           if (response.code == 200) {
-            let cusId = this.form.cusIdcard;
-            this.proIds = [];
-            getTransitionList1(cusId).then((response) => {
-              this.tableData1 = response.data;
-              this.TotalPrice1 = 0;
-              if (this.tableData1) {
-                this.tableData1.forEach((item) => {
-                  if (item.tjCategory != null) {
-                    this.tjCategory = item.tjCategory;
-                  }
-                  if (item.pacName == "鍗曢」") {
-                    item.list.forEach((item9) => {
-                      this.treeList.push(item9.proId);
-                    });
-                  }
-                  this.TotalPrice = 0;
-                  this.TotalPrice1 += item.ordPrice;
-                  this.TotalPrice += item.nowPrice;
-
-                  this.pacName = item.pacName;
-                });
-                this.discount =
-                  (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) /
-                    100) *
-                  10;
-
-                this.list1 = false;
-                this.list3 = true;
-                this.list2 = false;
-              } else {
-                this.list1 = true;
-                this.TotalPrice = 0;
-              }
-            });
-          } else {
+            this.processOrderItems(cusId);
           }
+          this.isSubmitting = false; // 鎻愪氦瀹屾垚鍚庨噸缃爣蹇�
+        }).catch(() => {
+          this.isSubmitting = false; // 纭繚鍦ㄩ敊璇儏鍐典笅涔熼噸缃爣蹇�
         });
       }
+
       this.taocan = false;
       this.defaultKeys = [];
       this.DataLists = [];
     },
+
+    // 澶勭悊璁㈠崟椤圭洰
+    processOrderItems(cusId) {
+      getTransitionList1(cusId).then((response) => {
+        this.tableData1 = response.data;
+        if (this.tableData1) {
+          this.tableData1.forEach((item) => {
+            if (item.tjCategory != null) {
+              this.tjCategory = item.tjCategory;
+            }
+            if (item.pacName == "鍗曢」") {
+              item.list.forEach((item9) => {
+                this.treeList.push(item9.proId);
+              });
+            }
+            this.TotalPrice1 += item.ordPrice || 0; // 绱姞搴旀敹閲戦
+            this.TotalPrice += item.nowPrice || 0; // 绱姞瀹炴敹閲戦
+          });
+          // 璁$畻鎶樻墸
+          this.discount = this.TotalPrice1 > 0 ?
+            (Math.floor((this.TotalPrice / this.TotalPrice1) * 100) / 100) * 10 : 0;
+
+          this.list1 = false;
+          this.list3 = true;
+          this.list2 = false;
+        } else {
+          this.list1 = true;
+          this.TotalPrice = 0;
+        }
+      });
+    },
     submitCheckinfee() {
       let _this = this;
       if (_this.tjCategory !== "") {
-        let List = _this.tableData1; //鍗曚釜椤圭洰淇℃伅
+        let List = _this.tableData1;
         if (this.responseList.cusId) {
           var userId = this.responseList.cusId;
         } else {
@@ -2763,8 +2874,6 @@
         if (this.tableData[0]) {
           var pacId = this.tableData[0].pacId;
         }
-
-        //tjOrderList//杩欎釜鏄鐞嗗畬鐨勬瘡涓�椤瑰椁愪俊鎭�
         List.forEach((item) => {
           if (item.list) {
             item.list.forEach((item1) => {
@@ -2914,9 +3023,7 @@
             }
             this.discount =
               (this.formInline.paidIn / this.formInline.price) * 10;
-            if (this.discount <= this.getInfodis) {
-              this.discount = this.getInfodis;
-            }
+
           } else {
             this.discount = 10;
             this.formInline.paidIn = "0.00";
@@ -3010,8 +3117,8 @@
     // 鏈�鍚庢彁浜ゆ寜閽�
     submitPrice() {
       let _this = this;
+      this.loadingSubmit = true;
       if (_this.tjCategory !== "") {
-        this.loadingSubmit = true;
         let List = _this.tableData1; //鍗曚釜椤圭洰淇℃伅
         if (this.responseList.cusId) {
           var userId = this.responseList.cusId;

--
Gitblit v1.8.0