index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import history from "./../../utils/history";
  2. import { getContentHeight } from "../../utils";
  3. import { getDepartmentList } from "./service";
  4. import { queryServiceByCode } from "../../service/common";
  5. import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  6. Component({
  7. props: {
  8. componentData: {},
  9. },
  10. data: {
  11. index: 0,
  12. show: false,
  13. menus: [],
  14. cache: {},
  15. lastCache: {},
  16. loading: true,
  17. serviceItem: null,
  18. contentHeight: getContentHeight(),
  19. },
  20. async didMount() {
  21. /* 服务预警, 预约挂号 */
  22. reportCmPV_YL({
  23. title: "预约挂号",
  24. });
  25. const { hospitalDistrictId } = this.getQuery();
  26. try {
  27. await this.getServiceDetail(); // eslint-disable-next-line no-empty
  28. } catch (e) {}
  29. await this.fetchMenus(hospitalDistrictId);
  30. },
  31. methods: {
  32. updateData(data) {
  33. return new Promise((resolve) => this.setData(data, resolve));
  34. },
  35. async getServiceDetail() {
  36. const code = "hospital_service_code";
  37. const { link, uuid, title, linkType, accessMode, serviceDesc } =
  38. await queryServiceByCode(code);
  39. const serviceItem = {
  40. url: link,
  41. accessMode,
  42. name: title,
  43. serviceDesc,
  44. urlType: linkType,
  45. serviceUUID: uuid,
  46. };
  47. await this.updateData({
  48. serviceItem,
  49. });
  50. },
  51. getQuery() {
  52. const { $routeConfig } = this.$page;
  53. return $routeConfig.query;
  54. },
  55. async fetchProxy(func, ...arg) {
  56. my.showLoading();
  57. await func(...arg).finally(my.hideLoading);
  58. },
  59. /* 检测缓存 */
  60. hasCache() {
  61. const { index, cache } = this.data;
  62. return (cache[index] || []).length > 0;
  63. },
  64. /* 设置缓存 */
  65. setCache(list) {
  66. const { index: i, cache: _cache } = this.data;
  67. const cache = { ..._cache };
  68. cache[i] = list;
  69. return this.updateData({
  70. cache,
  71. });
  72. },
  73. /* 获取一级列表数据 */
  74. async fetchMenus(hospitalDistrictId) {
  75. const params = {
  76. hospitalDistrictId,
  77. };
  78. const list = await getDepartmentList(params);
  79. await this.updateData({
  80. menus: list,
  81. loading: false,
  82. });
  83. /* 获取一级列表下面的第一项的第一个 */
  84. const departmentId = this.getDepartmentId(0);
  85. await this.fetchDepartments(departmentId, list[0]);
  86. },
  87. /* 获取二级列表 */
  88. async fetchDepartments(departmentId, item) {
  89. if (this.hasCache()) return;
  90. const list = !departmentId
  91. ? [item]
  92. : await getDepartmentList({
  93. parentId: departmentId,
  94. });
  95. this.setCache(list);
  96. },
  97. /* 获取科室id */
  98. getDepartmentId(index) {
  99. const { menus = [] } = this.data;
  100. const { hasChildren, departmentId } = menus[index] || {};
  101. if (hasChildren) return departmentId;
  102. },
  103. /* 切换科室 */
  104. async onTapMenu(i) {
  105. const item = this.data.menus[i];
  106. await this.updateData({
  107. index: i,
  108. });
  109. const departmentId = this.getDepartmentId(i);
  110. await this.fetchDepartments(departmentId, item);
  111. },
  112. /* 获取三级列表数据 */
  113. async onTapOpenLast(item) {
  114. const { departmentId } = item;
  115. const { lastCache } = this.data;
  116. const cacheList = lastCache[departmentId] || [];
  117. if (cacheList.length > 0) return cacheList;
  118. my.showLoading();
  119. const list = await getDepartmentList({
  120. parentId: departmentId,
  121. }).finally(my.hideLoading);
  122. lastCache[departmentId] = list;
  123. await this.updateData({
  124. lastCache: { ...lastCache },
  125. });
  126. return list;
  127. },
  128. onTapItem(item) {
  129. const query = this.getQuery();
  130. const { name: areaName } = query;
  131. const { componentData } = this.props;
  132. const {
  133. departmentId,
  134. name: dpName,
  135. departmentCode: depCode,
  136. hospitalId,
  137. } = item;
  138. history.push({
  139. query: {
  140. departmentId,
  141. depCode,
  142. hospitalId,
  143. },
  144. title: `${dpName}(${areaName})`,
  145. pageType: "hospital-num-source",
  146. componentData: { ...componentData, department: item },
  147. });
  148. },
  149. },
  150. });