PatientCardInfo.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <window-size>
  3. <div style="margin-top: 12px">
  4. <div id="qrcode" :style="qrMargin"></div>
  5. </div>
  6. <div class="expire-wrapper">
  7. <div style="color: #999">
  8. <span v-if="timer > -1">{{timer}}秒后过期</span>
  9. <span v-else>已过期</span>
  10. </div>
  11. <div v-if="timer < 0" style="color: #409EFF; margin-left: 8px" @click="drawQrcode">
  12. <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M512 166.4c-70.4 0-134.4 19.2-192 57.6L294.4 185.6C281.6 166.4 256 172.8 249.6 192L204.8 332.8C204.8 345.6 217.6 364.8 230.4 364.8l147.2-6.4c19.2 0 32-25.6 19.2-38.4L364.8 281.6l0 0 0-6.4C403.2 243.2 460.8 230.4 512 230.4c153.6 0 281.6 128 281.6 281.6s-128 281.6-281.6 281.6-281.6-128-281.6-281.6c0-19.2-12.8-32-32-32S166.4 492.8 166.4 512c0 192 153.6 345.6 345.6 345.6S857.6 704 857.6 512 704 166.4 512 166.4z" fill="#409EFF"></path></svg>
  13. 刷新
  14. </div>
  15. </div>
  16. <div style="height: 10px"></div>
  17. <van-cell title="姓名" icon="user-o" :value="currentCard.name" />
  18. <van-cell title="就诊卡号" icon="credit-pay" :value="currentCard.patientId" />
  19. <van-cell title="手机号" icon="phone-o" :value="currentCard.phone" />
  20. <van-cell title="身份证号" icon="idcard" :value="currentCard.socialNo" />
  21. <div style="height: 10px"></div>
  22. <van-button type="primary" plain block @click="setThisDefaultCard" :disabled="currentCard.isDefault === 1" icon="star-o">
  23. 设置默认就诊人
  24. </van-button>
  25. <div style="height: 10px"></div>
  26. <van-button type="primary" plain block @click="showEditDialog = true" icon="edit">编辑个人信息</van-button>
  27. <div style="height: 10px"></div>
  28. <van-button type="primary" plain block @click="unbindCard" icon="revoke">解除绑定</van-button>
  29. <van-dialog v-model:show="showEditDialog" title="编辑个人信息" show-cancel-button :before-close="modifyInfo">
  30. <div class="modify-note">提示:如需修改姓名或身份证号,请本人持身份证到医院窗口办理。</div>
  31. <van-field v-model="currentCard.name" label="姓名" disabled></van-field>
  32. <van-field v-model="currentCard.socialNo" label="身份证" disabled></van-field>
  33. <van-field v-model="currentCard.phone" type="tel" label="手机号" placeholder="请输入手机号"></van-field>
  34. </van-dialog>
  35. </window-size>
  36. </template>
  37. <script setup>
  38. import store from '@/store'
  39. import {onMounted, ref} from 'vue'
  40. import {useRouter} from 'vue-router'
  41. import {showConfirmDialog, showToast} from 'vant'
  42. import {
  43. getPatientIdByOpenid,
  44. relieveBindCard,
  45. relieveBindCardButCanceled,
  46. setDefaultCard,
  47. updateBindInfo,
  48. } from '@/api/patient-id-cards'
  49. import {isValidIdcard, isValidPhone} from '@/utils/validate'
  50. import {qrcanvas} from 'qrcanvas'
  51. const timer = ref(0)
  52. const screenSize = store.state.screenSize
  53. const qrMargin = {
  54. marginLeft: (screenSize.w - 164) / 2 + 'px',
  55. }
  56. const router = useRouter()
  57. const currentCard = store.getters.getCertainCard(router.currentRoute.value.params.patientId)
  58. const setThisDefaultCard = () => {
  59. setDefaultCard(currentCard.patientId).then(() => {
  60. showToast({
  61. message: '设置成功',
  62. position: 'top'
  63. })
  64. getPatientIdByOpenid().then((cards) => {
  65. store.dispatch({
  66. type: 'storePatientCards',
  67. cards
  68. })
  69. })
  70. })
  71. }
  72. const showEditDialog = ref(false)
  73. const modifyInfo = (action) => {
  74. if (action === 'cancel') {
  75. showEditDialog.value = false
  76. } else {
  77. if (!currentCard.name) {
  78. showToast({
  79. message: '请输入姓名',
  80. position: 'top',
  81. })
  82. return
  83. }
  84. if (!isValidIdcard(currentCard.socialNo)) {
  85. showToast({
  86. message: '请输入正确的身份证号码',
  87. position: 'top',
  88. })
  89. return
  90. }
  91. if (!isValidPhone(currentCard.phone)) {
  92. showToast({
  93. message: '请输入正确的手机号码',
  94. position: 'top',
  95. })
  96. return
  97. }
  98. updateBindInfo(currentCard).then(() => {
  99. showToast({
  100. message: '修改个人信息成功!',
  101. position: 'top'
  102. })
  103. })
  104. }
  105. }
  106. const unbindCard = () => {
  107. showConfirmDialog({
  108. title: '提示',
  109. message: '是否确定解除绑定?',
  110. }).then(() => {
  111. relieveBindCard(currentCard).then((cards) => {
  112. showToast({
  113. message: '解除绑定成功!',
  114. position: 'top'
  115. })
  116. store.dispatch({
  117. type: 'storePatientCards',
  118. cards
  119. }).then(() => {
  120. router.go(-1)
  121. })
  122. })
  123. }).catch(() => {
  124. relieveBindCardButCanceled(currentCard)
  125. })
  126. }
  127. let expireInterval = null
  128. const startExpireInterval = () => {
  129. timer.value = 60
  130. expireInterval = setInterval(() => {
  131. timer.value -= 1
  132. if (timer.value < 0) {
  133. clearInterval(expireInterval)
  134. expireQrcode()
  135. }
  136. }, 1000)
  137. }
  138. function expireQrcode() {
  139. const canvas = qrcanvas({
  140. data: 'expired',
  141. size: 164,
  142. })
  143. let oldChild = document.getElementById('qrcode').childNodes[0]
  144. document.getElementById('qrcode').replaceChild(canvas, oldChild)
  145. }
  146. const drawQrcode = () => {
  147. const canvas = qrcanvas({
  148. id: 'new',
  149. data: currentCard.patientId + '@' + currentCard.cardType,
  150. size: 164,
  151. })
  152. document.getElementById('qrcode').innerHTML = ''
  153. document.getElementById('qrcode').appendChild(canvas)
  154. startExpireInterval()
  155. }
  156. onMounted(() => {
  157. drawQrcode()
  158. })
  159. </script>
  160. <style scoped>
  161. .expire-wrapper {
  162. display: flex;
  163. align-items: center;
  164. justify-content: center;
  165. }
  166. .modify-note {
  167. padding: 4px 12px;
  168. font-size: 12px;
  169. color: red;
  170. }
  171. </style>