Procházet zdrojové kódy

优化药品输入 协定方等组件

cc12458 před 1 rokem
rodič
revize
5c9854020e

+ 5 - 2
src/components/ChineseMedicine.vue

@@ -2002,6 +2002,7 @@ export default {
         scope.row.id - 1
       ].search_i = 0;
 
+      if (!scope.row.key) scope.row.key = scope.row.name;
       debounce(this.getTableDrug(scope.row.key, 1, scope.row.id - 1), 10000);
     },
     // 输入框获取 药品列表
@@ -2217,7 +2218,10 @@ export default {
         if (from == "reserve") {
           this.$refs.accordEdit.isNeedOpenRecipe = true;
         }
-        this.$refs.accordEdit.assignTableData(arr, "saveToMy");
+        const last = arr[arr.length - 1];
+        if (last && !last.name) arr.pop();
+        const val = this.recipe_tabs[this.recipe_tabs_c].radio;
+        this.$refs.accordEdit.assignTableData(arr, val);
         // 赋值病名数据
         let tcmValue = this.$parent.$refs.TCM.getParams();
 
@@ -2654,7 +2658,6 @@ export default {
       }
       setTimeout(() => {
         const el = document.querySelectorAll(`#searchD${index+1}`)[0];
-        console.log(el);
         if (el) el.focus();
       }, 100);
     },

+ 98 - 175
src/components/MedicineAccord.vue

@@ -1,5 +1,5 @@
 <template>
-  <div>
+  <div class="medicine-editor-wrapper">
     <div class="table-container">
       <div class="t-con-header flex-vertical-between">
         <div class="t-con-radio flex-vertical-center-l" v-if="false">
@@ -706,6 +706,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();
@@ -772,6 +786,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;
@@ -795,36 +811,22 @@ 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"
-      //   );
-      // }
+      if (totalData[index].drugList.length > 5) {
+        const el = document.querySelectorAll(`.medicine-editor-wrapper #infiniteList${scope.row.id}`)[0];
+        if (el) 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);
       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;
       // 如果到最后一个 判断是否需要分页
