expertsItem.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { createSubscribe } from 'applet-page-component';
  2. import history from '../../utils/history';
  3. import { getDoctorList } from './service';
  4. Component(createSubscribe({
  5. /* 分页逻辑 */
  6. async onReachBottom() {
  7. const {
  8. loading,
  9. isLastPage
  10. } = this.data;
  11. if (loading || isLastPage) return;
  12. this.pageIndex = this.pageIndex + 1;
  13. await this.updateData({
  14. loading: true
  15. });
  16. await this.onSplitPage();
  17. }
  18. })({
  19. props: {
  20. componentData: {}
  21. },
  22. data: {
  23. loading: true,
  24. /* 是否为最后一页 */
  25. isLastPage: false,
  26. dataSource: []
  27. },
  28. async didMount() {
  29. await this.onRefresh();
  30. },
  31. methods: {
  32. updateData(data) {
  33. return new Promise(resolve => this.setData(data, resolve));
  34. },
  35. /* 分页显示医生列表 */
  36. async onSplitPage() {
  37. let total = 0;
  38. let dataList = [];
  39. let success = true;
  40. const {
  41. isLastPage
  42. } = this.data;
  43. const params = {
  44. pageSize: 10,
  45. pageIndex: this.pageIndex
  46. };
  47. if (!isLastPage) {
  48. try {
  49. const {
  50. list = [],
  51. pagination = {}
  52. } = await getDoctorList(params);
  53. dataList = list;
  54. total = pagination.total || 0;
  55. } catch (e) {
  56. success = false;
  57. }
  58. }
  59. let state = {
  60. loading: false
  61. };
  62. if (success) {
  63. const {
  64. dataSource
  65. } = this.data;
  66. const _list = [...dataSource, ...dataList];
  67. state = { ...state,
  68. dataSource: _list,
  69. isLastPage: _list.length >= total
  70. };
  71. }
  72. await this.updateData(state);
  73. },
  74. /* 刷新数据 */
  75. async onRefresh() {
  76. /* 初始化数据 */
  77. this.pageIndex = 1;
  78. await this.updateData({
  79. loading: true,
  80. isLastPage: false,
  81. dataSource: []
  82. });
  83. await this.onSplitPage();
  84. },
  85. toDetailPage({
  86. target
  87. }) {
  88. const {
  89. item
  90. } = target.dataset;
  91. const {
  92. doctorId
  93. } = item;
  94. history.push({
  95. query: {
  96. doctorId
  97. },
  98. title: '医生简介',
  99. pageType: 'doctor-profile-item'
  100. });
  101. }
  102. }
  103. }));