index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. if (uuid) {
  40. const serviceItem = {
  41. url: link,
  42. accessMode,
  43. name: title,
  44. serviceDesc,
  45. urlType: linkType,
  46. serviceUUID: uuid,
  47. };
  48. await this.updateData({
  49. serviceItem,
  50. });
  51. }
  52. },
  53. getQuery() {
  54. const { $routeConfig } = this.$page;
  55. return $routeConfig.query;
  56. },
  57. async fetchProxy(func, ...arg) {
  58. my.showLoading();
  59. await func(...arg).finally(my.hideLoading);
  60. },
  61. /* 检测缓存 */
  62. hasCache() {
  63. const { index, cache } = this.data;
  64. return (cache[index] || []).length > 0;
  65. },
  66. /* 设置缓存 */
  67. setCache(list) {
  68. const { index: i, cache: _cache } = this.data;
  69. const cache = { ..._cache };
  70. cache[i] = list;
  71. return this.updateData({
  72. cache,
  73. });
  74. },
  75. /* 获取一级列表数据 */
  76. async fetchMenus(hospitalDistrictId) {
  77. const params = {
  78. hospitalDistrictId,
  79. };
  80. const list = await getDepartmentList(params);
  81. await this.updateData({
  82. menus: list,
  83. loading: false,
  84. });
  85. /* 获取一级列表下面的第一项的第一个 */
  86. const departmentId = this.getDepartmentId(0);
  87. await this.fetchDepartments(departmentId, list[0]);
  88. },
  89. /* 获取二级列表 */
  90. async fetchDepartments(departmentId, item) {
  91. if (this.hasCache()) return;
  92. const list = !departmentId
  93. ? [item]
  94. : await getDepartmentList({
  95. parentId: departmentId,
  96. });
  97. this.setCache(list);
  98. },
  99. /* 获取科室id */
  100. getDepartmentId(index) {
  101. const { menus = [] } = this.data;
  102. const { hasChildren, departmentId } = menus[index] || {};
  103. if (hasChildren) return departmentId;
  104. },
  105. /* 切换科室 */
  106. async onTapMenu(i) {
  107. const item = this.data.menus[i];
  108. await this.updateData({
  109. index: i,
  110. });
  111. const departmentId = this.getDepartmentId(i);
  112. await this.fetchDepartments(departmentId, item);
  113. },
  114. /* 获取三级列表数据 */
  115. async onTapOpenLast(item) {
  116. const { departmentId } = item;
  117. const { lastCache } = this.data;
  118. const cacheList = lastCache[departmentId] || [];
  119. if (cacheList.length > 0) return cacheList;
  120. my.showLoading();
  121. const list = await getDepartmentList({
  122. parentId: departmentId,
  123. }).finally(my.hideLoading);
  124. lastCache[departmentId] = list;
  125. await this.updateData({
  126. lastCache: { ...lastCache },
  127. });
  128. return list;
  129. },
  130. onTapItem(item) {
  131. const query = this.getQuery();
  132. const { name: areaName } = query;
  133. const { componentData } = this.props;
  134. const {
  135. departmentId,
  136. name: dpName,
  137. departmentCode: depCode,
  138. hospitalId,
  139. } = item;
  140. history.push({
  141. query: {
  142. departmentId,
  143. depCode,
  144. hospitalId,
  145. yuanqu: areaName,
  146. },
  147. title: `${dpName}(${areaName})`,
  148. pageType: "hospital-num-source",
  149. componentData: { ...componentData, department: item },
  150. });
  151. },
  152. },
  153. });