personalCenterHead.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. this.setData({
  76. showPatient: true
  77. });
  78. },
  79. onClose() {
  80. this.setData({
  81. showPatient: false
  82. });
  83. },
  84. onChange(item) {
  85. const {
  86. cardInfo
  87. } = this.data;
  88. const {
  89. id: patientId,
  90. bindCardNum: cardNum
  91. } = item;
  92. this.setData({
  93. showPatient: false,
  94. cardInfo: { ...cardInfo,
  95. cardNum,
  96. patientId
  97. }
  98. });
  99. my.showToast({
  100. duration: 1500,
  101. content: '就诊人切换成功'
  102. });
  103. },
  104. toPatientDetail() {
  105. const {
  106. patientId
  107. } = this.data.cardInfo;
  108. history.push({
  109. title: '就诊人详情',
  110. query: {
  111. id: patientId
  112. },
  113. pageType: 'patient-detail'
  114. });
  115. },
  116. toAddCard() {
  117. const {
  118. userInfo
  119. } = this.data;
  120. const {
  121. phone,
  122. gender,
  123. idCardNo,
  124. fullName
  125. } = userInfo || {};
  126. const editForm = {
  127. idCardNo,
  128. name: fullName,
  129. defaultCard: '是',
  130. phoneNumber: phone,
  131. relationShip: '本人',
  132. sex: gender === 'm' ? '男' : '女'
  133. };
  134. history.push({
  135. title: '添加就诊卡',
  136. pageType: 'edit-patient',
  137. query: {
  138. editType: 'card'
  139. },
  140. componentData: {
  141. editForm
  142. }
  143. });
  144. }
  145. }
  146. })));