index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { connect } from 'herculex';
  2. import { getIn } from 'herculex/dist/utils/manipulate';
  3. import { getDepList } from '../utils/service';
  4. import { history } from '../utils';
  5. import { reportCmPV_YL } from '../utils/cloudMonitorHelper';
  6. Component(connect({
  7. mapStateToProps: {
  8. bookingInfo: state => getIn(state, ['$global', 'bookingInfo'], {}),
  9. titleBarHeight: state => state.$global.titleBarHeight
  10. }
  11. })({
  12. props: {
  13. componentData: {}
  14. },
  15. data: {
  16. showLoading: true,
  17. noData: false,
  18. keyWord: '',
  19. // 关键词
  20. // 选择科室
  21. deparmentList: [],
  22. chidrenList: [],
  23. // 预约信息
  24. bookInfo: {}
  25. },
  26. didMount() {
  27. console.log(this.data.titleBarHeight);
  28. const {
  29. serviceCode
  30. } = getCurrentPages().pop().options;
  31. reportCmPV_YL({
  32. title: '预约挂号',
  33. query: {
  34. serviceCode
  35. }
  36. });
  37. this.getDepartmentList();
  38. my.setNavigationBar({
  39. title: '选择科室'
  40. });
  41. },
  42. methods: {
  43. // 获取科室列表
  44. async getDepartmentList(departmentId = '', keyWord) {
  45. this.setData({
  46. noData: false,
  47. showLoading: true,
  48. deparmentList: [],
  49. chidrenList: []
  50. });
  51. const params = {
  52. departmentId,
  53. keyWord
  54. };
  55. const [, res] = await getDepList(params);
  56. if (res && res.length) {
  57. const departmentList = this.addTitle(res);
  58. this.setData({
  59. showLoading: false,
  60. activeTab: 0,
  61. deparmentList: departmentList,
  62. noData: false
  63. }, () => {
  64. // 查询第一个科室的子科室
  65. departmentId = this.data.deparmentList[0].departmentId;
  66. const departmentName = this.data.deparmentList[0].name;
  67. const {
  68. hasChildren
  69. } = this.data.deparmentList[0];
  70. this.getChildrenList(departmentId, departmentName, hasChildren, keyWord);
  71. });
  72. } else {
  73. this.setData({
  74. showLoading: false,
  75. noData: true
  76. });
  77. }
  78. },
  79. // 增加title属性匹配组件展示
  80. addTitle(list) {
  81. return list.map(item => {
  82. // eslint-disable-next-line no-param-reassign
  83. item.title = item.name;
  84. return item;
  85. });
  86. },
  87. // 根据父级科室获取子科室列表
  88. async getChildrenList(parentId, parentName, hasChildren, keyWord) {
  89. if (!hasChildren) {
  90. this.setData({
  91. chidrenList: this.addTitle([{
  92. departmentId: parentId,
  93. name: parentName,
  94. hasChildren
  95. }])
  96. });
  97. return;
  98. }
  99. this.setData({
  100. chidrenList: []
  101. });
  102. const params = {
  103. parentId,
  104. parentName,
  105. keyWord
  106. };
  107. const [, res] = await getDepList(params);
  108. if (res && res.length) {
  109. const departmentList = this.addTitle(res);
  110. if (this.data.deparmentList && this.data.deparmentList.length) {
  111. this.setData({
  112. chidrenList: departmentList
  113. });
  114. }
  115. }
  116. },
  117. handleChange(index) {
  118. this.setData({
  119. activeTab: index
  120. });
  121. const {
  122. departmentId,
  123. name,
  124. hasChildren
  125. } = this.data.deparmentList[index]; // 查询对应的子科室
  126. this.getChildrenList(departmentId, name, hasChildren, this.data.keyWord);
  127. },
  128. clearkeyWord() {
  129. this.setData({
  130. keyWord: ''
  131. });
  132. this.getDepartmentList();
  133. },
  134. handleInput(keyWord) {
  135. this.setData({
  136. keyWord
  137. });
  138. this.getDepartmentList('', keyWord);
  139. },
  140. onItemClick(e) {
  141. const {
  142. departmentId,
  143. departmentName
  144. } = e.target.dataset;
  145. const bookInfo = {
  146. depId: departmentId,
  147. depName: departmentName
  148. };
  149. this.setData({
  150. bookInfo
  151. });
  152. history.openPage({
  153. pageType: 'choose-a-doctor',
  154. data: {
  155. bookInfo
  156. }
  157. });
  158. },
  159. handleRefresh() {
  160. this.getDepartmentList();
  161. }
  162. }
  163. }));