index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. },
  76. title: "修改手机号",
  77. pageType: "patient-detail-phone",
  78. });
  79. },
  80. onSubmit() {
  81. patientUpdate({
  82. id: this.data.patient.id,
  83. name: this.data.patient.name,
  84. relationShip: this.data.patient.relationShip,
  85. }).then(my.navigateBack);
  86. },
  87. },
  88. });