DoctorArrangement.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <window-size>
  3. <van-grid :column-num="1" :center="false">
  4. <van-grid-item>
  5. <div style="display: flex">
  6. <van-image
  7. round
  8. fit="cover"
  9. width="60px"
  10. height="80px"
  11. :src="'data:image/png;base64,' + data.doctorInfo.portrait"
  12. />
  13. <div style="min-width: 60%">
  14. <van-cell center :title="data.doctorInfo.doctorName">
  15. <template #label>
  16. <div>{{ data.doctorInfo.deptName }}</div>
  17. <div>{{ data.doctorInfo.doctorTitle }}</div>
  18. </template>
  19. </van-cell>
  20. </div>
  21. <div>
  22. <div style="height: 5px"></div>
  23. <van-button type="primary" plain size="small" :icon="collected.icon" @click="collectAction">
  24. {{ collected.text }}
  25. </van-button>
  26. <div style="height: 5px"></div>
  27. <van-button type="primary" plain size="small" icon="qr" @click="showDoctorQrCode">二维码</van-button>
  28. </div>
  29. </div>
  30. </van-grid-item>
  31. </van-grid>
  32. <van-collapse v-model="data.activeCollapse">
  33. <van-collapse-item title="介绍" name="1">
  34. <div style="color: #333333; margin-top: 10px">简介</div>
  35. {{ data.doctorInfo.introduction }}
  36. <div style="color: #333333; margin-top: 10px">擅长</div>
  37. {{ data.doctorInfo.specialty }}
  38. </van-collapse-item>
  39. <div id="noPadding">
  40. <van-collapse-item title="挂号" name="2">
  41. <van-collapse v-model="data.activeDate" accordion>
  42. <van-collapse-item :title="getSelectDate" name="dateSelection" value="更多日期">
  43. <van-grid direction="horizontal" :column-num="7">
  44. <van-grid-item v-for="item in data.oneWeekText" :key="item" :text="'周' + item" />
  45. </van-grid>
  46. <van-grid direction="horizontal" :column-num="7">
  47. <van-grid-item v-for="(item, index) in data.nextSevenDate" :key="index">
  48. <van-badge :content="hasSource(index)" :color="badgeColor(index)">
  49. <van-button
  50. :type="getType(index)"
  51. size="small"
  52. round
  53. @click="handleClickDate(index)"
  54. :disabled="hasSource(index) === '无'"
  55. >{{ item.date }}</van-button
  56. >
  57. </van-badge>
  58. </van-grid-item>
  59. </van-grid>
  60. </van-collapse-item>
  61. </van-collapse>
  62. <div v-for="item in data.arrangements" :key="item.mzyRequestId" @click="toAppointConfirm(item)">
  63. <van-cell center :title="item.ampm" is-link>
  64. <template #label>
  65. <span v-html="hasLeftNum(item.leftNum)"></span>
  66. </template>
  67. <template #default>
  68. <span style="color: orangered">¥{{ item.fee }}</span>
  69. </template>
  70. </van-cell>
  71. </div>
  72. </van-collapse-item>
  73. </div>
  74. </van-collapse>
  75. <van-popup v-model:show="data.showQr" closeable position="bottom" :style="{ height: '300px' }">
  76. <van-grid :border="false" :column-num="1">
  77. <van-grid-item>
  78. <van-image fit="fill" style="width: 240px; height: 240px" :src="data.qrcode" />
  79. <span style="color: orangered; font-size: 12px; margin-top: 5px">长按二维码识别或保存</span>
  80. </van-grid-item>
  81. </van-grid>
  82. </van-popup>
  83. <van-empty :image="empty" v-show="data.arrangements.length === 0" description="暂未获取到医生排班信息" />
  84. </window-size>
  85. </template>
  86. <script>
  87. import empty from '../../../assets/empty.png'
  88. import store from '../../../store'
  89. import { useRouter } from 'vue-router'
  90. import { computed, onMounted, reactive } from 'vue'
  91. import {
  92. getDoctorInfo,
  93. getSourcesByDateAndDoctor,
  94. getDoctorArrangement,
  95. getDoctorQrCode,
  96. } from '../../../api/appointment'
  97. import { collectDoctor, disCollectDoctor } from '../../../api/my-collection'
  98. import { getLocalOpenId } from '../../../utils/check-patient-id'
  99. import { genTextPortrait } from '../../../utils/portrait'
  100. import { getOneWeekText, getNextSevenDate } from '../../../utils/date'
  101. import { Toast } from 'vant'
  102. import Cookies from 'js-cookie'
  103. export default {
  104. name: 'DoctorArangement',
  105. setup() {
  106. const router = useRouter()
  107. const deptCode = router.currentRoute.value.params.dept
  108. const doctorCode = router.currentRoute.value.params.doctor
  109. const date = router.currentRoute.value.params.date
  110. const data = reactive({
  111. activeCollapse: ['1', '2'],
  112. activeDate: '',
  113. doctorInfo: {},
  114. arrangements: [],
  115. showQr: false,
  116. date: date,
  117. currentIndex: 0,
  118. oneWeekText: getOneWeekText(),
  119. nextSevenDate: getNextSevenDate(),
  120. nextSevenDaySources: new Array(7).fill(4001),
  121. qrcode: '',
  122. })
  123. const toAppointConfirm = (item) => {
  124. item.deptCode = Cookies.get('appointmentDeptCode')
  125. item.deptName = Cookies.get('appointmentDeptName')
  126. item.date = data.date
  127. store.commit('SET_APPOINTMENTINFO', item)
  128. router.push('/appointmentConfirm')
  129. }
  130. const collected = computed(() => {
  131. const icon = data.doctorInfo.collected > 0 ? 'star' : 'star-o'
  132. const text = data.doctorInfo.collected > 0 ? '已收藏' : '未收藏'
  133. return { icon, text }
  134. })
  135. const openId = getLocalOpenId()
  136. const collectAction = () => {
  137. const param = {
  138. openId,
  139. doctorCode,
  140. deptCode,
  141. }
  142. if (data.doctorInfo.collected === 0) {
  143. collectDoctor(param).then(() => {
  144. Toast.success('已收藏')
  145. getDoctorInfo(doctorCode, openId).then((res) => {
  146. data.doctorInfo = res
  147. if (!res.portrait) {
  148. data.doctorInfo.portrait = genTextPortrait(res.doctorName)
  149. }
  150. })
  151. })
  152. } else {
  153. disCollectDoctor(param).then(() => {
  154. Toast.success('已取消收藏')
  155. getDoctorInfo(doctorCode, openId).then((res) => {
  156. data.doctorInfo = res
  157. if (!res.portrait) {
  158. data.doctorInfo.portrait = genTextPortrait(res.doctorName)
  159. }
  160. })
  161. })
  162. }
  163. }
  164. const getSelectDate = computed(() => {
  165. return data.date
  166. })
  167. const getType = (index) => {
  168. return index === data.currentIndex ? 'primary' : 'default'
  169. }
  170. const hasSource = (index) => {
  171. return data.nextSevenDaySources[index] === 200 ? '有' : '无'
  172. }
  173. const badgeColor = (index) => {
  174. return data.nextSevenDaySources[index] === 200 ? 'green' : 'red'
  175. }
  176. const hasLeftNum = (val) => {
  177. return val > 0
  178. ? '<span style="font-size: 12px;color:green">有号</span>'
  179. : '<span style="font-size: 12px;color:red">无号</span>'
  180. }
  181. const handleClickDate = (index) => {
  182. if (index > 6) {
  183. return
  184. }
  185. data.currentIndex = index
  186. data.date = data.nextSevenDate[index].fullDate
  187. const param = {
  188. date: data.date,
  189. deptCode: deptCode,
  190. doctorCode: doctorCode,
  191. }
  192. getDoctorArrangement(param)
  193. .then((res) => {
  194. data.arrangements = res
  195. })
  196. .catch(() => {
  197. handleClickDate(++index)
  198. })
  199. }
  200. const showDoctorQrCode = () => {
  201. getDoctorQrCode(doctorCode).then((res) => {
  202. data.qrcode = res
  203. data.showQr = true
  204. })
  205. }
  206. onMounted(() => {
  207. getDoctorInfo(doctorCode, openId).then((res) => {
  208. data.doctorInfo = res
  209. if (!res.portrait) {
  210. data.doctorInfo.portrait = genTextPortrait(res.doctorName)
  211. }
  212. })
  213. const param = {
  214. date: data.nextSevenDate[0].fullDate,
  215. deptCode: deptCode,
  216. doctorCode: doctorCode,
  217. }
  218. getSourcesByDateAndDoctor(param).then((res) => {
  219. data.nextSevenDaySources = res
  220. for (let i = 0; i < 7; i++) {
  221. if (data.nextSevenDate[i].fullDate === date) {
  222. handleClickDate(i)
  223. }
  224. }
  225. })
  226. })
  227. return {
  228. empty,
  229. data,
  230. collected,
  231. collectAction,
  232. toAppointConfirm,
  233. getSelectDate,
  234. getType,
  235. hasSource,
  236. badgeColor,
  237. handleClickDate,
  238. showDoctorQrCode,
  239. hasLeftNum,
  240. }
  241. },
  242. }
  243. </script>
  244. <style>
  245. #noPadding .van-collapse-item__content {
  246. padding: 0;
  247. }
  248. </style>