@@ -834,30 +836,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(`.medicine-editor-wrapper #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(
@@ -872,16 +860,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;
@@ -926,17 +905,17 @@ export default {
         this.recipe_tabs[this.recipe_tabs_c].totalTableD.length - 1
       ) {
         // console.log(document.querySelectorAll('#searchD' + (scope.row.id + 1)), '啦啦啦')
-        document.querySelectorAll("#searchD" + (scope.row.id + 1))[0].focus();
+        document.querySelectorAll(".medicine-editor-wrapper #searchD" + (scope.row.id + 1))[0].focus();
       } else {
         try {
           this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(item => {
             if (item.name && !item.dose && scope.row.id < item.id) {
-              document.querySelectorAll("#dose" + item.id)[0].focus();
+              document.querySelectorAll(".medicine-editor-wrapper #dose" + item.id)[0].focus();
               throw Error();
             }
             if (!item.name) {
               // console.log(document.querySelectorAll('#searchD' + item.id), '啦啦啦')
-              document.querySelectorAll("#searchD" + item.id)[0].focus();
+              document.querySelectorAll(".medicine-editor-wrapper #searchD" + item.id)[0].focus();
               throw Error();
             }
           });
@@ -1270,13 +1249,13 @@ export default {
       if (Number(e) > Number(kucun)) {
         this.$message.warning("当前库存不足");
 
-        document.querySelectorAll("#dose" + scope.row.id)[0].style.border =
+        document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id)[0].style.border =
           "1px solid red";
-        document.querySelectorAll("#dose" + scope.row.id)[0].style.color =
+        document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id)[0].style.color =
           "red";
       } else {
-        document.querySelectorAll("#dose" + scope.row.id)[0].style.border = "";
-        document.querySelectorAll("#dose" + scope.row.id)[0].style.color = "";
+        document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id)[0].style.border = "";
+        document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id)[0].style.color = "";
       }
 
       let price = this.recipe_tabs[this.recipe_tabs_c].totalTableD[
@@ -1300,22 +1279,13 @@ export default {
         scope.row.id - 1
       ].total = total;
 
-      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 (this.recipe_tabs[this.recipe_tabs_c].bottom_form.doseNum) {
-        this.countNowRecipeMoney();
+        // this.countNowRecipeMoney();
       }
-    },
-    // 表一 选中药品
+      this.countNowRecipeMoney();
+    },// 表一 选中药品
     chooseDis1(scope, index, item, from = "now") {
       let totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
       let isHas = false;
@@ -1328,15 +1298,20 @@ export default {
         this.$message.warning("请勿重复添加药品");
         return;
       }
+
       let obj = {
-        color: "#000",
+        color: item.kc == 0 ? "red" : "#000",
         id: scope.row.id,
         name: item.ypmc,
         spec: item.gg, // 规格
-        dose: "", // 剂量
+        // dose: "", // 剂量
+        dose: scope.row.color == "red" ? scope.row.dose : "",
         unit: item.dw, // 单位
-        // usage: item.usagestr, // 用法
-        usage: "",
+        usage:
+          scope.row.color == "red"
+            ? this.usageList[0].key
+            : scope.row.usage || item.usagestr || this.usageList[0].key, // 用法
+        //usage: "",
         // price: item.lsjg,
         price: item.price,
         total: 0,
@@ -1351,7 +1326,6 @@ export default {
       Object.assign(totalData[scope.row.id - 1], obj);
 
       // 调用 父级合理用药接口
-      let father = this.$parent;
 
       if (scope.row.id == totalData.length) {
         totalData.push({
@@ -1371,22 +1345,15 @@ 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(() => {
-        let ids = document.querySelectorAll("#dose" + scope.row.id);
-        document.querySelectorAll("#dose" + scope.row.id)[0].focus();
+        let ids = document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id);
+        document.querySelectorAll(".medicine-editor-wrapper #dose" + scope.row.id)[0].focus();
       }, 500);
+
+      this.countNowRecipeMoney();
     },
     // 表一和表二 数据添加
     addDis1(scope, type = "click") {
@@ -1429,29 +1396,20 @@ 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 (
           scope.row.id ==
           this.recipe_tabs[this.recipe_tabs_c].totalTableD.length - 1
         ) {
-          document.querySelectorAll("#searchD" + (scope.row.id + 1))[0].focus();
+          document.querySelectorAll(".medicine-editor-wrapper #searchD" + (scope.row.id + 1))[0].focus();
         } else {
           try {
             this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(item => {
               if (!item.name) {
                 // console.log(document.querySelectorAll('#searchD' + item.id), '啦啦啦')
-                document.querySelectorAll("#searchD" + item.id)[0].focus();
+                document.querySelectorAll(".medicine-editor-wrapper #searchD" + item.id)[0].focus();
                 throw Error();
               }
             });
@@ -1476,16 +1434,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) {
@@ -1515,11 +1464,8 @@ export default {
         scope.row.id - 1
       ].search_i = 0;
 
+      if (!scope.row.key) scope.row.key = scope.row.name;
       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) {
@@ -1536,8 +1482,7 @@ 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");
+      let ids = document.querySelectorAll(".medicine-editor-wrapper #operate2");
       ids.forEach((item, index) => {
         item.style["z-index"] = "auto";
       });
@@ -1551,21 +1496,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;
@@ -1588,7 +1527,7 @@ export default {
         let index = scope.row.id ? scope.row.id - 1 : 0;
         this.recipe_tabs[this.recipe_tabs_c].totalTableD[index].key = "";
 
-        let ids = document.querySelectorAll("#operate2");
+        let ids = document.querySelectorAll(".medicine-editor-wrapper #operate2");
         ids.forEach((item, index) => {
           item.style["z-index"] = "99";
         });
@@ -1596,16 +1535,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) {
@@ -1627,7 +1557,7 @@ export default {
         this.recipe_tabs[this.recipe_tabs_c].totalTableD[
           index
         ].showSearch = false;
-        let ids = document.querySelectorAll("#operate2");
+        let ids = document.querySelectorAll(".medicine-editor-wrapper #operate2");
         ids.forEach((item, index) => {
           item.style["z-index"] = "99";
         });
@@ -1635,16 +1565,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);
     },
     // 合并表一 表二
@@ -1994,7 +1915,11 @@ export default {
     },
 
     // 切换中药类型时 切换 药房 获取 药品里面有没有这条数据
-    async changePharmacy(type) {
+    async changePharmacy(type, val) {
+      if (!type) type = this.recipe_tabs[this.recipe_tabs_c].lastType || '';
+      if (!val) val = this.recipe_tabs[this.recipe_tabs_c].radio || '';
+      this.recipe_tabs[this.recipe_tabs_c].radio = val;
+
       let drugIds = [];
       const loading = this.$loading({
         lock: true,
@@ -2005,7 +1930,7 @@ export default {
 
       this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(item => {
         if (item.name) {
-          let idDose = item.medid + "&" + (item.dose || item.oldDose);
+          let idDose = item.medid + "&" + (item.dose || item.oldDose) + "&" + (item.usage || "");
           // drugIds.push(item.medid)
           item.oldDose = item.dose;
           drugIds.push(idDose);
@@ -2013,8 +1938,7 @@ export default {
       });
 
       let pharmacyName = "";
-      let type1 = "";
-      type1 = this.recipe_tabs[this.recipe_tabs_c].radio.split("@")[1];
+      val = val.split("@")[1];
       type = type.split("@")[1];
 
       this.recipe_tabs[this.recipe_tabs_c].pharmacyID = this.recipe_tabs[
@@ -2022,7 +1946,7 @@ export default {
       ].radio.split("@")[0];
 
       let params = {
-        type: type1,
+        type: val || type,
         pharmacyid: this.recipe_tabs[this.recipe_tabs_c].pharmacyID,
         drugIds,
         preType: this.recipe_tabs[this.recipe_tabs_c].preType,
@@ -2035,6 +1959,12 @@ export default {
         this.recipe_tabs[this.recipe_tabs_c].totalTableD.forEach(
           (item1, index1) => {
             if (item1.name) {
+              const getUsage = (function (list = [], value = '') {
+                if (!Array.isArray(list) || list.length === 0) return void 0;
+                const option = value && list.find(item => item.value === value || item.key == value);
+                return option ? option.key : list[0].key;
+              }).bind(null, this.usageList);
+
               res.Data.forEach((item, index) => {
                 if (item == item1.medid) {
                   item1.color = "red";
@@ -2049,7 +1979,7 @@ export default {
                     spec: item.gg, // 规格
                     dose: item.dose, // 剂量
                     unit: item.dw, // 单位
-                    usage: item1.usagestr || item1.usage || "", // 用法
+                    usage: item.usagestr || item.usage, // || this.usegeList[0].key, // 用法
                     // usage: "",
                     // price: item.lsjg,
                     price: item.price,
@@ -2063,6 +1993,7 @@ export default {
                     usageList: [],
                     oldDose: item1.oldDose
                   };
+                  /* 修正 */ item1.usage = item1.useage = getUsage(item1.usage);
 
                   item1.color = "#000";
                 }
@@ -2082,16 +2013,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 // 存储这一次的 药房类型
@@ -2100,7 +2022,7 @@ export default {
         ].radio; // 存储这一次的 药房类型
         loading.close();
         // console.log(this.recipe_tabs[this.recipe_tabs_c].totalTableD);
-        this.getPharmacyMsg(this.recipe_tabs[this.recipe_tabs_c].pharmacyID);
+        await this.getPharmacyMsg(this.recipe_tabs[this.recipe_tabs_c].pharmacyID);
         setTimeout(() => {
           this.countNowRecipeMoney();
         }, 500);
@@ -2175,22 +2097,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(`.medicine-editor-wrapper #infiniteList${index+1}`)[0];
+          if (el && el.scrollTop > 0) el.scrollTop = 0;
+        }
       }
+      setTimeout(() => {
+        const el = document.querySelectorAll(`.medicine-editor-wrapper #searchD${index+1}`)[0];
+        console.log(el);
+        if (el) el.focus();
+      }, 100);
     },
     // 获取省数据
     async getProver() {

+ 1 - 1
src/views/business/AccordEdit.vue

@@ -676,7 +676,7 @@ export default {
           treatment: res.Data.treatment
         };
         tcmd.setParams(data);
-        this.assignTableData(res.Data.prescriptionDetailVos, "saveToMy");
+        this.assignTableData(res.Data.prescriptionDetailVos, res.Data.pharmacyid+'@1');
       }
     }
   }