index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 {
  26. hospitalDistrictId
  27. } = this.getQuery();
  28. try {
  29. await this.getServiceDetail(); // eslint-disable-next-line no-empty
  30. } catch (e) {}
  31. await this.fetchMenus(hospitalDistrictId);
  32. },
  33. methods: {
  34. updateData(data) {
  35. return new Promise(resolve => this.setData(data, resolve));
  36. },
  37. async getServiceDetail() {
  38. const code = 'hospital_service_code';
  39. const {
  40. link,
  41. uuid,
  42. title,
  43. linkType,
  44. accessMode,
  45. serviceDesc
  46. } = await queryServiceByCode(code);
  47. const serviceItem = {
  48. url: link,
  49. accessMode,
  50. name: title,
  51. serviceDesc,
  52. urlType: linkType,
  53. serviceUUID: uuid
  54. };
  55. await this.updateData({
  56. serviceItem
  57. });
  58. },
  59. getQuery() {
  60. const {
  61. $routeConfig
  62. } = this.$page;
  63. return $routeConfig.query;
  64. },
  65. async fetchProxy(func, ...arg) {
  66. my.showLoading();
  67. await func(...arg).finally(my.hideLoading);
  68. },
  69. /* 检测缓存 */
  70. hasCache() {
  71. const {
  72. index,
  73. cache
  74. } = this.data;
  75. return (cache[index] || []).length > 0;
  76. },
  77. /* 设置缓存 */
  78. setCache(list) {
  79. const {
  80. index: i,
  81. cache: _cache
  82. } = this.data;
  83. const cache = { ..._cache
  84. };
  85. cache[i] = list;
  86. return this.updateData({
  87. cache
  88. });
  89. },
  90. /* 获取一级列表数据 */
  91. async fetchMenus(hospitalDistrictId) {
  92. const params = {
  93. hospitalDistrictId
  94. };
  95. const list = await getDepartmentList(params);
  96. await this.updateData({
  97. menus: list,
  98. loading: false
  99. });
  100. /* 获取一级列表下面的第一项的第一个 */
  101. const departmentId = this.getDepartmentId(0);
  102. await this.fetchDepartments(departmentId, list[0]);
  103. },
  104. /* 获取二级列表 */
  105. async fetchDepartments(departmentId, item) {
  106. if (this.hasCache()) return;
  107. const list = !departmentId ? [item] : await getDepartmentList({
  108. parentId: departmentId
  109. });
  110. this.setCache(list);
  111. },
  112. /* 获取科室id */
  113. getDepartmentId(index) {
  114. const {
  115. menus = []
  116. } = this.data;
  117. const {
  118. hasChildren,
  119. departmentId
  120. } = menus[index] || {};
  121. if (hasChildren) return departmentId;
  122. },
  123. /* 切换科室 */
  124. async onTapMenu(i) {
  125. const item = this.data.menus[i];
  126. await this.updateData({
  127. index: i
  128. });
  129. const departmentId = this.getDepartmentId(i);
  130. await this.fetchDepartments(departmentId, item);
  131. },
  132. /* 获取三级列表数据 */
  133. async onTapOpenLast(item) {
  134. const {
  135. departmentId
  136. } = item;
  137. const {
  138. lastCache
  139. } = this.data;
  140. const cacheList = lastCache[departmentId] || [];
  141. if (cacheList.length > 0) return cacheList;
  142. my.showLoading();
  143. const list = await getDepartmentList({
  144. parentId: departmentId
  145. }).finally(my.hideLoading);
  146. lastCache[departmentId] = list;
  147. await this.updateData({
  148. lastCache: { ...lastCache
  149. }
  150. });
  151. return list;
  152. },
  153. onTapItem(item) {
  154. const query = this.getQuery();
  155. const {
  156. name: areaName
  157. } = query;
  158. const {
  159. componentData
  160. } = this.props;
  161. const {
  162. departmentId,
  163. name: dpName
  164. } = item;
  165. history.push({
  166. query: {
  167. departmentId
  168. },
  169. title: `${dpName}(${areaName})`,
  170. pageType: 'hospital-num-source',
  171. componentData: { ...componentData,
  172. department: item
  173. }
  174. });
  175. }
  176. }
  177. });