Browse Source

调整进入开方数据获取逻辑

cc12458 1 year ago
parent
commit
79fe3fa020
2 changed files with 54 additions and 69 deletions
  1. 8 4
      src/components/ChineseMedicine.vue
  2. 46 65
      src/views/diagnosis/Prescribing.vue

+ 8 - 4
src/components/ChineseMedicine.vue

@@ -1143,6 +1143,10 @@ export default {
   },
   mounted() {},
   methods: {
+    async loaded(props) {
+      if (!this.pharmacyTypes.length) await this.customerQuery(props).catch(() => void 0);
+      return this;
+    },
     _splitDataToView(totalData) {
       if (!Array.isArray(totalData)) totalData = this.recipe_tabs[this.recipe_tabs_c].totalTableD;
       const forceUpdate = (data) => Object.assign({}, data);
@@ -2405,7 +2409,7 @@ export default {
       }
     },
     // 选择药房
-    async customerQuery() {
+    async customerQuery(defaultProps = {}) {
       let res = await customerQuery({
         type: 0
       });
@@ -2421,10 +2425,10 @@ export default {
             });
           });
         });
-
+        defaultProps = {...pharmacyTypes[0], ...defaultProps};
         this.recipe_tabs[this.recipe_tabs_c].pharmacyID = res.Data[0].pid;
-        this.recipe_tabs[this.recipe_tabs_c].radio = pharmacyTypes[0].ptype;
-        this.recipe_tabs[this.recipe_tabs_c].lastType = pharmacyTypes[0].ptype;
+        this.recipe_tabs[this.recipe_tabs_c].radio = defaultProps.ptype;
+        this.recipe_tabs[this.recipe_tabs_c].lastType = defaultProps.ptype;
         this.pharmacyList = res.Data;
         this.pharmacyTypes = pharmacyTypes;
         this.$forceUpdate();

+ 46 - 65
src/views/diagnosis/Prescribing.vue

@@ -1375,25 +1375,7 @@ export default {
     }
   },
   mounted() {
-    this._getPreNumber();
-    setTimeout(() => {
-      this.inferRecipe(4, "1");
-      this.inferRecipe(4, "3");
-    }, 1000);
-
-    return;
-    if (this.$route.query.recipeID) {
-      this.getRecipeDataByid(this.$route.query.recipeID);
-    } else if (this.$route.query.doctorCase) {
-      setTimeout(() => {
-        this.changeAndJoin();
-      }, 1000);
-    } else if (this.$route.query.type == "tuidao") {
-      this.isTuiDaoZy = true;
-      this.inferRecipe();
-    } else {
-      this.getRecipeShowData();
-    }
+    this._processRouteQuery();
   },
   beforeRouteLeave(to, from, next) {
     if (to.path == "/index/recipe") {
@@ -1416,11 +1398,35 @@ export default {
   methods: {
     // 处理路由参数
    async _processRouteQuery() {
-      const query = this.$route.query;
-      if (!query) return;
+      const query = this.$route.query || {};
+      // 暂存处方数据(不含药品)
+      if (sessionStorage.getItem("prescr" + this.getPatiensInfo.pid)) await this._showDataFromStorage(true);
+
+      // 名医名方 —> 方剂查询
       if (query.recipeID && query.kjType === "kj-fj") await this.getPreDetal(query.recipeID);
+      // 名医名方 —> 名医医案
       else if (query.doctorCase) await this.changeAndJoin();
-    },
+      // 中医诊疗 -> 智能辩证
+      else if (query.type === "tuidao") {
+        await Promise.all([
+          this.inferRecipe(4, "1"),
+          this.inferRecipe(4, "3"),
+          this.inferRecipe(),
+        ])
+        this.isTuiDaoZy = true;
+      }
+      // 处方编辑 recipeType
+      else if (this.getEditPreNo()) await this.getRecipeDataByid(this.getEditPreNo());
+      // 暂存处方
+      else if (sessionStorage.getItem("prescr" + this.getPatiensInfo.pid)) await this._showDataFromStorage();
+      // 历史处方
+      else {
+        // 跟据就诊记录id获取处方号
+        let res = await getPreNumber({pid: this.getPatiensInfo.pid}).catch(() => void 0);
+        const has = res && res.ResultCode == 0 && res.Data.length > 0;
+        if (has) await this.getRecipeShowData();
+      }
+   },
     // 参考医案
     // 中医诊断推导点击
     tcmClick(isauto = true) {
@@ -1512,7 +1518,7 @@ export default {
       // getPatiensInfo
     },
     // 展示系统缓存数据
-    _showDataFromStorage() {
+    async _showDataFromStorage(ignoreTable = false) {
       let storageData = JSON.parse(
         sessionStorage.getItem("prescr" + this.getPatiensInfo.pid)
       );
@@ -1527,6 +1533,8 @@ export default {
       let child2 = children[1];
       let child3 = children[2];
 
+      if (typeof child1.loaded === 'function') await child1.loaded(storageData.child1);
+
       if (storageData.child1.recipe_tabs[0].totalTableD.length > 1) {
         this.isTuiDaoZy = true;
       }
@@ -1535,14 +1543,24 @@ export default {
         this.isTuiDaoZy = true;
       }
 
+      if (ignoreTable) {
+        for (const recipe of storageData.child1.recipe_tabs) {
+          recipe.tableData = [];
+          recipe.tableData1 = [];
+          recipe.totalTableD = [];
+        }
+        storageData.child2.tableData3 = [];
+        storageData.child3.tableData4 = [];
+      }
+
       this.container_i = storageData.container_i;
       child1.recipe_tabs = storageData.child1.recipe_tabs;
       child1.recipe_tabs_c = storageData.child1.recipe_tabs_c;
-      child1.getSelectType("剂型", 0);
-      child1.getSelectType("处方用法");
-      child1.getSelectType("中药服药时间");
-      child1.getSelectType("中药频次");
-      child1.getPharmacyID();
+      // child1.getSelectType("剂型", 0);
+      // child1.getSelectType("处方用法");
+      // child1.getSelectType("中药服药时间");
+      // child1.getSelectType("中药频次");
+      // child1.getPharmacyID();
       child2.tableData3 = storageData.child2.tableData3;
       child2.bottom_form = storageData.child2.bottom_form;
 
@@ -3024,43 +3042,6 @@ export default {
       this.setDrugsInfo(this.preInfo.items);
       this.changeAndJoin(1);
     },
-    // 跟据就诊记录id获取处方号
-    async _getPreNumber() {
-      let res = await getPreNumber({
-        pid: this.getPatiensInfo.pid
-      });
-      if (res.ResultCode == 0) {
-        setTimeout(() => {
-          this.inferRecipe();
-        }, 800);
-        if (res.Data.length == 0) {
-          // 没有处方号
-          let hasStorage = sessionStorage.getItem(
-            "prescr" + this.getPatiensInfo.pid
-          )
-            ? true
-            : false;
-          if (hasStorage) {
-            this._showDataFromStorage();
-          }
-
-          const recipeID = this.getEditPreNo();
-          debugger
-          if (!!recipeID && !this.$route.query.kjType) {
-            await this.getRecipeDataByid(recipeID);
-          } else if (this.$route.query.type == "tuidao") {
-            this.isTuiDaoZy = true;
-            // setTimeout(() => {
-            //   this.inferRecipe()
-            // }, 800)
-          }
-        } else {
-          // 有处方号
-          await this.getRecipeShowData();
-        }
-      }
-      await this._processRouteQuery();
-    },
     // 药方是否支付
     async _recipeIsPay(id, type, index) {
       let res = await recipeIsPay({