index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // this.$page.updatePatient = this;
  25. // const page = getCurrentPages();
  26. // console.log("page", this.$page);
  27. // console.log("page ===>", page);
  28. },
  29. didUnmount() {
  30. this.onEventRemove();
  31. },
  32. methods: {
  33. onEventChange() {
  34. const _this = this;
  35. EventHub.addEventListener("onPatienDetailUpdate", (payload) => {
  36. if (payload) {
  37. _this.querySingle();
  38. }
  39. });
  40. },
  41. onEventRemove() {
  42. const _this = this;
  43. EventHub.removeEventListener("onPatienDetailUpdate", (payload) => {
  44. if (payload) {
  45. _this.querySingle();
  46. }
  47. });
  48. },
  49. querySingle() {
  50. const {
  51. query = {
  52. id: "",
  53. },
  54. } = this.$page.data;
  55. my.showLoading();
  56. querySingle({
  57. id: query.id,
  58. }).then((data) => {
  59. this.setData({
  60. patient: data,
  61. });
  62. my.hideLoading();
  63. });
  64. },
  65. // 修改关系
  66. onChange(e) {
  67. this.setData({
  68. "patient.relationShip": e.name,
  69. });
  70. },
  71. onChangePhone() {
  72. history.push({
  73. query: {
  74. id: this.data.patient.id,
  75. relationShip: this.data.patient.relationShip,
  76. },
  77. title: "修改手机号",
  78. pageType: "patient-detail-phone",
  79. });
  80. },
  81. onSubmit() {
  82. patientUpdate({
  83. id: this.data.patient.id,
  84. name: this.data.patient.name,
  85. relationShip: this.data.patient.relationShip,
  86. }).then(my.navigateBack);
  87. },
  88. },
  89. });