index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { createSubscribe } from 'applet-page-component';
  2. import { CREATE_CARD_TYPE } from '../utils/common';
  3. import { getCardList } from '../utils/service';
  4. import { connect } from 'herculex';
  5. import { promisify, replaceStar, history } from '../utils';
  6. import { reportCmPV_YL } from '../utils/cloudMonitorHelper';
  7. const getAuthCode = promisify(my.getAuthCode);
  8. Component(connect({
  9. mapStateToProps: {}
  10. })(createSubscribe({
  11. onShow() {
  12. this.scrollFetch && this.scrollFetch.fetchList({
  13. pageIndex: 1
  14. }, true, true);
  15. }
  16. })({
  17. props: {
  18. componentData: {}
  19. },
  20. data: {
  21. tabsConfig: {
  22. tabs: [{
  23. title: '就诊卡'
  24. }, {
  25. title: '医保卡'
  26. }]
  27. },
  28. activeTab: 0,
  29. cardType: 0 // 0-普通卡 1-医保卡 9-全部
  30. },
  31. didMount() {
  32. const {
  33. serviceCode
  34. } = getCurrentPages().pop().options;
  35. reportCmPV_YL({
  36. title: '就诊卡管理',
  37. query: {
  38. serviceCode
  39. }
  40. });
  41. getApp().globalData.cardFormComponentData = this.props.componentData;
  42. },
  43. methods: {
  44. saveRef(ref) {
  45. this.scrollFetch = ref;
  46. },
  47. async getCardLists(params) {
  48. let authCode = '';
  49. const {
  50. cardType,
  51. medicareflag
  52. } = this.data;
  53. if (medicareflag) {
  54. const [err, res] = await getAuthCode({
  55. scopes: ['medicare']
  56. });
  57. if (err) {
  58. return my.alert({
  59. content: '获取授权失败'
  60. });
  61. }
  62. authCode = res.authCode;
  63. }
  64. const [err, res] = await getCardList({ ...params,
  65. authCode,
  66. type: cardType
  67. });
  68. if (res) {
  69. res.list.forEach(item => {
  70. item.viewCardNum = replaceStar(item.cardNum, 3, 4);
  71. });
  72. }
  73. return [err, res];
  74. },
  75. // 卡管理页,tabble切换
  76. async handleTabClick({
  77. index,
  78. tabsName
  79. }) {
  80. await this.setData({
  81. medicareflag: index,
  82. [tabsName]: index,
  83. cardType: index
  84. });
  85. this.scrollFetch.fetchList({
  86. pageIndex: 1
  87. }, true, true);
  88. },
  89. // 绑定就诊卡
  90. toBindCard() {
  91. history.openPage({
  92. pageType: 'card-form',
  93. data: {
  94. type: CREATE_CARD_TYPE.BIND,
  95. btnText: '绑定就诊卡'
  96. }
  97. });
  98. },
  99. // 创建就诊卡
  100. toCreateCard() {
  101. history.openPage({
  102. pageType: 'card-form',
  103. data: {
  104. type: CREATE_CARD_TYPE.CREATE,
  105. btnText: '创建电子就诊卡'
  106. }
  107. });
  108. },
  109. // 就诊卡详情
  110. toCardDetail(e) {
  111. const cardNum = e.target.dataset.cardnum;
  112. const {
  113. type
  114. } = e.target.dataset;
  115. if (type === 1) {
  116. my.navigateToMiniProgram({
  117. appId: '2021001123625885',
  118. path: 'pages/index/index'
  119. });
  120. } else {
  121. history.openPage({
  122. pageType: 'card-detail',
  123. data: {
  124. cardNum,
  125. type
  126. }
  127. });
  128. }
  129. }
  130. }
  131. })));