index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { querySingle, patientUpdate } from "../patient-detail/service";
  2. import history from "../../utils/history";
  3. import EventHub from "../../../abMall/utils/eventEmitter";
  4. Component({
  5. props: {},
  6. data: {
  7. patient: {
  8. balance: 0,
  9. id: "",
  10. name: "",
  11. age: "",
  12. sex: "",
  13. phoneNumber: "",
  14. birthDay: "",
  15. idCardNo: "",
  16. relationShip: "",
  17. bindCardNum: "",
  18. medicCards: [],
  19. },
  20. },
  21. didMount() {
  22. this.querySingle();
  23. this.onEventChange();
  24. const page = getCurrentPages();
  25. console.log("page ===>", page);
  26. },
  27. didUnmount() {
  28. this.onEventRemove();
  29. },
  30. methods: {
  31. onEventChange() {
  32. const _this = this;
  33. EventHub.addEventListener("onPatienDetailUpdate", (payload) => {
  34. if (payload) {
  35. _this.querySingle();
  36. }
  37. });
  38. },
  39. onEventRemove() {
  40. const _this = this;
  41. EventHub.removeEventListener("onPatienDetailUpdate", (payload) => {
  42. if (payload) {
  43. _this.querySingle();
  44. }
  45. });
  46. },
  47. querySingle() {
  48. const {
  49. query = {
  50. id: "",
  51. },
  52. } = this.$page.data;
  53. my.showLoading();
  54. querySingle({
  55. id: query.id,
  56. }).then((data) => {
  57. this.setData({
  58. patient: data,
  59. });
  60. my.hideLoading();
  61. });
  62. },
  63. // 修改关系
  64. onChange(e) {
  65. this.setData({
  66. "patient.relationShip": e.name,
  67. });
  68. },
  69. onChangePhone() {
  70. history.push({
  71. query: {
  72. id: this.data.patient.id,
  73. },
  74. title: "修改手机号",
  75. pageType: "patient-detail-phone",
  76. });
  77. },
  78. onSubmit() {
  79. patientUpdate({
  80. id: this.data.patient.id,
  81. name: this.data.patient.name,
  82. relationShip: this.data.patient.relationShip,
  83. }).then(my.navigateBack);
  84. },
  85. },
  86. });