cc12458 1 год назад
Родитель
Сommit
77d3a663be
1 измененных файлов с 49 добавлено и 144 удалено
  1. 49 144
      src/components/ChineseMedicine.vue

+ 49 - 144
src/components/ChineseMedicine.vue

@@ -1143,6 +1143,20 @@ export default {
   },
   mounted() {},
   methods: {
+    _splitDataToView(totalData) {
+      if (!Array.isArray(totalData)) totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
+      const forceUpdate = (data) => Object.assign({}, data);
+      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
+        (item, index) => {
+          return item.id % 2 !== 0;
+        }
+      ).map(forceUpdate);
+      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
+        (item, index) => {
+          return item.id % 2 === 0;
+        }
+      ).map(forceUpdate);
+    },
     // 打开父级安全合理用药监测
     openSafeDrug() {
       this.$parent.opensafeD();
@@ -1209,6 +1223,8 @@ export default {
     },
     // 监听键盘事件
     drugDown(e, scope) {
+      e.stopPropagation();
+      e.preventDefault();
       let index = scope.row.id ? scope.row.id - 1 : 0;
 
       let totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
@@ -1233,15 +1249,8 @@ export default {
       // 表格 fixed 时 去 下标 为 1
 
       if (totalData[index].drugList.length > 5) {
-        document.querySelectorAll(
-          `#infiniteList${scope.row.id}`
-        )[1].scrollTop += 36;
-
-        console.log(
-          document.querySelectorAll(`#infiniteList${scope.row.id}`)[1]
-            .scrollTop,
-          "top"
-        );
+        const el = document.querySelectorAll(`#infiniteList${scope.row.id}`)[0];
+        if (el) el.scrollTop += 36;
       }
       this.recipe_tabs[this.recipe_tabs_c].totalTableD = totalData;
       totalData.filter((item, index) => {
@@ -1249,19 +1258,12 @@ export default {
         return (item.id = index + 1);
       });
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
       this.$forceUpdate();
     },
     drugUp(e, scope) {
+      e.stopPropagation();
+      e.preventDefault();
       let index = scope.row.id ? scope.row.id - 1 : 0;
       let totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
       // 如果到最后一个 判断是否需要分页
@@ -1271,30 +1273,16 @@ export default {
         totalData[index].search_i -= 1;
       }
 
-      if (
-        document.querySelectorAll(`#infiniteList${scope.row.id}`)[1].scrollTop >
-        0
-      ) {
-        document.querySelectorAll(
-          `#infiniteList${scope.row.id}`
-        )[1].scrollTop -= 36;
-      }
+
+      const el = document.querySelectorAll(`#infiniteList${scope.row.id}`)[0];
+      if (el && el.scrollTop > 0) el.scrollTop -= 36;
       this.recipe_tabs[this.recipe_tabs_c].totalTableD = totalData;
       totalData.filter((item, index) => {
         // this.getSelectType('中药药品用法', index)
         return (item.id = index + 1);
       });
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
     },
     drugEnter(scope) {
       this.chooseDis1(
@@ -1309,16 +1297,7 @@ export default {
 
       this.recipe_tabs[this.recipe_tabs_c].totalTableD[index].usage = e;
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
     },
     doseFocus(scope) {
       let width = window.innerWidth;
@@ -1810,17 +1789,7 @@ export default {
         scope.row.id - 1
       ].total = total;
 
-      const forceUpdate = (data) => Object.assign({}, data);
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      ).map(forceUpdate);
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      ).map(forceUpdate);
+      this._splitDataToView(totalData);
 
       if (this.recipe_tabs[this.recipe_tabs_c].bottom_form.doseNum) {
         // this.countNowRecipeMoney();
@@ -1905,16 +1874,7 @@ export default {
         return (item.id = index + 1);
       });
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
 
       if (from != "now") return;
       setTimeout(() => {
@@ -1965,16 +1925,7 @@ export default {
 
       this.recipe_tabs[this.recipe_tabs_c].totalTableD = totalData;
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
       if (type != "click") return;
       setTimeout(() => {
         if (
@@ -2017,16 +1968,7 @@ export default {
         // father.getRationalMed(item.medid)
         return (item.id = index + 1);
       });
-      this.recipe_tabs[this.recipe_tabs_c].tableData = totalData.filter(
-        (item, index) => {
-          return item.id % 2 != 0;
-        }
-      );
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = totalData.filter(
-        (item, index) => {
-          return item.id % 2 == 0;
-        }
-      );
+      this._splitDataToView(totalData);
       this.countNowRecipeMoney();
     },
     clickName(scope) {
@@ -2057,10 +1999,6 @@ export default {
       ].search_i = 0;
 
       debounce(this.getTableDrug(scope.row.key, 1, scope.row.id - 1), 10000);
-      setTimeout(() => {
-        // console.log(document.querySelectorAll('#searchD' + scope.row.id));
-        document.querySelectorAll("#searchD" + scope.row.id)[0].focus();
-      }, 800);
     },
     // 输入框获取 药品列表
     searchDrug(e, scope) {
@@ -2077,7 +2015,6 @@ export default {
       let index = scope.row.id ? scope.row.id - 1 : 0;
       // console.log(this.recipe_tabs[this.recipe_tabs_c].totalTableD[index], '我是key')
 
-      this.recipe_tabs[this.recipe_tabs_c].totalTableD[index].key = e;
       let ids = document.querySelectorAll("#operate2");
       ids.forEach((item, index) => {
         item.style["z-index"] = "auto";
@@ -2092,21 +2029,15 @@ export default {
       //     ].showSearch = false
       // }
 
-      this.recipe_tabs[this.recipe_tabs_c].tableData = this.recipe_tabs[
-        this.recipe_tabs_c
-      ].totalTableD.filter((item, index) => {
-        return item.id % 2 != 0;
-      });
-      this.recipe_tabs[this.recipe_tabs_c].tableData1 = this.recipe_tabs[
-        this.recipe_tabs_c
-      ].totalTableD.filter((item, index) => {
-        return item.id % 2 == 0;
-      });
+      const totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
+      totalData[index].key = e;
+      totalData[index].search_i = 0;
+      this._splitDataToView(totalData);
       this.index = scope.row.id - 1;
 
       // this.getTableDrug(scope.row.key, 1, scope.row.id - 1)
 
-      debounce(this.getTableDrug(scope.row.key, 1, index), 10000);
+      debounce(this.getTableDrug(e, 1, index), 10000);
     },
     drugFocus(scope) {
       this.medIndex = scope.$index;
@@ -2137,16 +2068,7 @@ export default {
         this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(item => {
           item.drugList = [];
         });
-        this.recipe_tabs[this.recipe_tabs_c].tableData = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 != 0;
-        });
-        this.recipe_tabs[this.recipe_tabs_c].tableData1 = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 == 0;
-        });
+        this._splitDataToView();
       }, 500);
     },
     drugBlur1(e, scope) {
@@ -2176,16 +2098,7 @@ export default {
         this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(item => {
           item.drugList = [];
         });
-        this.recipe_tabs[this.recipe_tabs_c].tableData = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 != 0;
-        });
-        this.recipe_tabs[this.recipe_tabs_c].tableData1 = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 == 0;
-        });
+        this._splitDataToView();
       }, 500);
     },
     // 合并表一 表二
@@ -2639,16 +2552,7 @@ export default {
             return (item.id = index + 1);
           }
         );
-        this.recipe_tabs[this.recipe_tabs_c].tableData = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 != 0;
-        });
-        this.recipe_tabs[this.recipe_tabs_c].tableData1 = this.recipe_tabs[
-          this.recipe_tabs_c
-        ].totalTableD.filter((item, index) => {
-          return item.id % 2 == 0;
-        });
+        this._splitDataToView();
 
         // this.recipe_tabs[this.recipe_tabs_c].lastType = this.recipe_tabs[this.recipe_tabs_c]
         //     .radio // 存储这一次的 药房类型
@@ -2732,22 +2636,23 @@ export default {
               return (item.id = index + 1);
             }
           );
-          this.recipe_tabs[this.recipe_tabs_c].tableData = this.recipe_tabs[
-            this.recipe_tabs_c
-          ].totalTableD.filter((item, index) => {
-            return item.id % 2 != 0;
-          });
-          this.recipe_tabs[this.recipe_tabs_c].tableData1 = this.recipe_tabs[
-            this.recipe_tabs_c
-          ].totalTableD.filter((item, index) => {
-            return item.id % 2 == 0;
-          });
+          this._splitDataToView();
         } else {
           this.recipe_tabs[this.recipe_tabs_c].totalTableD[
             index
           ].loadMore = false;
         }
+
+        if (page === 1) {
+          const el = document.querySelectorAll(`#infiniteList${index+1}`)[0];
+          if (el && el.scrollTop > 0) el.scrollTop = 0;
+        }
       }
+      setTimeout(() => {
+        const el = document.querySelectorAll(`#searchD${index+1}`)[0];
+        console.log(el);
+        if (el) el.focus();
+      }, 100);
     },
     // 获取省数据
     async getProver() {