personalCenterHead.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { connect } from 'herculex';
  2. import { setPagesQuery } from "../../../../core/utils";
  3. import { createSubscribe } from 'applet-page-component';
  4. import { getMyCardInfo } from './service';
  5. import history from '../../utils/history';
  6. import doLogin from '../../utils/doLogin';
  7. const app = getApp();
  8. const qrImage = 'https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*z8duR6vAPp0AAAAAAAAAAAAAARQnAQ';
  9. const addIcon = 'https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*dqcsTZEuGTgAAAAAAAAAAAAAARQnAQ';
  10. Component(createSubscribe({
  11. onShow() {
  12. const {
  13. isLogin
  14. } = this.data;
  15. if (isLogin) this.fetchCardInfo();
  16. }
  17. })(connect({
  18. mapStateToProps: {
  19. scopes: ({
  20. $global
  21. }) => $global.scopes,
  22. userInfo: ({
  23. $global
  24. }) => $global.userInfo || {},
  25. isLogin: ({
  26. $global
  27. }) => $global.userInfo.isLogin
  28. }
  29. })({
  30. props: {
  31. componentData: {}
  32. },
  33. data: {
  34. addIcon,
  35. qrImage,
  36. cardInfo: null,
  37. showPatient: false,
  38. imgSrcPrefix: app.globalData.imgSrcPrefix
  39. },
  40. async didUpdate(_, preState) {
  41. const {
  42. isLogin = false
  43. } = preState;
  44. const {
  45. isLogin: curLogin
  46. } = this.data;
  47. if (isLogin !== curLogin && curLogin) {
  48. await this.fetchCardInfo();
  49. }
  50. },
  51. methods: {
  52. async fetchCardInfo() {
  53. const info = await getMyCardInfo();
  54. this.setData({
  55. cardInfo: info
  56. });
  57. },
  58. setQuery(patientId) {
  59. setPagesQuery({
  60. currentUserId: patientId
  61. });
  62. },
  63. /**
  64. * 去登陆
  65. */
  66. async onLogin() {
  67. await doLogin.call(this, {
  68. scopes: 'auth_user'
  69. });
  70. },
  71. /**
  72. * 切换就诊人
  73. */
  74. changeBtn() {
  75. console.log('1111111');
  76. this.setData({
  77. showPatient: true
  78. });
  79. },
  80. onClose() {
  81. this.setData({
  82. showPatient: false
  83. });
  84. },
  85. onChange(item) {
  86. const {
  87. cardInfo
  88. } = this.data;
  89. const {
  90. id: patientId,
  91. bindCardNum: cardNum,
  92. hisPatientId
  93. } = item;
  94. this.setData({
  95. showPatient: false,
  96. cardInfo: { ...cardInfo,
  97. cardNum,
  98. patientId,
  99. hisPatientId
  100. }
  101. });
  102. my.showToast({
  103. duration: 1500,
  104. content: '就诊人切换成功'
  105. });
  106. },
  107. toPatientDetail() {
  108. const {
  109. patientId
  110. } = this.data.cardInfo;
  111. history.push({
  112. title: '就诊人详情',
  113. query: {
  114. id: patientId
  115. },
  116. pageType: 'patient-detail'
  117. });
  118. },
  119. toAddCard() {
  120. const {
  121. userInfo
  122. } = this.data;
  123. const {
  124. phone,
  125. gender,
  126. idCardNo,
  127. fullName
  128. } = userInfo || {};
  129. const editForm = {
  130. idCardNo,
  131. name: fullName,
  132. defaultCard: '是',
  133. phoneNumber: phone,
  134. relationShip: '本人',
  135. sex: gender === 'm' ? '男' : '女'
  136. };
  137. history.push({
  138. title: '添加就诊卡',
  139. pageType: 'edit-patient',
  140. query: {
  141. editType: 'card'
  142. },
  143. componentData: {
  144. editForm
  145. }
  146. });
  147. }
  148. }
  149. })));