PatientCardInfo.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <window-size>
  3. <van-cell title="姓名" icon="user-o" :value="card.name" />
  4. <van-cell title="就诊卡号" icon="credit-pay" :value="card.patientId" />
  5. <van-cell title="手机号" icon="phone-o" :value="card.phone" />
  6. <van-cell title="身份证号" icon="idcard" :value="card.socialNo" />
  7. <div style="height: 10px"></div>
  8. <van-button type="primary" plain block @click="setThisDefaultCard" :disabled="card.isDefault === 1" icon="star-o">
  9. 设置默认就诊人
  10. </van-button>
  11. <div style="height: 10px"></div>
  12. <van-button type="primary" plain block @click="showEditDialog = true" icon="edit">编辑个人信息</van-button>
  13. <div style="height: 10px"></div>
  14. <van-button type="primary" plain block @click="unbindCard" icon="revoke">解除绑定</van-button>
  15. <van-dialog v-model:show="showEditDialog" title="编辑个人信息" show-cancel-button :before-close="modifyInfo">
  16. <van-field v-model="card.name" label="姓名" placeholder="请输入姓名"></van-field>
  17. <van-field v-model="card.socialNo" label="身份证" placeholder="请输入身份证号"></van-field>
  18. <van-field v-model="card.phone" type="tel" label="手机号" placeholder="请输入手机号"></van-field>
  19. </van-dialog>
  20. </window-size>
  21. </template>
  22. <script>
  23. import store from '../../../store'
  24. import { computed, ref } from 'vue'
  25. import { useRouter } from 'vue-router'
  26. import { Dialog, Toast } from 'vant'
  27. import {
  28. setDefaultCard,
  29. relieveBindCard,
  30. relieveBindCardButCanceled,
  31. updateBindInfo,
  32. } from '../../../api/patient-id-cards'
  33. import { getLocalOpenId, checkPatientId } from '../../../utils/check-patient-id'
  34. import { isValidIdcard, isValidPhone } from '../../../utils/validate'
  35. export default {
  36. name: 'PatientCardInfo',
  37. setup() {
  38. const router = useRouter()
  39. const paramId = router.currentRoute.value.params.patientId
  40. const card = computed(() => {
  41. let temp = {}
  42. store.state.patientCards.forEach((item) => {
  43. if (item.patientId === paramId) {
  44. temp = item
  45. }
  46. })
  47. return temp
  48. })
  49. const setThisDefaultCard = () => {
  50. const openId = getLocalOpenId()
  51. setDefaultCard(card.value.patientId, openId).then(() => {
  52. Toast.success('设置成功')
  53. checkPatientId()
  54. })
  55. }
  56. const showEditDialog = ref(false)
  57. const modifyInfo = (action) =>
  58. new Promise((resolve) => {
  59. if (action === 'cancel') {
  60. showEditDialog.value = false
  61. resolve(false)
  62. } else {
  63. if (!card.value.name) {
  64. Toast({
  65. message: '请输入姓名',
  66. position: 'top',
  67. })
  68. resolve(false)
  69. return
  70. }
  71. if (!isValidIdcard(card.value.socialNo)) {
  72. Toast({
  73. message: '请输入正确的身份证号码',
  74. position: 'top',
  75. })
  76. resolve(false)
  77. return
  78. }
  79. if (!isValidPhone(card.value.phone)) {
  80. Toast({
  81. message: '请输入正确的手机号码',
  82. position: 'top',
  83. })
  84. resolve(false)
  85. return
  86. }
  87. setTimeout(() => {
  88. updateBindInfo(card.value)
  89. .then(() => {
  90. Toast.success('修改个人信息成功!')
  91. resolve(true)
  92. })
  93. .catch(() => {
  94. resolve(false)
  95. })
  96. }, 500)
  97. }
  98. })
  99. const unbindCard = () => {
  100. Dialog.confirm({
  101. title: '提示',
  102. message: '是否确定解除绑定?',
  103. })
  104. .then(() => {
  105. const openId = getLocalOpenId()
  106. card.value.openId = openId
  107. relieveBindCard(card.value).then((res) => {
  108. Toast.success('解除绑定成功!')
  109. store.commit('SET_PATIENTCARDS', res)
  110. router.go(-1)
  111. })
  112. })
  113. .catch(() => {
  114. relieveBindCardButCanceled(card.value)
  115. })
  116. }
  117. return {
  118. card,
  119. setThisDefaultCard,
  120. showEditDialog,
  121. modifyInfo,
  122. unbindCard,
  123. }
  124. },
  125. }
  126. </script>