浏览代码

优化: 医共体、医疗机构、科室病区 三级列表数据获取逻辑

cc12458 1 年之前
父节点
当前提交
4bb7bbc03b
共有 1 个文件被更改,包括 35 次插入29 次删除
  1. 35 29
      src/views/pharmacy/mechanism/index.vue

+ 35 - 29
src/views/pharmacy/mechanism/index.vue

@@ -25,7 +25,7 @@
               placeholder="请选择医共体"
               clearable
               size="small"
-              @change="handleComId"
+              @change="getMechanismListArr"
               style="width:160px"
             >
               <el-option
@@ -45,7 +45,7 @@
               placeholder="请选择医疗机构"
               clearable
               size="small"
-              @change="handleMechanismId"
+              @change="getDeptListArr"
             >
               <el-option
                 v-for="item in mechanismArr"
@@ -70,6 +70,7 @@
               style="width:160px"
               v-model="queryParams.deptId"
               placeholder="请选择科室病区"
+              :disabled="!queryParams.mechanismId"
             >
               <el-option
                 v-for="item in deptListArr"
@@ -359,9 +360,8 @@ export default {
     };
   },
   created() {
-    this.getList();
+    this.resetQuery()
     this.getMedicalPharmacy();
-    this.getCommunityList();
     // this.getMechanismListArr();
     // this.getListDeptArr();
     // this.getListDept();
@@ -422,24 +422,30 @@ export default {
         this.cimmunity = response.rows;
       });
     },
-    /** 通过医共体id查询机构 **/
-    handleChangeCommunity() {
-      if (this.form.communityId) {
-        this.getMechanismList(this.form.communityId);
-        this.form.mechanismId = null;
-        this.form.deptId = null;
+    /* [搜索] 获取机构 */
+    async getMechanismListArr(id) {
+      if (id) {
+        this.mechanismArr = await listMechanismId(id).then((response) => response.data)
+      } else {
+        this.mechanismArr = await listMedicalMechanism().then(response => response.data);
+      }
+      const mechanismId = this.queryParams.mechanismId;
+      if (mechanismId && !this.mechanismArr.find(item => +item.id === +mechanismId)) {
+        this.queryParams.mechanismId = ''
+        this.queryParams.deptId = ''
       }
     },
-    handleComId(e) {
-      //console.log(e);
-      this.getMechanismListArr(e);
-    },
-    getMechanismListArr(id) {
-      this.queryParams.mechanismId = ''
+    /* [搜索] 获取科室 */
+    async getDeptListArr(e) {
       this.queryParams.deptId = ''
-      listMedicalMechanism(id).then((response) => {
-        this.mechanismArr = response.data.filter(v => v.communityId == id);
-      });
+      this.deptListArr = [];
+      if (!e) return;
+      this.deptListArr = await getByMechanismId(e).then((response) => response.data);
+      const item = this.mechanismArr.find(item => +item.id === +e) || {};
+      if (!this.queryParams.communityId && item.communityId) {
+        this.queryParams.communityId = item.communityId;
+        await this.getMechanismListArr(item.communityId)
+      }
     },
     /** 查询医疗机构名称 **/
     getMechanismList(id) {
@@ -448,6 +454,14 @@ export default {
         this.mechanismId = null;
       });
     },
+    /** 通过医共体id查询机构 **/
+    handleChangeCommunity() {
+      if (this.form.communityId) {
+        this.getMechanismList(this.form.communityId);
+        this.form.mechanismId = null;
+        this.form.deptId = null;
+      }
+    },
     /** 通过医疗机构查询科室 **/
     handlechangeMechanidm() {
       if (this.form.mechanismId) {
@@ -456,16 +470,6 @@ export default {
         this.form.deptId = null;
       }
     },
-    handleMechanismId(e) {
-      this.queryParams.deptId = ''
-      this.getListDeptArr(e);
-    },
-    getListDeptArr(id) {
-      listDept(id).then((response) => {
-        this.deptListArr = response.rows.filter(v => v.communityId == id);
-        // //console.log(response.rows, "999");
-      });
-    },
     /** 查询科室名称 */
     getListDept(id) {
       getByMechanismId(id).then((response) => {
@@ -500,6 +504,8 @@ export default {
     },
     /** 重置按钮操作 */
     resetQuery() {
+      this.getCommunityList();
+      this.getMechanismListArr();
       this.resetForm("queryForm");
       this.handleQuery();
     },