personalCenterHead.js 2.8 KB

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