index.js 1.6 KB

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