index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { saveAdmissionRegistration } from '../add-inpatient-information/service';
  2. import history from '../../utils/history';
  3. Component({
  4. data: {
  5. personItem: {},
  6. // 就诊人信息
  7. inpatientNo: '',
  8. showOtherButton: 'false'
  9. },
  10. didMount() {
  11. // 获取用户id
  12. const {
  13. personItem,
  14. showOtherButton
  15. } = this.$page.data.query;
  16. console.log(showOtherButton);
  17. this.setData({
  18. personItem: personItem ? JSON.parse(personItem) : {},
  19. inpatientNo: '',
  20. showOtherButton
  21. });
  22. },
  23. methods: {
  24. // 表单提交
  25. async onSubmit() {
  26. const {
  27. inpatientNo,
  28. personItem
  29. } = this.data;
  30. if (/.*[\u4e00-\u9fa5]+.*$/.test(inpatientNo)) {
  31. my.showToast({
  32. content: '住院号不能有汉字'
  33. });
  34. return;
  35. } // 调用方法 - 添加住院人
  36. delete personItem.id;
  37. const {
  38. inpatientId
  39. } = await saveAdmissionRegistration({
  40. inpatientNo,
  41. ...personItem,
  42. patientId: this.data.personItem.id
  43. }); // 如果添加失败,toast提示
  44. if (!inpatientId) {
  45. my.showToast({
  46. content: '住院号信息有误,请重新输入!'
  47. });
  48. return;
  49. } // 如果添加成功,跳转至登记结果页
  50. if (inpatientId) {
  51. my.showToast({
  52. content: '添加成功',
  53. duration: 1000,
  54. success: () => {
  55. history.replace({
  56. query: {
  57. inpatientId,
  58. showOtherButton: this.data.showOtherButton
  59. },
  60. title: '登记结果',
  61. pageType: 'registration-result'
  62. });
  63. }
  64. });
  65. }
  66. },
  67. handleInput(e) {
  68. this.setData({
  69. inpatientNo: e.detail.value
  70. });
  71. }
  72. }
  73. });